|
| 1 | +var jsonProject = require('./fixtures/full-project') |
| 2 | + fullProjectStr = JSON.stringify(jsonProject), |
| 3 | + path = require('path'), |
| 4 | + pbx = require('../lib/pbxProject'), |
| 5 | + pbxFile = require('../lib/pbxFile'), |
| 6 | + proj = new pbx('.'), |
| 7 | + singleDataModelFilePath = __dirname + '/fixtures/single-data-model.xcdatamodeld', |
| 8 | + multipleDataModelFilePath = __dirname + '/fixtures/multiple-data-model.xcdatamodeld'; |
| 9 | + |
| 10 | +function cleanHash() { |
| 11 | + return JSON.parse(fullProjectStr); |
| 12 | +} |
| 13 | + |
| 14 | +exports.setUp = function (callback) { |
| 15 | + proj.hash = cleanHash(); |
| 16 | + callback(); |
| 17 | +} |
| 18 | + |
| 19 | +exports.dataModelDocument = { |
| 20 | + 'should return a pbxFile': function (test) { |
| 21 | + var newFile = proj.addDataModelDocument(singleDataModelFilePath); |
| 22 | + |
| 23 | + test.equal(newFile.constructor, pbxFile); |
| 24 | + test.done() |
| 25 | + }, |
| 26 | + 'should set a uuid on the pbxFile': function (test) { |
| 27 | + var newFile = proj.addDataModelDocument(singleDataModelFilePath); |
| 28 | + |
| 29 | + test.ok(newFile.uuid); |
| 30 | + test.done() |
| 31 | + }, |
| 32 | + 'should set a fileRef on the pbxFile': function (test) { |
| 33 | + var newFile = proj.addDataModelDocument(singleDataModelFilePath); |
| 34 | + |
| 35 | + test.ok(newFile.fileRef); |
| 36 | + test.done() |
| 37 | + }, |
| 38 | + 'should set an optional target on the pbxFile': function (test) { |
| 39 | + var newFile = proj.addDataModelDocument(singleDataModelFilePath, undefined, { target: target }), |
| 40 | + target = proj.findTargetKey('TestApp'); |
| 41 | + |
| 42 | + test.equal(newFile.target, target); |
| 43 | + test.done() |
| 44 | + }, |
| 45 | + 'should populate the PBXBuildFile section with 2 fields': function (test) { |
| 46 | + var newFile = proj.addDataModelDocument(singleDataModelFilePath), |
| 47 | + buildFileSection = proj.pbxBuildFileSection(), |
| 48 | + bfsLength = Object.keys(buildFileSection).length; |
| 49 | + |
| 50 | + test.equal(59 + 1, bfsLength); |
| 51 | + test.ok(buildFileSection[newFile.uuid]); |
| 52 | + test.ok(buildFileSection[newFile.uuid + '_comment']); |
| 53 | + |
| 54 | + test.done(); |
| 55 | + }, |
| 56 | + 'should populate the PBXFileReference section with 2 fields for single model document': function (test) { |
| 57 | + var newFile = proj.addDataModelDocument(singleDataModelFilePath), |
| 58 | + fileRefSection = proj.pbxFileReferenceSection(), |
| 59 | + frsLength = Object.keys(fileRefSection).length; |
| 60 | + |
| 61 | + test.equal(66 + 2, frsLength); |
| 62 | + test.ok(fileRefSection[newFile.models[0].fileRef]); |
| 63 | + test.ok(fileRefSection[newFile.models[0].fileRef + '_comment']); |
| 64 | + |
| 65 | + test.done(); |
| 66 | + }, |
| 67 | + 'should populate the PBXFileReference section with 2 fields for each model of a model document': function (test) { |
| 68 | + var newFile = proj.addDataModelDocument(multipleDataModelFilePath), |
| 69 | + fileRefSection = proj.pbxFileReferenceSection(), |
| 70 | + frsLength = Object.keys(fileRefSection).length; |
| 71 | + |
| 72 | + test.equal(66 + 2 * 2, frsLength); |
| 73 | + test.ok(fileRefSection[newFile.models[0].fileRef]); |
| 74 | + test.ok(fileRefSection[newFile.models[0].fileRef + '_comment']); |
| 75 | + test.ok(fileRefSection[newFile.models[1].fileRef]); |
| 76 | + test.ok(fileRefSection[newFile.models[1].fileRef + '_comment']); |
| 77 | + |
| 78 | + test.done(); |
| 79 | + }, |
| 80 | + 'should add to resources group by default': function (test) { |
| 81 | + var newFile = proj.addDataModelDocument(singleDataModelFilePath); |
| 82 | + groupChildren = proj.pbxGroupByName('Resources').children, |
| 83 | + found = false; |
| 84 | + |
| 85 | + for (var index in groupChildren) { |
| 86 | + if (groupChildren[index].comment === 'single-data-model.xcdatamodeld') { |
| 87 | + found = true; |
| 88 | + break; |
| 89 | + } |
| 90 | + } |
| 91 | + test.ok(found); |
| 92 | + test.done(); |
| 93 | + }, |
| 94 | + 'should add to group specified by key': function (test) { |
| 95 | + var group = 'Frameworks', |
| 96 | + newFile = proj.addDataModelDocument(singleDataModelFilePath, proj.findPBXGroupKey({ name: group })); |
| 97 | + groupChildren = proj.pbxGroupByName(group).children; |
| 98 | + |
| 99 | + var found = false; |
| 100 | + for (var index in groupChildren) { |
| 101 | + if (groupChildren[index].comment === path.basename(singleDataModelFilePath)) { |
| 102 | + found = true; |
| 103 | + break; |
| 104 | + } |
| 105 | + } |
| 106 | + test.ok(found); |
| 107 | + test.done(); |
| 108 | + }, |
| 109 | + 'should add to group specified by name': function (test) { |
| 110 | + var group = 'Frameworks', |
| 111 | + newFile = proj.addDataModelDocument(singleDataModelFilePath, group); |
| 112 | + groupChildren = proj.pbxGroupByName(group).children; |
| 113 | + |
| 114 | + var found = false; |
| 115 | + for (var index in groupChildren) { |
| 116 | + if (groupChildren[index].comment === path.basename(singleDataModelFilePath)) { |
| 117 | + found = true; |
| 118 | + break; |
| 119 | + } |
| 120 | + } |
| 121 | + test.ok(found); |
| 122 | + test.done(); |
| 123 | + }, |
| 124 | + 'should add to the PBXSourcesBuildPhase': function (test) { |
| 125 | + var newFile = proj.addDataModelDocument(singleDataModelFilePath), |
| 126 | + sources = proj.pbxSourcesBuildPhaseObj(); |
| 127 | + |
| 128 | + test.equal(sources.files.length, 2 + 1); |
| 129 | + test.done(); |
| 130 | + }, |
| 131 | + 'should create a XCVersionGroup section': function (test) { |
| 132 | + var newFile = proj.addDataModelDocument(singleDataModelFilePath), |
| 133 | + xcVersionGroupSection = proj.xcVersionGroupSection(); |
| 134 | + |
| 135 | + test.ok(xcVersionGroupSection[newFile.fileRef]); |
| 136 | + test.done(); |
| 137 | + }, |
| 138 | + 'should populate the XCVersionGroup comment correctly': function (test) { |
| 139 | + var newFile = proj.addDataModelDocument(singleDataModelFilePath), |
| 140 | + xcVersionGroupSection = proj.xcVersionGroupSection(), |
| 141 | + commentKey = newFile.fileRef + '_comment'; |
| 142 | + |
| 143 | + test.equal(xcVersionGroupSection[commentKey], path.basename(singleDataModelFilePath)); |
| 144 | + test.done(); |
| 145 | + }, |
| 146 | + 'should add the XCVersionGroup object correctly': function (test) { |
| 147 | + var newFile = proj.addDataModelDocument(singleDataModelFilePath), |
| 148 | + xcVersionGroupSection = proj.xcVersionGroupSection(), |
| 149 | + xcVersionGroupEntry = xcVersionGroupSection[newFile.fileRef]; |
| 150 | + |
| 151 | + test.equal(xcVersionGroupEntry.isa, 'XCVersionGroup'); |
| 152 | + test.equal(xcVersionGroupEntry.children[0], newFile.models[0].fileRef); |
| 153 | + test.equal(xcVersionGroupEntry.currentVersion, newFile.currentModel.fileRef); |
| 154 | + test.equal(xcVersionGroupEntry.name, path.basename(singleDataModelFilePath)); |
| 155 | + test.equal(xcVersionGroupEntry.path, singleDataModelFilePath); |
| 156 | + test.equal(xcVersionGroupEntry.sourceTree, '"<group>"'); |
| 157 | + test.equal(xcVersionGroupEntry.versionGroupType, 'wrapper.xcdatamodel'); |
| 158 | + |
| 159 | + test.done(); |
| 160 | + } |
| 161 | +} |
0 commit comments