/*global describe, it*/
var expect = require('../unexpected-with-plugins'),
    AssetGraph = require('../../lib/AssetGraph');

describe('relations/HtmlOpenGraph', function () {
    function getHtmlAsset(htmlString) {
        var graph = new AssetGraph({ root: __dirname });
        var htmlAsset = new AssetGraph.Html({
            text: htmlString || '<!doctype html><html><head></head><body></body></html>',
            url: 'file://' + __dirname + 'doesntmatter.html'
        });

        graph.addAsset(htmlAsset);

        return htmlAsset;
    }

    describe('#inline', function () {
        it('should throw', function () {
            var relation = new AssetGraph.HtmlOpenGraph({
                to: { url: 'index.html' }
            });

            expect(relation.inline, 'to throw', /Inlining of open graph relations is not allowed/);
        });
    });

    it('should handle a test case with an existing <link rel="preconnect"> element', function () {
        return new AssetGraph({root: __dirname + '/../../testdata/relations/HtmlOpenGraph/'})
            .loadAssets('index.html')
            .queue(function (assetGraph) {
                expect(assetGraph, 'to contain relation including unresolved', 'HtmlOpenGraph', 10);
            });
    });

    it('should update the href', function () {
        return new AssetGraph({root: __dirname + '/../../testdata/relations/HtmlOpenGraph/'})
            .loadAssets('index.html')
            .queue(function (assetGraph) {
                expect(assetGraph, 'to contain relation including unresolved', 'HtmlOpenGraph', 10);

                var link = assetGraph.findRelations({ type: 'HtmlOpenGraph' }, true)[0];

                link.to.url = 'foo.bar';
                // This is necessary because link.to is an asset config object, not a real asset that will
                // propagate url changes:
                link.refreshHref();

                expect(link, 'to satisfy', {
                    href: 'foo.bar'
                });
            });
    });

    describe('when programmatically adding a relation', function () {
        it('should handle crossorigin url', function () {
            var htmlAsset = getHtmlAsset();
            var relation = new AssetGraph.HtmlOpenGraph({
                to: {
                    url: 'http://assetgraph.org'
                },
                ogProperty: 'og:image'
            });

            relation.attachToHead(htmlAsset, 'first');

            expect(htmlAsset.parseTree.head.firstChild, 'to exhaustively satisfy', '<meta property="og:image" content="http://assetgraph.org/">');
        });
    });
});

@@ -17,19 +17,21 @@
 e, it*/%0A
-var
+const
  expect 
@@ -69,21 +69,23 @@
 lugins')
-,%0A   
+;%0Aconst
  AssetGr
@@ -1299,16 +1299,22 @@
 e href',
+ async
  functio
@@ -1320,38 +1320,56 @@
 on () %7B%0A        
-return
+const assetGraph = await
  new AssetGraph(
@@ -1473,60 +1473,11 @@
 ml')
-%0A            .queue(function (assetGraph) %7B%0A        
+;%0A%0A
     
@@ -1574,27 +1574,21 @@
         
-        var
+const
  link = 
@@ -1662,339 +1662,140 @@
     
-        link.to.url = 'foo.bar';%0A                // This is necessary because link.to is an asset config object, not a real asset that will%0A                // propagate url changes:%0A                link.refreshHref();%0A%0A                expect(link, 'to satisfy', %7B%0A                    href: 'foo.bar'%0A                %7D);%0A           
+link.hrefType = 'relative';%0A        link.to.url = assetGraph.root + 'foo.bar';%0A%0A        expect(link, 'to satisfy', %7B href: 'foo.bar'
  %7D);

Fix HtmlOpenGraph test, 26 failing [ci skip]