UNPKG

product-admin

Version:

EA admin screens

149 lines (126 loc) 4.31 kB
<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <script src="../../bower_components/webcomponentsjs/webcomponents-lite.js"></script> <script src="../../bower_components/web-component-tester/browser.js"></script> <link rel="import" href="../../element.html" /> <link rel="import" href="./product-table-check.html"> </head> <body> <test-fixture id="product-table-check-fixture"> <template> <product-table-check product="{}" ></product-table-check> </template> </test-fixture> <script> suite('<product-table-check>', function () { setup(function (done) { window.myEl = fixture("product-table-check-fixture"); Polymer.dom.flush(); flush(done); }); teardown(function (done) { flush(done); }); test('product-table-check exists', function() { expect(myEl).to.exist; }); test('check should be checked when its active', function(done) { var listItems; var productTableCheck = fixture("product-table-check-fixture"); productTableCheck.product = { "pk": "fakePk-9ade-4cd8-9b4f-14d5bdebb6e8", "productDescription": "fake desc", "productCode": "Fake code", "currentSpecificationRate": 120.0, "assets": [], "specifications": [{}], "tenantZoneId": "1b3e5fc2-a2d9-49a3-a877-6e9e6e5b7764", "active": "true", "longDescription": null, "currentSpecificationCycleTime": null, "cycleTimeSpecifications": [] }; flush(function() { var paperCheck = Polymer.dom(productTableCheck.root).querySelectorAll('paper-checkbox'); assert.equal(paperCheck[0].checked, true); done(); }); }); test('check should not be checked when its not active', function(done) { var listItems; var productTableCheck = fixture("product-table-check-fixture"); productTableCheck.product = { "pk": "fakePk-9ade-4cd8-9b4f-14d5bdebb6e8", "productDescription": "fake desc", "productCode": "Fake code", "currentSpecificationRate": 120.0, "assets": [], "specifications": [{}], "tenantZoneId": "1b3e5fc2-a2d9-49a3-a877-6e9e6e5b7764", "active": "false", "longDescription": null, "currentSpecificationCycleTime": null, "cycleTimeSpecifications": [] }; flush(function() { var paperCheck = Polymer.dom(productTableCheck.root).querySelectorAll('paper-checkbox'); assert.equal(paperCheck[0].checked, false); done(); }); }); }); suite('making iron-ajax', function() { setup(function() { stub('iron-ajax', { generateRequest: function() { console.log('paper-button.click called'); } }); window.myEl = fixture("product-table-check-fixture"); }); test('when click, it should fire ajax', function(done) { var productTableCheck = fixture("product-table-check-fixture"); productTableCheck.product = { "pk": "fakePk-9ade-4cd8-9b4f-14d5bdebb6e8", "productDescription": "fake desc", "productCode": "Fake code", "currentSpecificationRate": 120.0, "assets": [], "specifications": [{}], "tenantZoneId": "1b3e5fc2-a2d9-49a3-a877-6e9e6e5b7764", "active": "false", "longDescription": null, "currentSpecificationCycleTime": null, "cycleTimeSpecifications": [] }; var checkbox = Polymer.dom(productTableCheck.root).querySelectorAll('paper-checkbox')[0]; var ironAjax = Polymer.dom(productTableCheck.root).querySelectorAll('iron-ajax')[0] checkbox.click(); flush(function() { assert.equal(ironAjax.url, "/updateProduct/fakePk-9ade-4cd8-9b4f-14d5bdebb6e8"); assert.equal(ironAjax.body.active, "true"); done(); }); }); test('when click on checked box, it should fire ajax with not active', function(done) { var productTableCheck = fixture("product-table-check-fixture"); productTableCheck.product = { "pk": "fakePk-9ade-4cd8-9b4f-1234567890", "active": "true" }; var checkbox = Polymer.dom(productTableCheck.root).querySelectorAll('paper-checkbox')[0]; var ironAjax = Polymer.dom(productTableCheck.root).querySelectorAll('iron-ajax')[0] checkbox.click(); flush(function() { assert.equal(ironAjax.url, "/updateProduct/fakePk-9ade-4cd8-9b4f-1234567890"); assert.equal(ironAjax.body.active, "false"); done(); }); }); }); </script> </body> </html>