From 77a34bd4b952700a13cbc6ced98e29ce93930e1e Mon Sep 17 00:00:00 2001 From: Peter Snyder Date: Sat, 28 Oct 2017 15:29:44 -0500 Subject: [PATCH] add import / export functionality, along with tests, fixes #8 --- add-on/config/css/config.css | 8 ++ .../config/js/components/import-export.vue.js | 134 ++++++++++-------- package-lock.json | 18 +++ package.json | 5 +- test/functional/import-export.js | 96 +++++++++++++ test/functional/lib/utils.js | 2 +- 6 files changed, 198 insertions(+), 65 deletions(-) create mode 100644 test/functional/import-export.js diff --git a/add-on/config/css/config.css b/add-on/config/css/config.css index cce8d0b..3adf697 100644 --- a/add-on/config/css/config.css +++ b/add-on/config/css/config.css @@ -12,4 +12,12 @@ body { section p:first-child { padding-top: 1em; +} + +section.container { + margin-top: 2em; +} + +section { + margin-bottom: 5em; } \ No newline at end of file diff --git a/add-on/config/js/components/import-export.vue.js b/add-on/config/js/components/import-export.vue.js index bbbb7cf..90070a9 100644 --- a/add-on/config/js/components/import-export.vue.js +++ b/add-on/config/js/components/import-export.vue.js @@ -6,9 +6,11 @@ const generateExportString = function (domainsToExport, allDomainData) { const dataToExport = domainsToExport.map(function (domain) { + const domainsToBlock = allDomainData[domain]; + domainsToBlock.sort(); return { "pattern": domain, - "standards": allDomainData[domain] + "standards": domainsToBlock }; }); @@ -18,73 +20,81 @@ Vue.component("import-export", { props: ["domainNames", "selectedStandards"], template: ` -

Export Settings

-
- - - - Select one or more domain rules to export. - -
- -
- - -
- -

Import Settings

- -
- - -
- -
-
-
-
- -
+
+ + +
+ -
Import log: - -
+
+

Import Settings

+ +
+ + +
+ +
+
+ + + If this option is selected, than existing options will be + overwritten. If it is unchecked, then the blocked standards + for existing domains will not be affected. + +
+
+ +
+ +
+ +
+ + +
+ driver.wait(until.elementLocated(by.css("a[href='#import-export']"))), 500) + .then(element => element.click()); +}; + +describe("Import / Export", function () { + + this.timeout = () => 5000; + + describe("Exporting", function () { + + it("Exporting empty blocking rule", function (done) { + + let driverReference; + + utils.promiseGetDriver() + .then(function (driver) { + driverReference = driver; + return promiseOpenImportExportTab(driverReference); + }) + .then(() => driverReference.findElement(by.css(".export-section select option:nth-child(1)")).click()) + .then(() => driverReference.findElement(by.css(".export-section textarea")).getAttribute("value")) + .then(function (exportValue) { + assert.equal(exportValue.trim(), emptyRuleSet, "Exported ruleset does not match expected value."); + done(); + }) + .catch(done); + }); + + it("Exporting SVG and Beacon blocking rules", function (done) { + + let driverReference; + + utils.promiseGetDriver() + .then(function (driver) { + driverReference = driver; + return utils.promiseSetBlockingRules(driverReference, utils.constants.svgBlockRule.concat(["Beacon"])); + }) + .then(() => promiseOpenImportExportTab(driverReference)) + .then(() => driverReference.findElement(by.css(".export-section select option:nth-child(1)")).click()) + .then(() => driverReference.findElement(by.css(".export-section textarea")).getAttribute("value")) + .then(function (exportValue) { + assert.equal(exportValue.trim(), blockingSVGandBeacon, "Exported ruleset does not match expected value."); + done(); + }) + .catch(done); + }); + }); + + describe("Importing", function () { + + it("Importing SVG and Beacon blocking rules", function (done) { + + let driverReference; + let checkedCheckboxes; + + utils.promiseGetDriver() + .then(function (driver) { + driverReference = driver; + return promiseOpenImportExportTab(driverReference); + }) + .then(() => driverReference.findElement(by.css(".import-section textarea")).sendKeys(blockingSVGandBeacon)) + .then(() => driverReference.findElement(by.css(".import-section input[type='checkbox']")).click()) + .then(() => driverReference.findElement(by.css(".import-section button")).click()) + .then(() => utils.pause(500)) + .then(() => driverReference.findElements(by.css("#domain-rules input[type='checkbox']:checked"))) + .then(function (checkboxElms) { + checkedCheckboxes = checkboxElms; + assert.equal(checkboxElms.length, 2, "There should be two standards blocked."); + return checkedCheckboxes[0].getAttribute("value"); + }) + .then(function (firstCheckboxValue) { + assert.equal(firstCheckboxValue, "Beacon", "The first blocked standard should be 'Beacon'."); + return checkedCheckboxes[1].getAttribute("value"); + }) + .then(function (secondCheckboxValue) { + assert.equal(secondCheckboxValue, utils.constants.svgBlockRule[0], "The second blocked standard should be the SVG standard."); + done(); + }) + .catch(done); + }); + }); +}); diff --git a/test/functional/lib/utils.js b/test/functional/lib/utils.js index f112100..972a0e1 100644 --- a/test/functional/lib/utils.js +++ b/test/functional/lib/utils.js @@ -75,7 +75,7 @@ module.exports.promiseSetBlockingRules = function (driver, standardsToBlock) { return this.promiseExtensionConfigPage(driver) .then(driver.executeAsyncScript(setStandardsScript)) - .then(() => module.exports.pause(1000)); + .then(() => module.exports.pause(500)); }; module.exports.promiseGetDriver = function () {