|
| 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.addResourceFile = { |
| 17 | + 'should return a pbxFile': function (test) { |
| 18 | + var newFile = proj.addResourceFile('assets.bundle'); |
| 19 | + |
| 20 | + test.equal(newFile.constructor, pbxFile); |
| 21 | + test.done() |
| 22 | + }, |
| 23 | + 'should set a uuid on the pbxFile': function (test) { |
| 24 | + var newFile = proj.addResourceFile('assets.bundle'); |
| 25 | + |
| 26 | + test.ok(newFile.uuid); |
| 27 | + test.done() |
| 28 | + }, |
| 29 | + 'should set a fileRef on the pbxFile': function (test) { |
| 30 | + var newFile = proj.addResourceFile('assets.bundle'); |
| 31 | + |
| 32 | + test.ok(newFile.fileRef); |
| 33 | + test.done() |
| 34 | + }, |
| 35 | + 'should populate the PBXBuildFile section with 2 fields': function (test) { |
| 36 | + var newFile = proj.addResourceFile('assets.bundle'), |
| 37 | + buildFileSection = proj.pbxBuildFileSection(), |
| 38 | + bfsLength = Object.keys(buildFileSection).length; |
| 39 | + |
| 40 | + test.equal(60, bfsLength); |
| 41 | + test.ok(buildFileSection[newFile.uuid]); |
| 42 | + test.ok(buildFileSection[newFile.uuid + '_comment']); |
| 43 | + |
| 44 | + test.done(); |
| 45 | + }, |
| 46 | + 'should add the PBXBuildFile comment correctly': function (test) { |
| 47 | + var newFile = proj.addResourceFile('assets.bundle'), |
| 48 | + commentKey = newFile.uuid + '_comment', |
| 49 | + buildFileSection = proj.pbxBuildFileSection(); |
| 50 | + |
| 51 | + test.equal(buildFileSection[commentKey], 'assets.bundle in Resources'); |
| 52 | + test.done(); |
| 53 | + }, |
| 54 | + 'should add the PBXBuildFile object correctly': function (test) { |
| 55 | + var newFile = proj.addResourceFile('assets.bundle'), |
| 56 | + buildFileSection = proj.pbxBuildFileSection(), |
| 57 | + buildFileEntry = buildFileSection[newFile.uuid]; |
| 58 | + |
| 59 | + test.equal(buildFileEntry.isa, 'PBXBuildFile'); |
| 60 | + test.equal(buildFileEntry.fileRef, newFile.fileRef); |
| 61 | + test.equal(buildFileEntry.fileRef_comment, 'assets.bundle'); |
| 62 | + |
| 63 | + test.done(); |
| 64 | + }, |
| 65 | + 'should populate the PBXFileReference section with 2 fields': function (test) { |
| 66 | + var newFile = proj.addResourceFile('assets.bundle'), |
| 67 | + fileRefSection = proj.pbxFileReferenceSection(), |
| 68 | + frsLength = Object.keys(fileRefSection).length; |
| 69 | + |
| 70 | + test.equal(68, frsLength); |
| 71 | + test.ok(fileRefSection[newFile.fileRef]); |
| 72 | + test.ok(fileRefSection[newFile.fileRef + '_comment']); |
| 73 | + |
| 74 | + test.done(); |
| 75 | + }, |
| 76 | + 'should populate the PBXFileReference comment correctly': function (test) { |
| 77 | + var newFile = proj.addResourceFile('assets.bundle'), |
| 78 | + fileRefSection = proj.pbxFileReferenceSection(), |
| 79 | + commentKey = newFile.fileRef + '_comment'; |
| 80 | + |
| 81 | + test.equal(fileRefSection[commentKey], 'assets.bundle'); |
| 82 | + test.done(); |
| 83 | + }, |
| 84 | + 'should add the PBXFileReference object correctly': function (test) { |
| 85 | + var newFile = proj.addResourceFile('Plugins/assets.bundle'), |
| 86 | + fileRefSection = proj.pbxFileReferenceSection(), |
| 87 | + fileRefEntry = fileRefSection[newFile.fileRef]; |
| 88 | + |
| 89 | + test.equal(fileRefEntry.isa, 'PBXFileReference'); |
| 90 | + test.equal(fileRefEntry.fileEncoding, undefined); |
| 91 | + test.equal(fileRefEntry.lastKnownFileType, '"wrapper.plug-in"'); |
| 92 | + test.equal(fileRefEntry.name, 'assets.bundle'); |
| 93 | + test.equal(fileRefEntry.path, 'Plugins/assets.bundle'); |
| 94 | + test.equal(fileRefEntry.sourceTree, '"<group>"'); |
| 95 | + |
| 96 | + test.done(); |
| 97 | + }, |
| 98 | + 'should add to the Plugins PBXGroup group': function (test) { |
| 99 | + var newFile = proj.addResourceFile('Plugins/assets.bundle'), |
| 100 | + plugins = proj.pbxGroupByName('Plugins'); |
| 101 | + |
| 102 | + test.equal(plugins.children.length, 1); |
| 103 | + test.done(); |
| 104 | + }, |
| 105 | + 'should have the right values for the PBXGroup entry': function (test) { |
| 106 | + var newFile = proj.addResourceFile('Plugins/assets.bundle'), |
| 107 | + plugins = proj.pbxGroupByName('Plugins'), |
| 108 | + pluginObj = plugins.children[0]; |
| 109 | + |
| 110 | + test.equal(pluginObj.comment, 'assets.bundle'); |
| 111 | + test.equal(pluginObj.value, newFile.fileRef); |
| 112 | + test.done(); |
| 113 | + }, |
| 114 | + 'should add to the PBXSourcesBuildPhase': function (test) { |
| 115 | + var newFile = proj.addResourceFile('Plugins/assets.bundle'), |
| 116 | + sources = proj.pbxResourcesBuildPhaseObj(); |
| 117 | + |
| 118 | + test.equal(sources.files.length, 13); |
| 119 | + test.done(); |
| 120 | + }, |
| 121 | + 'should have the right values for the Sources entry': function (test) { |
| 122 | + var newFile = proj.addResourceFile('Plugins/assets.bundle'), |
| 123 | + sources = proj.pbxResourcesBuildPhaseObj(), |
| 124 | + sourceObj = sources.files[12]; |
| 125 | + |
| 126 | + test.equal(sourceObj.comment, 'assets.bundle in Resources'); |
| 127 | + test.equal(sourceObj.value, newFile.uuid); |
| 128 | + test.done(); |
| 129 | + } |
| 130 | +} |
0 commit comments