diff options
| author | Shin'ya Ueoka <ueokande@i-beam.org> | 2019-08-06 22:04:31 +0900 | 
|---|---|---|
| committer | Shin'ya Ueoka <ueokande@i-beam.org> | 2019-08-20 21:48:05 +0900 | 
| commit | 1bc96ed1118c38b4b18035f8e05f2709b53b746b (patch) | |
| tree | 5bb883f790bb6b8b2f52a76952a4cddf9326135c | |
| parent | 34bd084a4d0d3823764e3fb78378795aba9534d3 (diff) | |
My first e2e test for option page
| -rw-r--r-- | e2e/options.test.js | 66 | 
1 files changed, 66 insertions, 0 deletions
diff --git a/e2e/options.test.js b/e2e/options.test.js new file mode 100644 index 0000000..d386b20 --- /dev/null +++ b/e2e/options.test.js @@ -0,0 +1,66 @@ +const express = require('express'); +const lanthan = require('lanthan'); +const path = require('path'); +const assert = require('assert'); +const eventually = require('./eventually'); + +describe("options page", () => { +  let firefox; +  let session; +  let browser; + +  before(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; +  }); + +  after(async() => { +    if (firefox) { +      await firefox.close(); +    } +  }); + +  beforeEach(async() => { +    let tabs = await browser.tabs.query({}); +    for (let tab of tabs.slice(1)) { +      await browser.tabs.remove(tab.id); +    } +  }) + +  it('saves current config on blur', async () => { +    let url = await browser.runtime.getURL("build/settings.html") +    await session.navigateTo(url); + +    let textarea = await session.findElementByCSS('textarea'); +    const updateTextarea = async(value) => { +      await session.executeScript(`document.querySelector('textarea').value = '${value}'`) +      await textarea.sendKeys(' '); +      await session.executeScript(() => document.querySelector('textarea').blur()); +    } + +    await updateTextarea(`{ "blacklist": [ "https://example.com" ] }`); + +    let { settings } = await browser.storage.local.get('settings'); +    assert.equal(settings.source, 'json') +    assert.equal(settings.json, '{ "blacklist": [ "https://example.com" ] } ') + +    await updateTextarea(`invalid json`); + +    settings = (await browser.storage.local.get('settings')).settings; +    assert.equal(settings.source, 'json') +    assert.equal(settings.json, '{ "blacklist": [ "https://example.com" ] } ') + +    let error = await session.findElementByCSS('.settings-ui-input-error'); +    let text = await error.getText(); +    assert.ok(text.startsWith('SyntaxError:')) +  }); +}); +  | 
