Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 1 | "use strict"; |
| 2 | /* Unit tests for Toaster's JS */ |
| 3 | |
| 4 | /* libtoaster tests */ |
| 5 | |
| 6 | QUnit.test("Layer alert notification", function(assert) { |
| 7 | var layer = { |
| 8 | "layerdetailurl":"/toastergui/project/1/layer/22", |
| 9 | "vcs_url":"git://example.com/example.git", |
| 10 | "detail":"[ git://example.com/example.git | master ]", |
| 11 | "vcs_reference":"master", |
| 12 | "id": 22, |
| 13 | "name":"meta-example" |
| 14 | }; |
| 15 | |
| 16 | var correctResponse = "You have added <strong>3</strong> layers to your project: <a id=\"layer-affected-name\" href=\"/toastergui/project/1/layer/22\">meta-example</a> and its dependencies <a href=\"/toastergui/project/1/layer/9\" data-original-title=\"\" title=\"\">meta-example-two</a>, <a href=\"/toastergui/project/1/layer/9\" data-original-title=\"\" title=\"\">meta-example-three</a>"; |
| 17 | |
| 18 | var layerDepsList = [ |
| 19 | { |
| 20 | "layerdetailurl":"/toastergui/project/1/layer/9", |
| 21 | "vcs_url":"git://example.com/example.git", |
| 22 | "detail":"[ git://example.com/example.git | master ]", |
| 23 | "vcs_reference":"master", |
| 24 | "id": 9, |
| 25 | "name":"meta-example-two" |
| 26 | }, |
| 27 | { |
| 28 | "layerdetailurl":"/toastergui/project/1/layer/9", |
| 29 | "vcs_url":"git://example.com/example.git", |
| 30 | "detail":"[ git://example.com/example.git | master ]", |
| 31 | "vcs_reference":"master", |
| 32 | "id": 10, |
| 33 | "name":"meta-example-three" |
| 34 | }, |
| 35 | ]; |
| 36 | |
| 37 | var msg = libtoaster.makeLayerAddRmAlertMsg(layer, layerDepsList, true); |
| 38 | var test = $("<div></div>"); |
| 39 | |
| 40 | test.html(msg); |
| 41 | |
| 42 | assert.equal(test.children("strong").text(), "3"); |
| 43 | assert.equal(test.children("a").length, 3); |
| 44 | }); |
| 45 | |
| 46 | QUnit.test("Project info", function(assert){ |
| 47 | var done = assert.async(); |
| 48 | libtoaster.getProjectInfo(libtoaster.ctx.projectPageUrl, function(prjInfo){ |
| 49 | assert.ok(prjInfo.machine.name); |
| 50 | assert.ok(prjInfo.releases.length > 0); |
| 51 | assert.ok(prjInfo.layers.length > 0); |
| 52 | assert.ok(prjInfo.freqtargets); |
| 53 | assert.ok(prjInfo.release); |
| 54 | done(); |
| 55 | }); |
| 56 | }); |
| 57 | |
| 58 | QUnit.test("Show notification", function(assert){ |
| 59 | var msg = "Testing"; |
| 60 | var element = $("#change-notification-msg"); |
| 61 | |
| 62 | libtoaster.showChangeNotification(msg); |
| 63 | |
| 64 | assert.equal(element.text(), msg); |
| 65 | assert.ok(element.is(":visible")); |
| 66 | |
| 67 | $("#change-notification").hide(); |
| 68 | }); |
| 69 | |
| 70 | var layer = { |
| 71 | "id": 91, |
| 72 | "name": "meta-crystalforest", |
| 73 | "layerdetailurl": "/toastergui/project/4/layer/91" |
| 74 | }; |
| 75 | |
| 76 | QUnit.test("Add layer", function(assert){ |
| 77 | var done = assert.async(); |
| 78 | |
| 79 | /* Wait for the modal to be added to the dom */ |
| 80 | var checkModal = setInterval(function(){ |
| 81 | if ($("#dependencies-modal").length > 0) { |
| 82 | $("#dependencies-modal .btn-primary").click(); |
| 83 | clearInterval(checkModal); |
| 84 | } |
| 85 | }, 200); |
| 86 | |
| 87 | libtoaster.addRmLayer(layer, true, function(deps){ |
| 88 | assert.equal(deps.length, 1); |
| 89 | done(); |
| 90 | }); |
| 91 | |
| 92 | }); |
| 93 | |
| 94 | QUnit.test("Rm layer", function(assert){ |
| 95 | var done = assert.async(); |
| 96 | |
| 97 | libtoaster.addRmLayer(layer, false, function(deps){ |
| 98 | assert.equal(deps.length, 0); |
| 99 | done(); |
| 100 | }); |
| 101 | |
| 102 | }); |
| 103 | |
| 104 | QUnit.test("Parse url params", function(assert){ |
| 105 | var params = libtoaster.parseUrlParams(); |
| 106 | assert.ok(params); |
| 107 | }); |
| 108 | |
| 109 | QUnit.test("Dump url params", function(assert){ |
| 110 | var params = libtoaster.dumpsUrlParams(); |
| 111 | assert.ok(params); |
| 112 | }); |
| 113 | |
| 114 | QUnit.test("Make typeaheads", function(assert){ |
| 115 | var layersT = $("#layers"); |
| 116 | var machinesT = $("#machines"); |
| 117 | var projectsT = $("#projects"); |
| 118 | var recipesT = $("#recipes"); |
| 119 | |
| 120 | libtoaster.makeTypeahead(layersT, |
| 121 | libtoaster.ctx.layersTypeAheadUrl, {}, function(){}); |
| 122 | |
| 123 | libtoaster.makeTypeahead(machinesT, |
| 124 | libtoaster.ctx.machinesTypeAheadUrl, {}, function(){}); |
| 125 | |
| 126 | libtoaster.makeTypeahead(projectsT, |
| 127 | libtoaster.ctx.projectsTypeAheadUrl, {}, function(){}); |
| 128 | |
| 129 | libtoaster.makeTypeahead(recipesT, |
| 130 | libtoaster.ctx.recipesTypeAheadUrl, {}, function(){}); |
| 131 | |
| 132 | assert.ok(recipesT.data('typeahead')); |
| 133 | assert.ok(layersT.data('typeahead')); |
| 134 | assert.ok(projectsT.data('typeahead')); |
| 135 | assert.ok(recipesT.data('typeahead')); |
| 136 | }); |
| 137 | |
| 138 | |
| 139 | |
| 140 | /* Page init functions */ |
| 141 | |
| 142 | QUnit.test("Import layer page init", function(assert){ |
| 143 | assert.throws(importLayerPageInit()); |
| 144 | }); |
| 145 | |
| 146 | QUnit.test("Project page init", function(assert){ |
| 147 | assert.throws(projectPageInit()); |
| 148 | }); |
| 149 | |
| 150 | QUnit.test("Layer details page init", function(assert){ |
| 151 | assert.throws(layerDetailsPageInit()); |
| 152 | }); |
| 153 | |
| 154 | QUnit.test("Layer btns init", function(assert){ |
| 155 | assert.throws(layerBtnsInit({ projectLayers : [] })); |
| 156 | }); |
| 157 | |
| 158 | QUnit.test("Table init", function(assert){ |
| 159 | assert.throws(tableInit({ url : tableUrl })); |
| 160 | }); |
| 161 | |
| 162 | $(document).ajaxError(function(event, jqxhr, settings, errMsg){ |
| 163 | if (errMsg === 'abort') |
| 164 | return; |
| 165 | |
| 166 | QUnit.test("Ajax error", function(assert){ |
| 167 | assert.notOk(jqxhr.responseText); |
| 168 | }); |
| 169 | }); |
| 170 | |
| 171 | |
| 172 | |
| 173 | |
| 174 | |
| 175 | |