forked from extmvc/extmvc
/
ExtMVC.spec.js
65 lines (50 loc) · 2.7 KB
/
ExtMVC.spec.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
Screw.Unit(function() {
describe("ExtMVC", function() {
describe("environments", function() {
it("should default to the production environment", function() {
expect(ExtMVC.getCurrentEnvironment()).to(equal, 'production');
});
it("should return current environment settings", function() {
expect(ExtMVC.getCurrentEnvironmentSettings()).to(equal, {});
});
it("should allow retrieval of existing environment settings", function() {
var prod = ExtMVC.getEnvironmentSettings('production');
expect(prod).to(equal, {});
});
it("should allow specification of environment settings to an existing environment", function() {
expect(ExtMVC.getEnvironmentSettings('production')).to(equal, {});
ExtMVC.addEnvironmentSettings('production', {myKey: 'myValue'});
expect(ExtMVC.getEnvironmentSettings('production').myKey).to(equal, 'myValue');
});
it("should allow specification of environment settings to a new environment", function() {
var mySettings = {key: 'value'};
expect(ExtMVC.getEnvironmentSettings('newEnv')).to(equal, null);
ExtMVC.addEnvironmentSettings('newEnv', mySettings);
expect(ExtMVC.getEnvironmentSettings('newEnv')).to(equal, mySettings);
});
describe("when changing environment", function() {
it("should allow the current environment to be changed if the new environment is valid", function() {
expect(ExtMVC.getCurrentEnvironment()).to(equal, 'production');
//we need to add this environment first to make it valid
ExtMVC.addEnvironmentSettings('development', {key: 'value'});
ExtMVC.setCurrentEnvironment('development');
expect(ExtMVC.getCurrentEnvironment()).to(equal, 'development');
});
it("should not allow the current environment to be changed if the new environment does not exist", function() {
ExtMVC.setCurrentEnvironment('notReal');
expect(ExtMVC.getCurrentEnvironment()).to_not(equal, 'notReal');
});
it("should fire an environment-changed event", function() {
var newEnv = '', newConfig = {};
var devSettings = {key: 'value'};
//add another environment to be able to change to
ExtMVC.addEnvironmentSettings('development', devSettings);
ExtMVC.on('environment-changed', function(n, c) {newEnv = n; newConfig = c;}, this);
ExtMVC.setCurrentEnvironment('development');
expect(newEnv).to(equal, 'development');
expect(newConfig).to(equal, devSettings);
});
});
});
});
});