Skip to content

Commit d09c261

Browse files
committed
adding removeResourceFile.js unit test
1 parent 8a56d12 commit d09c261

File tree

1 file changed

+184
-0
lines changed

1 file changed

+184
-0
lines changed

test/removeResourceFile.js

Lines changed: 184 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,184 @@
1+
var fullProject = require('./fixtures/full-project')
2+
fullProjectStr = JSON.stringify(fullProject),
3+
pbx = require('../lib/pbxProject'),
4+
pbxFile = require('../lib/pbxFile'),
5+
proj = new pbx('.');
6+
7+
function cleanHash() {
8+
return JSON.parse(fullProjectStr);
9+
}
10+
11+
exports.setUp = function (callback) {
12+
proj.hash = cleanHash();
13+
callback();
14+
}
15+
16+
exports.removeResourceFile = {
17+
'should return a pbxFile': function (test) {
18+
var newFile = proj.addResourceFile('assets.bundle');
19+
20+
test.equal(newFile.constructor, pbxFile);
21+
22+
var deletedFile = proj.removeResourceFile('assets.bundle');
23+
24+
test.equal(deletedFile.constructor, pbxFile);
25+
26+
test.done()
27+
},
28+
'should set a uuid on the pbxFile': function (test) {
29+
var newFile = proj.addResourceFile('assets.bundle');
30+
31+
test.ok(newFile.uuid);
32+
33+
var deletedFile = proj.removeResourceFile('assets.bundle');
34+
35+
test.ok(deletedFile.uuid);
36+
37+
test.done()
38+
},
39+
'should set a fileRef on the pbxFile': function (test) {
40+
var newFile = proj.addResourceFile('assets.bundle');
41+
42+
test.ok(newFile.fileRef);
43+
44+
var deletedFile = proj.removeResourceFile('assets.bundle');
45+
46+
test.ok(deletedFile.fileRef);
47+
48+
test.done()
49+
},
50+
'should remove 2 fields from the PBXBuildFile section': function (test) {
51+
var newFile = proj.addResourceFile('assets.bundle'),
52+
buildFileSection = proj.pbxBuildFileSection(),
53+
bfsLength = Object.keys(buildFileSection).length;
54+
55+
test.equal(60, bfsLength);
56+
test.ok(buildFileSection[newFile.uuid]);
57+
test.ok(buildFileSection[newFile.uuid + '_comment']);
58+
59+
var deletedFile = proj.removeResourceFile('assets.bundle'),
60+
buildFileSection = proj.pbxBuildFileSection(),
61+
bfsLength = Object.keys(buildFileSection).length;
62+
63+
test.equal(58, bfsLength);
64+
test.ok(!buildFileSection[deletedFile.uuid]);
65+
test.ok(!buildFileSection[deletedFile.uuid + '_comment']);
66+
67+
test.done();
68+
},
69+
'should remove the PBXBuildFile comment correctly': function (test) {
70+
var newFile = proj.addResourceFile('assets.bundle'),
71+
commentKey = newFile.uuid + '_comment',
72+
buildFileSection = proj.pbxBuildFileSection();
73+
74+
test.equal(buildFileSection[commentKey], 'assets.bundle in Resources');
75+
76+
var deletedFile = proj.removeResourceFile('assets.bundle'),
77+
commentKey = deletedFile.uuid + '_comment',
78+
buildFileSection = proj.pbxBuildFileSection();
79+
80+
test.ok(!buildFileSection[commentKey]);
81+
82+
test.done();
83+
},
84+
'should remove the PBXBuildFile object correctly': function (test) {
85+
var newFile = proj.addResourceFile('assets.bundle'),
86+
buildFileSection = proj.pbxBuildFileSection(),
87+
buildFileEntry = buildFileSection[newFile.uuid];
88+
89+
test.equal(buildFileEntry.isa, 'PBXBuildFile');
90+
test.equal(buildFileEntry.fileRef, newFile.fileRef);
91+
test.equal(buildFileEntry.fileRef_comment, 'assets.bundle');
92+
93+
var deletedFile = proj.removeResourceFile('assets.bundle'),
94+
buildFileSection = proj.pbxBuildFileSection(),
95+
buildFileEntry = buildFileSection[deletedFile.uuid];
96+
97+
test.ok(!buildFileEntry);
98+
99+
test.done();
100+
},
101+
'should remove 2 fields from the PBXFileReference section': function (test) {
102+
var newFile = proj.addResourceFile('assets.bundle'),
103+
fileRefSection = proj.pbxFileReferenceSection(),
104+
frsLength = Object.keys(fileRefSection).length;
105+
106+
test.equal(68, frsLength);
107+
test.ok(fileRefSection[newFile.fileRef]);
108+
test.ok(fileRefSection[newFile.fileRef + '_comment']);
109+
110+
var deletedFile = proj.removeResourceFile('assets.bundle'),
111+
fileRefSection = proj.pbxFileReferenceSection(),
112+
frsLength = Object.keys(fileRefSection).length;
113+
114+
test.equal(66, frsLength);
115+
test.ok(!fileRefSection[deletedFile.fileRef]);
116+
test.ok(!fileRefSection[deletedFile.fileRef + '_comment']);
117+
118+
test.done();
119+
},
120+
'should populate the PBXFileReference comment correctly': function (test) {
121+
var newFile = proj.addResourceFile('assets.bundle'),
122+
fileRefSection = proj.pbxFileReferenceSection(),
123+
commentKey = newFile.fileRef + '_comment';
124+
125+
test.equal(fileRefSection[commentKey], 'assets.bundle');
126+
127+
var deletedFile = proj.removeResourceFile('assets.bundle'),
128+
fileRefSection = proj.pbxFileReferenceSection(),
129+
commentKey = deletedFile.fileRef + '_comment';
130+
131+
test.ok(!fileRefSection[commentKey]);
132+
test.done();
133+
},
134+
'should remove the PBXFileReference object correctly': function (test) {
135+
delete proj.pbxGroupByName('Plugins').path;
136+
137+
var newFile = proj.addResourceFile('Plugins/assets.bundle'),
138+
fileRefSection = proj.pbxFileReferenceSection(),
139+
fileRefEntry = fileRefSection[newFile.fileRef];
140+
141+
test.equal(fileRefEntry.isa, 'PBXFileReference');
142+
test.equal(fileRefEntry.fileEncoding, undefined);
143+
test.equal(fileRefEntry.lastKnownFileType, '"wrapper.plug-in"');
144+
test.equal(fileRefEntry.name, 'assets.bundle');
145+
test.equal(fileRefEntry.path, 'Plugins/assets.bundle');
146+
test.equal(fileRefEntry.sourceTree, '"<group>"');
147+
148+
var deletedFile = proj.removeResourceFile('Plugins/assets.bundle'),
149+
fileRefSection = proj.pbxFileReferenceSection(),
150+
fileRefEntry = fileRefSection[deletedFile.fileRef];
151+
152+
test.ok(!fileRefEntry);
153+
154+
test.done();
155+
},
156+
'should remove from the Plugins PBXGroup group': function (test) {
157+
var newFile = proj.addResourceFile('Plugins/assets.bundle'),
158+
plugins = proj.pbxGroupByName('Plugins');
159+
160+
test.equal(plugins.children.length, 1);
161+
162+
var deletedFile = proj.removeResourceFile('Plugins/assets.bundle'),
163+
plugins = proj.pbxGroupByName('Plugins');
164+
165+
test.equal(plugins.children.length, 0);
166+
test.done();
167+
},
168+
'should remove to the PBXSourcesBuildPhase': function (test) {
169+
var newFile = proj.addResourceFile('Plugins/assets.bundle'),
170+
sources = proj.pbxResourcesBuildPhaseObj();
171+
172+
test.equal(sources.files.length, 13);
173+
174+
var deletedFile = proj.removeResourceFile('Plugins/assets.bundle'),
175+
sources = proj.pbxResourcesBuildPhaseObj();
176+
177+
test.equal(sources.files.length, 12);
178+
test.done();
179+
},
180+
tearDown: function (callback) {
181+
delete proj.pbxGroupByName('Plugins').path;
182+
callback();
183+
}
184+
}

0 commit comments

Comments
 (0)