|
| 1 | +var fullProject = require('./fixtures/full-project') |
| 2 | + fullProjectStr = JSON.stringify(fullProject), |
| 3 | + pbx = require('../lib/pbxProject'), |
| 4 | + proj = new pbx('.'); |
| 5 | + |
| 6 | +function cleanHash() { |
| 7 | + return JSON.parse(fullProjectStr); |
| 8 | +} |
| 9 | + |
| 10 | +exports.setUp = function (callback) { |
| 11 | + proj.hash = cleanHash(); |
| 12 | + callback(); |
| 13 | +} |
| 14 | + |
| 15 | +exports.addPbxGroup = { |
| 16 | + 'should return a pbxGroup': function (test) { |
| 17 | + var pbxGroup = proj.addPbxGroup(['file.m'], 'MyGroup', 'Application', 'Application', '"<group>"'); |
| 18 | + |
| 19 | + test.ok(typeof pbxGroup === 'object'); |
| 20 | + test.done() |
| 21 | + }, |
| 22 | + 'should set a uuid on the pbxGroup': function (test) { |
| 23 | + var pbxGroup = proj.addPbxGroup(['file.m'], 'MyGroup', 'Application', 'Application', '"<group>"'); |
| 24 | + |
| 25 | + test.ok(pbxGroup.uuid); |
| 26 | + test.done() |
| 27 | + }, |
| 28 | + 'should add all files to pbxGroup': function (test) { |
| 29 | + var pbxGroup = proj.addPbxGroup(['file.m'], 'MyGroup', 'Application', 'Application', '"<group>"'); |
| 30 | + for (var index = 0; index < pbxGroup.pbxGroup.children.length; index++) { |
| 31 | + var file = pbxGroup.pbxGroup.children[index]; |
| 32 | + test.ok(file.value); |
| 33 | + } |
| 34 | + |
| 35 | + test.done() |
| 36 | + }, |
| 37 | + 'should add the PBXGroup object correctly': function (test) { |
| 38 | + var pbxGroup = proj.addPbxGroup(['file.m'], 'MyGroup', 'Application', '"<group>"'); |
| 39 | + pbxGroupInPbx = proj.pbxGroupByName('MyGroup'); |
| 40 | + |
| 41 | + test.equal(pbxGroupInPbx.children, pbxGroup.pbxGroup.children); |
| 42 | + test.equal(pbxGroupInPbx.isa, 'PBXGroup'); |
| 43 | + test.equal(pbxGroupInPbx.path, 'Application'); |
| 44 | + test.equal(pbxGroupInPbx.sourceTree, '"<group>"'); |
| 45 | + test.done(); |
| 46 | + }, |
| 47 | + 'should add <group> sourceTree if no other specified': function (test) { |
| 48 | + var pbxGroup = proj.addPbxGroup(['file.m'], 'MyGroup', 'Application'); |
| 49 | + pbxGroupInPbx = proj.pbxGroupByName('MyGroup'); |
| 50 | + |
| 51 | + test.equal(pbxGroupInPbx.sourceTree, '"<group>"'); |
| 52 | + test.done(); |
| 53 | + }, |
| 54 | + 'should add each of the files to PBXBuildFile section': function (test) { |
| 55 | + var buildFileSection = proj.pbxBuildFileSection(); |
| 56 | + for (var key in buildFileSection) { |
| 57 | + test.notEqual(buildFileSection[key].fileRef_comment, 'file.m'); |
| 58 | + test.notEqual(buildFileSection[key].fileRef_comment, 'assets.bundle'); |
| 59 | + } |
| 60 | + |
| 61 | + var initialBuildFileSectionItemsCount = Object.keys(buildFileSection), |
| 62 | + pbxGroup = proj.addPbxGroup(['file.m', 'assets.bundle'], 'MyGroup', 'Application', '"<group>"'), |
| 63 | + afterAdditionBuildFileSectionItemsCount = Object.keys(buildFileSection); |
| 64 | + |
| 65 | + // for each file added in the build file section two keyes are added - one for the object and one for the comment |
| 66 | + test.equal(initialBuildFileSectionItemsCount.length, afterAdditionBuildFileSectionItemsCount.length - 4); |
| 67 | + test.done(); |
| 68 | + }, |
| 69 | + 'should not add any of the files to PBXBuildFile section if already added': function (test) { |
| 70 | + var buildFileSection = proj.pbxBuildFileSection(), |
| 71 | + initialBuildFileSectionItemsCount = Object.keys(buildFileSection), |
| 72 | + pbxGroup = proj.addPbxGroup(['AppDelegate.m', 'AppDelegate.h'], 'MyGroup', 'Application', '"<group>"'), |
| 73 | + afterAdditionBuildFileSectionItemsCount = Object.keys(buildFileSection); |
| 74 | + |
| 75 | + test.deepEqual(initialBuildFileSectionItemsCount, afterAdditionBuildFileSectionItemsCount); |
| 76 | + test.done(); |
| 77 | + }, |
| 78 | + 'should not add any of the files to PBXBuildFile section when they contain special symbols and are already added': function (test) { |
| 79 | + var buildFileSection = proj.pbxBuildFileSection(), |
| 80 | + initialBuildFileSectionItemsCount = Object.keys(buildFileSection), |
| 81 | + pbxGroup = proj.addPbxGroup(['KitchenSinktablet.app'], 'MyGroup', 'Application', '"<group>"'), |
| 82 | + afterAdditionBuildFileSectionItemsCount = Object.keys(buildFileSection); |
| 83 | + |
| 84 | + test.deepEqual(initialBuildFileSectionItemsCount, afterAdditionBuildFileSectionItemsCount); |
| 85 | + test.done(); |
| 86 | + }, |
| 87 | + 'should add all files which are not added and not add files already added to PBXBuildFile section': function (test) { |
| 88 | + var buildFileSection = proj.pbxBuildFileSection(); |
| 89 | + for (var key in buildFileSection) { |
| 90 | + test.notEqual(buildFileSection[key].fileRef_comment, 'file.m'); |
| 91 | + test.notEqual(buildFileSection[key].fileRef_comment, 'assets.bundle'); |
| 92 | + } |
| 93 | + |
| 94 | + var initialBuildFileSectionItemsCount = Object.keys(buildFileSection), |
| 95 | + pbxGroup = proj.addPbxGroup(['AppDelegate.m', 'AppDelegate.h', 'file.m', 'assets.bundle'], 'MyGroup', 'Application', '"<group>"'), |
| 96 | + afterAdditionBuildFileSectionItemsCount = Object.keys(buildFileSection); |
| 97 | + |
| 98 | + // for each file added in the build file section two keyes are added - one for the object and one for the comment |
| 99 | + test.equal(initialBuildFileSectionItemsCount.length, afterAdditionBuildFileSectionItemsCount.length - 4); |
| 100 | + test.done(); |
| 101 | + }, |
| 102 | + 'should add each of the files to PBXFileReference section': function (test) { |
| 103 | + var fileReference = proj.pbxFileReferenceSection(); |
| 104 | + for (var key in fileReference) { |
| 105 | + test.notEqual(fileReference[key].fileRef_comment, 'file.m'); |
| 106 | + test.notEqual(fileReference[key].fileRef_comment, 'assets.bundle'); |
| 107 | + } |
| 108 | + var pbxGroup = proj.addPbxGroup(['file.m', 'assets.bundle'], 'MyGroup', 'Application', '"<group>"'); |
| 109 | + for (var index = 0; index < pbxGroup.pbxGroup.children.length; index++) { |
| 110 | + var file = pbxGroup.pbxGroup.children[index]; |
| 111 | + test.ok(fileReference[file.value]); |
| 112 | + } |
| 113 | + |
| 114 | + test.done(); |
| 115 | + }, |
| 116 | + 'should not add any of the files to PBXFileReference section if already added': function (test) { |
| 117 | + var fileReference = proj.pbxFileReferenceSection (), |
| 118 | + initialBuildFileSectionItemsCount = Object.keys(fileReference), |
| 119 | + pbxGroup = proj.addPbxGroup(['AppDelegate.m', 'AppDelegate.h'], 'MyGroup', 'Application', '"<group>"'), |
| 120 | + afterAdditionBuildFileSectionItemsCount = Object.keys(fileReference); |
| 121 | + |
| 122 | + test.deepEqual(initialBuildFileSectionItemsCount, afterAdditionBuildFileSectionItemsCount); |
| 123 | + test.done(); |
| 124 | + }, |
| 125 | + 'should not add any of the files to PBXFileReference section when they contain special symbols and are already added': function (test) { |
| 126 | + var fileReference = proj.pbxFileReferenceSection (), |
| 127 | + initialBuildFileSectionItemsCount = Object.keys(fileReference), |
| 128 | + pbxGroup = proj.addPbxGroup(['KitchenSinktablet.app'], 'MyGroup', 'Application', '"<group>"'), |
| 129 | + afterAdditionBuildFileSectionItemsCount = Object.keys(fileReference); |
| 130 | + |
| 131 | + test.deepEqual(initialBuildFileSectionItemsCount, afterAdditionBuildFileSectionItemsCount); |
| 132 | + test.done(); |
| 133 | + }, |
| 134 | + 'should add all files which are not added and not add files already added to PBXFileReference section': function (test) { |
| 135 | + var fileReference = proj.pbxFileReferenceSection (); |
| 136 | + for (var key in fileReference) { |
| 137 | + test.notEqual(fileReference[key].fileRef_comment, 'file.m'); |
| 138 | + test.notEqual(fileReference[key].fileRef_comment, 'assets.bundle'); |
| 139 | + } |
| 140 | + |
| 141 | + var initialBuildFileSectionItemsCount = Object.keys(fileReference), |
| 142 | + pbxGroup = proj.addPbxGroup(['AppDelegate.m', 'AppDelegate.h', 'file.m', 'assets.bundle'], 'MyGroup', 'Application', '"<group>"'), |
| 143 | + afterAdditionBuildFileSectionItemsCount = Object.keys(fileReference); |
| 144 | + |
| 145 | + // for each file added in the file reference section two keyes are added - one for the object and one for the comment |
| 146 | + test.equal(initialBuildFileSectionItemsCount.length, afterAdditionBuildFileSectionItemsCount.length - 4); |
| 147 | + test.done(); |
| 148 | + } |
| 149 | +} |
0 commit comments