This repository has been archived by the owner on Oct 30, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 214
/
test-selector.js
150 lines (123 loc) · 5.7 KB
/
test-selector.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
/*
* Copyright (c) 2011-2013, Yahoo! Inc. All rights reserved.
* Copyrights licensed under the New BSD License.
* See the accompanying LICENSE file for terms.
*/
YUI().use(
'mojito-test-extra',
'base',
'oop',
'addon-rs-config',
'addon-rs-selector',
'test',
function(Y) {
var suite = new Y.Test.Suite('mojito-addon-rs-selector-tests'),
libpath = require('path'),
libycb = require('ycb'),
mojitoRoot = libpath.join(__dirname, '../../../../../../lib'),
fixtures = libpath.join(__dirname, '../../../../../fixtures/store');
A = Y.Assert;
function MockRS(config) {
MockRS.superclass.constructor.apply(this, arguments);
}
MockRS.NAME = 'MockResourceStore';
MockRS.ATTRS = {};
Y.extend(MockRS, Y.Base, {
initializer: function(cfg) {
this._config = cfg || {};
this.selectors = {
'devdroid': true,
'droid': true,
'shelves': true,
'right': true,
'*': true
};
},
blendStaticContext: function() {
return {};
},
validateContext: function() {},
cloneObj: function(o) {
return Y.clone(o);
}
});
suite.add(new Y.Test.Case({
name: 'selector rs addon tests',
'read dimensions': function() {
// from mojito
var store = new MockRS({ root: fixtures });
store.plug(Y.mojito.addons.rs.config, { appRoot: fixtures, mojitoRoot: mojitoRoot } );
store.plug(Y.mojito.addons.rs.selector, { appRoot: fixtures, mojitoRoot: mojitoRoot } );
var have = store.selector.getPOSLFromContext({});
var want = ['*'];
Y.TEST_CMP(have, want);
var have = store.selector.getPOSLFromContext({runtime:'client'});
var want = ['right', '*'];
Y.TEST_CMP(have, want);
var have = store.selector.getPOSLFromContext({runtime:'server'});
var want = ['shelves', '*'];
Y.TEST_CMP(have, want);
var have = store.selector.getPOSLFromContext({device:'android'});
var want = ['droid', '*'];
Y.TEST_CMP(have, want);
var have = store.selector.getPOSLFromContext({runtime:'server', device:'android'});
var want = ['shelves', 'droid', '*'];
Y.TEST_CMP(have, want);
var have = store.selector.getPOSLFromContext({device:'android', environment:'dev'});
var want = ['devdroid', 'droid', '*'];
Y.TEST_CMP(have, want);
var have = store.selector.getPOSLFromContext({runtime:'server', device:'android', environment:'dev'});
var want = ['shelves', 'devdroid', 'droid', '*'];
Y.TEST_CMP(have, want);
},
'get all posls': function() {
var store = new MockRS({ root: fixtures });
store.plug(Y.mojito.addons.rs.config, { appRoot: fixtures, mojitoRoot: mojitoRoot } );
store.plug(Y.mojito.addons.rs.selector, { appRoot: fixtures, mojitoRoot: mojitoRoot } );
var have = store.selector.getAllPOSLs();
var want = [
[ 'shelves', '*' ],
[ 'shelves', 'devdroid', 'droid', '*' ],
[ 'shelves', 'droid', '*' ],
[ 'right', '*' ],
[ 'right', 'devdroid', 'droid', '*' ],
[ 'right', 'droid', '*' ]
];
Y.TEST_CMP(want, have);
},
'list used dimensions': function() {
var store = new MockRS({ root: fixtures });
store.plug(Y.mojito.addons.rs.config, { appRoot: fixtures, mojitoRoot: mojitoRoot } );
store.plug(Y.mojito.addons.rs.selector, { appRoot: fixtures, mojitoRoot: mojitoRoot } );
var have = store.selector._listUsedDimensions();
var want = {
runtime: ['server', 'client'],
device: ['iphone', 'android'],
environment: ['dev']
}
Y.TEST_CMP(want, have);
},
'list used contexts': function() {
var store = new MockRS({ root: fixtures });
store.plug(Y.mojito.addons.rs.config, { appRoot: fixtures, mojitoRoot: mojitoRoot } );
store.plug(Y.mojito.addons.rs.selector, { appRoot: fixtures, mojitoRoot: mojitoRoot } );
var have = store.selector._listUsedContexts();
var want = [
{ runtime: 'server', device: 'iphone', environment: 'dev' },
{ runtime: 'server', device: 'iphone' },
{ runtime: 'server', device: 'android', environment: 'dev' },
{ runtime: 'server', device: 'android' },
{ runtime: 'server', environment: 'dev' },
{ runtime: 'server' },
{ runtime: 'client', device: 'iphone', environment: 'dev' },
{ runtime: 'client', device: 'iphone' },
{ runtime: 'client', device: 'android', environment: 'dev' },
{ runtime: 'client', device: 'android' },
{ runtime: 'client', environment: 'dev' },
{ runtime: 'client' }
];
Y.TEST_CMP(want, have);
}
}));
Y.Test.Runner.add(suite);
});