From ac93834ddca15e0929737bc99a5284039f4238b8 Mon Sep 17 00:00:00 2001
From: Shin'ya Ueoka <ueokande@i-beam.org>
Date: Mon, 19 Aug 2019 22:24:50 +0900
Subject: Add option form page

---
 e2e/options_form.test.js | 83 ++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 83 insertions(+)
 create mode 100644 e2e/options_form.test.js

(limited to 'e2e')

diff --git a/e2e/options_form.test.js b/e2e/options_form.test.js
new file mode 100644
index 0000000..d665f1c
--- /dev/null
+++ b/e2e/options_form.test.js
@@ -0,0 +1,83 @@
+const lanthan = require('lanthan');
+const path = require('path');
+const assert = require('assert');
+
+describe("options form page", () => {
+  let firefox;
+  let session;
+  let browser;
+
+  beforeEach(async() => {
+    firefox = await lanthan.firefox({
+      spy: path.join(__dirname, '..'),
+      builderf: (builder) => {
+        builder.addFile('build/settings.js');
+        builder.addFile('build/settings.html');
+      },
+    });
+    await firefox.session.installAddonFromPath(path.join(__dirname, '..'));
+    session = firefox.session;
+    browser = firefox.browser;
+
+    let tabs = await browser.tabs.query({});
+    for (let tab of tabs.slice(1)) {
+      await browser.tabs.remove(tab.id);
+    }
+  })
+
+  afterEach(async() => {
+    if (firefox) {
+      await firefox.close();
+    }
+  })
+
+  const setBlacklistValue = async(nth, value) => {
+    let selector = '.form-blacklist-form .column-url';
+    let input = (await session.findElementsByCSS(selector))[nth];
+    await input.sendKeys(value);
+    await session.executeScript(`document.querySelectorAll('${selector}')[${nth}].blur()`);
+  }
+
+  it('switch to form settings', async () => {
+    let url = await browser.runtime.getURL("build/settings.html")
+    await session.navigateTo(url);
+
+    let useFormInput = await session.findElementByCSS('#setting-source-form');
+    await useFormInput.click();
+    await session.acceptAlert();
+
+    let { settings } = await browser.storage.local.get('settings');
+    assert.equal(settings.source, 'form')
+  })
+
+  it('add blacklist', async () => {
+    let url = await browser.runtime.getURL("build/settings.html")
+    await session.navigateTo(url);
+
+    let useFormInput = await session.findElementByCSS('#setting-source-form');
+    await useFormInput.click();
+    await session.acceptAlert();
+
+    let settings = (await browser.storage.local.get('settings')).settings;
+    assert.deepEqual(settings.form.blacklist, [])
+
+    let addButton = await session.findElementByCSS('.form-blacklist-form .ui-add-button');
+    await addButton.click();
+    await setBlacklistValue(0, 'google.com')
+
+    settings = (await browser.storage.local.get('settings')).settings;
+    assert.deepEqual(settings.form.blacklist, ['google.com'])
+
+    await addButton.click();
+    await setBlacklistValue(1, 'yahoo.com')
+
+    settings = (await browser.storage.local.get('settings')).settings;
+    assert.deepEqual(settings.form.blacklist, ['google.com', 'yahoo.com'])
+
+    let deleteButton = (await session.findElementsByCSS('.form-blacklist-form .ui-delete-button'))[0];
+    await deleteButton.click()
+
+    settings = (await browser.storage.local.get('settings')).settings;
+    assert.deepEqual(settings.form.blacklist, ['yahoo.com'])
+  });
+});
-- 
cgit v1.2.3