diff options
author | Shin'ya Ueoka <ueokande@i-beam.org> | 2019-09-22 16:13:12 +0900 |
---|---|---|
committer | Shin'ya Ueoka <ueokande@i-beam.org> | 2019-09-22 16:13:12 +0900 |
commit | 7e77e31ad64c3649888eae337e0c984fd9c2ea2a (patch) | |
tree | 4d3e630f82712abce5afd7e498d514253464a6ea /e2e/options_form.test.ts | |
parent | 91f8383ecc2f7ef3f95173ad973a74f79e277a6c (diff) |
Migrate e2e tests to TypeScript
Diffstat (limited to 'e2e/options_form.test.ts')
-rw-r--r-- | e2e/options_form.test.ts | 124 |
1 files changed, 124 insertions, 0 deletions
diff --git a/e2e/options_form.test.ts b/e2e/options_form.test.ts new file mode 100644 index 0000000..04803da --- /dev/null +++ b/e2e/options_form.test.ts @@ -0,0 +1,124 @@ +import * as path from 'path'; +import * as assert from 'assert'; + +import { Builder, Lanthan } from 'lanthan'; +import { WebDriver, By } from 'selenium-webdriver'; + + +describe("options form page", () => { + let lanthan: Lanthan; + let webdriver: WebDriver; + let browser: any; + + beforeEach(async() => { + lanthan = await Builder + .forBrowser('firefox') + .spyAddon(path.join(__dirname, '..')) + .build(); + webdriver = lanthan.getWebDriver(); + browser = lanthan.getWebExtBrowser(); + + let tabs = await browser.tabs.query({}); + for (let tab of tabs.slice(1)) { + await browser.tabs.remove(tab.id); + } + }) + + afterEach(async() => { + if (lanthan) { + await lanthan.quit(); + } + }) + + const setBlacklistValue = async(nth: number, value: string) => { + let selector = '.form-blacklist-form .column-url'; + let input = (await webdriver.findElements(By.css(selector)))[nth]; + await input.sendKeys(value); + await webdriver.executeScript(`document.querySelectorAll('${selector}')[${nth}].blur()`); + } + + const setSearchEngineValue = async(nth: number, name: string, url: string) => { + let selector = '.form-search-form input.column-name'; + let input = (await webdriver.findElements(By.css(selector)))[nth]; + await input.sendKeys(name); + await webdriver.executeScript(`document.querySelectorAll('${selector}')[${nth}].blur()`); + + selector = '.form-search-form input.column-url'; + input = (await webdriver.findElements(By.css(selector)))[nth]; + await input.sendKeys(url); + await webdriver.executeScript(`document.querySelectorAll('${selector}')[${nth}].blur()`); + } + + it('switch to form settings', async () => { + let url = await browser.runtime.getURL("build/settings.html") + await webdriver.navigate().to(url); + + let useFormInput = await webdriver.findElement(By.css('#setting-source-form')); + await useFormInput.click(); + await webdriver.switchTo().alert().accept(); + + 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 webdriver.navigate().to(url); + + let useFormInput = await webdriver.findElement(By.css('#setting-source-form')); + await useFormInput.click(); + await webdriver.switchTo().alert().accept(); + await webdriver.executeScript(() => window.scrollBy(0, 1000)); + + // assert default + let settings = (await browser.storage.local.get('settings')).settings; + assert.deepEqual(settings.form.blacklist, []) + + // add blacklist items + let addButton = await webdriver.findElement(By.css('.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']) + + // delete first item + let deleteButton = (await webdriver.findElements(By.css('.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']) + }); + + it('add search engines', async () => { + let url = await browser.runtime.getURL("build/settings.html") + await webdriver.navigate().to(url); + + let useFormInput = await webdriver.findElement(By.css('#setting-source-form')); + await useFormInput.click(); + await webdriver.switchTo().alert().accept(); + + // assert default + let settings = (await browser.storage.local.get('settings')).settings; + assert.deepEqual(settings.form.search.default, 'google'); + + // change default + let radio = (await webdriver.findElements(By.css('.form-search-form input[type=radio]')))[2]; + await radio.click(); + settings = (await browser.storage.local.get('settings')).settings; + assert.deepEqual(settings.form.search.default, 'bing'); + + let addButton = await webdriver.findElement(By.css('.form-search-form .ui-add-button')) + await addButton.click(); + await setSearchEngineValue(6, 'yippy', 'https://www.yippy.com/search?query={}'); + + settings = (await browser.storage.local.get('settings')).settings; + assert.deepEqual(settings.form.search.engines[6], ['yippy', 'https://www.yippy.com/search?query={}']); + }); +}); |