~stephen-stewart/online-services-common-js/update-global-nav

« back to all changes in this revision

Viewing changes to src/global-navigation/tests/unit/assets/global-nav-test.js

  • Committer: Stephen Stewart
  • Date: 2014-02-22 15:05:16 UTC
  • Revision ID: stephen.stewart@canonical.com-20140222150516-rkzti2c43ggwr2ta
import latest js, convert

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
YUI.add('global-nav-test', function (Y) {
2
2
 
3
3
var Assert = Y.Assert,
4
 
    suite,
5
 
    nav;
6
 
 
7
 
suite = new Y.Test.Suite('Global Nav Tests');
 
4
    suite;
 
5
 
 
6
suite = new Y.Test.Suite({
 
7
    name: 'GlobalNav',
 
8
 
 
9
    // called before the first test in the first test case is executed
 
10
    // before the test's setup() method
 
11
    setUp : function () {
 
12
        this.nav = new Y.U1.GlobalNav();
 
13
    },
 
14
 
 
15
    // executes after all tests in all test cases/suites have been executed
 
16
    // after the test's teardown()
 
17
    tearDown: function () {
 
18
    },
 
19
});
8
20
 
9
21
suite.add(new Y.Test.Case({
10
22
 
11
23
    name: "General",
12
24
 
13
25
    setUp: function() {
14
 
        this.nav = new Y.U1.GlobalNav();
15
 
 
 
26
        console.log(this);
16
27
        this.data = [{
17
28
            url: "www.ubuntu.com",
18
29
            title: "Ubuntu"
27
38
 
28
39
    "_reduceUrlList should reduce a list of urls to the single longest": function() {
29
40
 
30
 
        var obj = this.nav._reduceUrlList(this.data);
 
41
        var obj = suite.nav._reduceUrlList(this.data);
31
42
        Assert.isObject(obj);
32
43
        Assert.areEqual('www.ubuntu.com/foo', obj.url);
33
44
    },
34
45
 
35
46
    "_filterUrls should filter urls": function() {
36
 
        var list = this.nav._filterUrls(this.data, "www.foo.com");
 
47
        var list = suite.nav._filterUrls(this.data, "www.foo.com");
37
48
        Assert.isArray(list);
38
49
        Assert.areEqual(1, list.length, 1);
39
50
        Assert.areEqual('www.foo.com', list[0].url);
40
51
 
41
 
        list = this.nav._filterUrls(this.data, "www.ubuntu.com/foo");
 
52
        list = suite.nav._filterUrls(this.data, "www.ubuntu.com/foo");
42
53
        Assert.isArray(list);
43
54
        Assert.areEqual(2, list.length);
44
55
    },
45
56
 
46
57
    "_getActiveUrl should do just that": function() {
47
58
 
48
 
        this.nav.location = "www.ubuntu.com";
49
 
        var index = this.nav.getActiveUrl(this.data);
 
59
        suite.nav.location = "www.ubuntu.com";
 
60
        var index = suite.nav.getActiveUrl(this.data);
50
61
        Assert.areEqual(0, index);
51
62
 
52
 
        this.nav.location = "www.ubuntu.com/foo";
53
 
        index = this.nav.getActiveUrl(this.data);
 
63
        suite.nav.location = "www.ubuntu.com/foo";
 
64
        index = suite.nav.getActiveUrl(this.data);
54
65
        Assert.areEqual(2, index);
55
66
    },
56
67