<!DOCTYPE html>
<html>
<head>
<title>Unit Tests</title>

<link rel="stylesheet" href="//cdnjs.cloudflare.com/ajax/libs/qunit/1.12.0/qunit.css" />

<script type="text/javascript" src="//cdnjs.cloudflare.com/ajax/libs/qunit/1.12.0/qunit.min.js"></script>

<!-- build:css http://cdn.knightlab.com/libs/storymapjs/latest/css/storymap.css -->
<link rel="stylesheet" href="/build/css/storymap.css?v1">
<!-- endbuild -->
<!-- build:js http://cdn.knightlab.com/libs/storymapjs/latest/js/storymap-min.js -->
<script type="text/javascript" src="/build/js/storymap.js"></script>
<!-- endbuild -->


<script type="text/javascript">

    test("Media Type matcher", function() {
        var test_items = [
            ['image', "http://upload.wikimedia.org/wikipedia/commons/thumb/b/bc/Mark_Twain_Vanity_Fair_1908-05-13.jpeg/375px-Mark_Twain_Vanity_Fair_1908-05-13.jpeg"],
            ['image', "http://upload.wikimedia.org/wikipedia/commons/thumb/9/9c/Mark_Twain_birthplace.jpg/800px-Mark_Twain_birthplace.jpg"],
            ['image',"http://upload.wikimedia.org/wikipedia/commons/thumb/9/93/Mark_Twain_Boyhood_Home_1.jpg/800px-Mark_Twain_Boyhood_Home_1.jpg"],
            ['youtube', "http://www.youtube.com/watch?v=C-nTpGMMVjY"],
            ['vine', "https://vine.co/v/bjHh0zHdgZT"],
            ['flickr', "http://www.flickr.com/photos/koci/11436254373/"],
            ['blockquote', "<blockquote><p>Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Morbi commodo, ipsum sed pharetra gravida, orci magna rhoncus neque, id pulvinar odio lorem non turpis. Nullam sit amet enim. Suspendisse id velit vitae ligula volutpat condimentum. Aliquam erat volutpat.</p><cite>Lorem Ipsum Generator</cite></blockquote>"],
            ['iframe', "<iframe src='http://cdn.knightlab.com/libs/timeline/latest/embed/index.html?source=0Agl_Dv6iEbDadHdKcHlHcTB5bzhvbF9iTWwyMmJHdkE&font=Bevan-PotanoSans&maptype=TERRAIN&lang=en&height=650' width='100%' height='650' frameborder='0'></iframe>",
            ['instagram', 'http://instagram.com/p/i9dz0fCeG-/']]
        ];

        for (var i = 0; i < test_items.length; i++) {
            var type = test_items[i][0];
            var url = test_items[i][1];
            var m = VCO.MediaType({'url': url});
            ok(m, "url " + url + " returns a media type");
            equal(m.url, url, "Expect the same url back in the url property");
            equal(m.type, type, "Expected url " + url + " to yield type " + type);
        }
    });

    test("Flickr IDs", function() {
        var media = {
                    "url": "http://www.flickr.com/photos/graysonfamily/349095341/",
                 "credit": "graysonfamily",
                "caption": "1820 Census Record"
        }
        var media_obj = new VCO.Media.Flickr(media,{});
        media_obj.establishMediaID();
        equal(media_obj.media_id,"349095341");

        media = {
            "url": "http://www.flickr.com/photos/statephotos/8507434935/in/photostream/",
            "credit": "State Department photo by Glen Johnson"
        }
        var media_obj = new VCO.Media.Flickr(media,{});
        media_obj.establishMediaID();
        equal(media_obj.media_id,"8507434935");
    })

    asyncTest("asynchronous test: JSON callback", function() {
        VCO.getJSON('http://date.jsontest.com/?callback=?', function(data, status, xhr){
          console.log('workin');
          window.stash = { data: data, status: status, xhr: xhr };
          equal(status,"success","Callback basically worked.")
          var date_parts = data.date.split('-');
          var date = new Date();
          equal(parseInt(date_parts[0]),date.getMonth() + 1,"JSON returned correct month.");
          equal(parseInt(date_parts[1]),date.getDate(),"JSON returned correct date.");
          equal(parseInt(date_parts[2]),date.getFullYear(),"JSON returned correct year.");
          start();
        });
    });
    
    test("VCO.Util.urljoin", function() {
        var joined_path = "http://s3.amazonaws.com/cdn.knightlab.com/libs/storymapjs/dev/js/locale/nl.js";        
        
        var test_items = [
            ["http://s3.amazonaws.com/cdn.knightlab.com/libs/storymapjs/dev/js/", "/locale/nl.js"],
            ["http://s3.amazonaws.com/cdn.knightlab.com/libs/storymapjs/dev/js/", "locale/nl.js"],
            ["http://s3.amazonaws.com/cdn.knightlab.com/libs/storymapjs/dev/js", "/locale/nl.js"],
            ["http://s3.amazonaws.com/cdn.knightlab.com/libs/storymapjs/dev/js", "locale/nl.js"]
        ];
        
        for(var i = 0; i < test_items.length; i++) {
            var path = VCO.Util.urljoin(test_items[i][0], test_items[i][1]);
            equal(path, joined_path, "Expected path "+path+" to equal "+joined_path);
        }
        
        var joined_path = "http://s3.amazonaws.com/cdn.knightlab.com/libs/storymapjs/dev/css/fonts/font.emoji.css"; 
        
        var test_items = [
            ["http://s3.amazonaws.com/cdn.knightlab.com/libs/storymapjs/dev/js/", "../css/fonts/font.emoji.css"],
            ["http://s3.amazonaws.com/cdn.knightlab.com/libs/storymapjs/dev/js", "../css/fonts/font.emoji.css"]
        ];
            
        for(var i = 0; i < test_items.length; i++) {
            var path = VCO.Util.urljoin(test_items[i][0], test_items[i][1]);
            equal(path, joined_path, "Expected path "+path+" to equal "+joined_path);
        }    
    });
    
    
    
</script>
</head>
<body>
    <div id="qunit"></div>
</body>
</html>