aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorValerio Virgillito2012-08-12 23:45:00 -0700
committerValerio Virgillito2012-08-12 23:45:00 -0700
commita9ff54e7490761a7c0ad572d060ee386179d11df (patch)
tree4cb5fa31a866f421bf4e1ed51da92aa3e5c4041a
parent91c440a04f0108d05e663d1696027ca5601b25bc (diff)
downloadninja-a9ff54e7490761a7c0ad572d060ee386179d11df.tar.gz
adding test cases for Jasmine
Signed-off-by: Valerio Virgillito <valerio@motorola.com>
-rw-r--r--tests/unit-tests/color-model-test.js130
-rw-r--r--tests/unit-tests/file-io-test.js610
-rw-r--r--tests/unit-tests/styles-controller-test.js143
3 files changed, 883 insertions, 0 deletions
diff --git a/tests/unit-tests/color-model-test.js b/tests/unit-tests/color-model-test.js
new file mode 100644
index 00000000..d596445b
--- /dev/null
+++ b/tests/unit-tests/color-model-test.js
@@ -0,0 +1,130 @@
1var Montage = require("montage/core/core").Montage;
2
3var cmObject = require("ninjaapp/js/models/color-model"),
4 cm = cmObject.ColorModel;
5
6console.log(cm);
7
8describe('ColorManager', function() {
9 /** **************** alpha tests **************** */
10 describe('alpha', function() {
11 it('default is 1', function() {
12 expect(cm.alpha).toEqual(1);
13 });
14 it('can be set/get', function() {
15 cm.alpha = 0.2;
16 expect(cm.alpha).toEqual(0.2);
17 });
18 });
19
20
21 /** **************** rgbToHex() tests **************** */
22 describe('rgbToHex()', function() {
23 it('rgbToHex(0,0,0) is 000000/black', function() {
24 var hex = cm.rgbToHex(0,0,0);
25 expect(hex).toEqual("000000");
26 });
27 it('rgbToHex(255,255,255) is FFFFFF/white', function() {
28 var hex = cm.rgbToHex(255,255,255);
29 expect(hex).toEqual("FFFFFF");
30 });
31 it('rgbToHex(255,0,0) is FF0000/red', function() {
32 var hex = cm.rgbToHex(255,0,0);
33 expect(hex).toEqual("FF0000");
34 });
35 it('rgbToHex(0,255,0) is 00FF00/green', function() {
36 var hex = cm.rgbToHex(0,255,0);
37 expect(hex).toEqual("00FF00");
38 });
39 it('rgbToHex(0,0,255) is 0000FF/blue', function() {
40 var hex = cm.rgbToHex(0,0,255);
41 expect(hex).toEqual("0000FF");
42 });
43 it('rgbToHex(255,160,122) is FFA07A/salmon', function() {
44 var hex = cm.rgbToHex(255,160,122);
45 expect(hex).toEqual("FFA07A");
46 });
47 });
48
49
50 /** **************** rgbToHsl() tests **************** */
51 describe('rgbToHsl()', function() {
52 it('rgbToHsl(0,0,0) is {h:0, s:0, l:0}/black', function() {
53 var value = cm.rgbToHsl(0,0,0);
54 expect(value.h).toEqual(0);
55 expect(value.s).toEqual(0);
56 expect(value.l).toEqual(0);
57 });
58 it('rgbToHsl(255,255,255) is {h:0, s:0, l:100}/white', function() {
59 var value = cm.rgbToHsl(255,255,255);
60 expect(value.h).toEqual(0);
61 expect(value.s).toEqual(0);
62 expect(value.l).toEqual(100);
63 });
64 it('rgbToHsl(255,0,0) is {h:0, s:100, l:50}/red', function() {
65 var value = cm.rgbToHsl(255,0,0);
66 expect(value.h).toEqual(0);
67 expect(value.s).toEqual(100);
68 expect(value.l).toEqual(50);
69 });
70 it('rgbToHsl(0,255,0) is {h:120, s:100, l:50}/green', function() {
71 var value = cm.rgbToHsl(0,255,0);
72 expect(value.h).toEqual(120);
73 expect(value.s).toEqual(100);
74 expect(value.l).toEqual(50);
75 });
76 it('rgbToHsl(0,0,255) is {h:240, s:100, l:50}/blue', function() {
77 var value = cm.rgbToHsl(0,0,255);
78 expect(value.h).toEqual(240);
79 expect(value.s).toEqual(100);
80 expect(value.l).toEqual(50);
81 });
82 it('rgbToHsl(255,160,122) is {h:17.14, s:100, l:73.92}/salmon', function() {
83 var value = cm.rgbToHsl(255,160,122);
84 expect(value.h).toEqual(17.142857142857142);
85 expect(value.s).toEqual(100);
86 expect(value.l).toEqual(73.92156862745098);
87 });
88 });
89
90
91 /** **************** hexToRgb() tests **************** */
92 describe('hexToRgb()', function() {
93 it('hexToRgb(000000) is {r:0, g:0, b:0}', function() {
94 var value = cm.hexToRgb("000000");
95 expect(value.r).toEqual(0); // red channel
96 expect(value.g).toEqual(0); // green channel
97 expect(value.b).toEqual(0); // blue channel
98 });
99 it('hexToRgb(FFFFFF) is {r:255, g:255, b:255}', function() {
100 var value = cm.hexToRgb("FFFFFF");
101 expect(value.r).toEqual(255); // red channel
102 expect(value.g).toEqual(255); // green channel
103 expect(value.b).toEqual(255); // blue channel
104 });
105 it('hexToRgb(FF0000) is {r:255, g:0, b:0}', function() {
106 var value = cm.hexToRgb("FF0000");
107 expect(value.r).toEqual(255); // red channel
108 expect(value.g).toEqual(0); // green channel
109 expect(value.b).toEqual(0); // blue channel
110 });
111 it('hexToRgb(00FF00) is {r:0, g:255, b:0}', function() {
112 var value = cm.hexToRgb("00FF00");
113 expect(value.r).toEqual(0); // red channel
114 expect(value.g).toEqual(255); // green channel
115 expect(value.b).toEqual(0); // blue channel
116 });
117 it('hexToRgb(0000FF) is {r:0, g:0, b:255}', function() {
118 var value = cm.hexToRgb("0000FF");
119 expect(value.r).toEqual(0); // red channel
120 expect(value.g).toEqual(0); // green channel
121 expect(value.b).toEqual(255); // blue channel
122 });
123 it('hexToRgb(FFA07A) is {r:255, g:160, b:122}', function() {
124 var value = cm.hexToRgb("FFA07A");
125 expect(value.r).toEqual(255); // red channel
126 expect(value.g).toEqual(160); // green channel
127 expect(value.b).toEqual(122); // blue channel
128 });
129 });
130}); \ No newline at end of file
diff --git a/tests/unit-tests/file-io-test.js b/tests/unit-tests/file-io-test.js
new file mode 100644
index 00000000..5b197d16
--- /dev/null
+++ b/tests/unit-tests/file-io-test.js
@@ -0,0 +1,610 @@
1var Montage = require("montage/core/core").Montage;
2var cmObject = require("ninjaapp/js/io/system/coreioapi"),
3 cm = cmObject.CoreIoApi,
4 rootPath1 = "Users/kfg834/Documents/Ninja Projects/FTest1/", //specify any path within your ninja projects root folder
5 rootPath2 = "Users/kfg834/Documents/Ninja Projects/FTest2/",
6 InitDirPath1 = "Users/kfg834/Documents/Ninja Projects/";
7
8describe('Shell API', function() {
9
10 describe('File IO', function() {
11
12 // File Create Tests
13 describe('File Create Tests', function() {
14
15 it('Create File', function() {
16 Creating Initial Main Directories in the documents folder
17 var dir = {uri:InitDirPath1 + "FTest1"};
18 var retVal = cm.createDirectory(dir);
19 var dir = {uri:InitDirPath1 + "FileTest2"};
20 var retVal = cm.createDirectory(dir);
21
22 var file = {uri:rootPath1 + "NewFile1.txt"};
23
24 var retVal = cm.createFile(file);
25 console.log("First create returned:" + retVal.status);
26
27 expect(retVal.success).toEqual(true);
28 expect(retVal.status).toEqual(201);
29
30 });
31
32
33 it('Create Existing File', function() {
34
35 var file = {uri:rootPath1 + "NewFile1.txt"};
36 var retVal = cm.createFile(file);
37
38 expect(retVal.success).toEqual(true);
39 expect(retVal.status).toEqual(400);
40
41 //Cleaning up the files by deleting after each test
42 var file = {uri:rootPath1 + "NewFile1.txt"};
43 var retVal = cm.deleteFile(file);
44
45 });
46
47 });
48
49
50 // File Delete
51 describe('File Delete Tests', function() {
52
53 it('Delete File', function() {
54
55 //Set up
56 var file = {uri:rootPath1 + "NewFile1.txt"};
57 var retVal = cm.createFile(file);
58
59 var file = {uri:rootPath1 + "NewFile1.txt"};
60 var retVal = cm.deleteFile(file);
61
62 expect(retVal.success).toEqual(true);
63 expect(retVal.status).toEqual(204);
64
65 });
66
67 });
68
69
70 // File Exists test
71 describe('File Exists Tests', function() {
72
73 it('File Exists', function() {
74
75 //Set up
76 var file = {uri:rootPath1 + "NewFile1.txt"};
77 var retVal = cm.createFile(file);
78 console.log("Called createFile for Exists which returned " + retVal);
79
80 var file = {uri:rootPath1 + "NewFile1.txt"};
81
82 var retVal = cm.fileExists(file);
83
84 expect(retVal.success).toEqual(true);
85 expect(retVal.status).toEqual(204);
86
87 });
88
89 it('File Does Not Exist', function() {
90
91 var file = {uri:rootPath1 +"NewFile2.txt"};
92
93 var retVal = cm.fileExists(file);
94
95 expect(retVal.success).toEqual(true);
96 expect(retVal.status).toEqual(404);
97
98 //Clean up
99 var file = {uri:rootPath1 + "NewFile1.txt"};