aboutsummaryrefslogtreecommitdiff
path: root/e2e/options_form.test.ts
blob: c3dc5fb50c532e03ba39485401af7d7d082bad52 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
import * as path from 'path';
import * as assert from 'assert';

import { Builder, Lanthan } from 'lanthan';
import OptionPage from './lib/OptionPage';

describe("options form page", () => {
  let lanthan: Lanthan;
  let browser: any;

  beforeEach(async() => {
    lanthan = await Builder
      .forBrowser('firefox')
      .spyAddon(path.join(__dirname, '..'))
      .build();
    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();
    }
  });

  it('switch to form settings', async () => {
    let page = await OptionPage.open(lanthan);
    await page.switchToForm();

    let { settings } = await browser.storage.local.get('settings');
    assert.strictEqual(settings.source, 'form')
  });

  it('add blacklist item', async () => {
    let page = await OptionPage.open(lanthan);
    let forms = await page.switchToForm();
    // Scroll is required to click a button on Firefox 60
    await page.scrollTo(0, 1000);

    // assert default
    let settings = (await browser.storage.local.get('settings')).settings;
    assert.deepStrictEqual(settings.form.blacklist, []);

    // add blacklist items
    await forms.addBlacklist();
    await forms.setBlacklist(0, 'google.com');

    settings = (await browser.storage.local.get('settings')).settings;
    assert.deepStrictEqual(settings.form.blacklist, ['google.com']);

    await forms.addBlacklist();
    await forms.setBlacklist(1, 'yahoo.com');

    settings = (await browser.storage.local.get('settings')).settings;
    assert.deepStrictEqual(settings.form.blacklist, ['google.com', 'yahoo.com']);

    // delete first item
    await forms.removeBlackList(0);
    settings = (await browser.storage.local.get('settings')).settings;
    assert.deepStrictEqual(settings.form.blacklist, ['yahoo.com'])
  });

  it('add a partial blacklist item', async () => {
    let page = await OptionPage.open(lanthan);
    let forms = await page.switchToForm();
    // Scroll is required to click a button on Firefox 60
    await page.scrollTo(0, 1000);

    // assert default
    let settings = (await browser.storage.local.get('settings')).settings;
    assert.deepStrictEqual(settings.form.blacklist, []);

    // add blacklist items
    await forms.addPartialBlacklist();
    await forms.setPartialBlacklist(0, 'google.com', 'j,k,<C-U>');

    settings = (await browser.storage.local.get('settings')).settings;
    assert.deepStrictEqual(settings.form.blacklist, [
      { url: 'google.com', keys: ['j', 'k', '<C-U>'] },
    ]);

    await forms.addPartialBlacklist();
    await forms.setPartialBlacklist(1, 'yahoo.com', 'g,G');

    settings = (await browser.storage.local.get('settings')).settings;
    assert.deepStrictEqual(settings.form.blacklist, [
      { url: 'google.com', keys: ['j', 'k', '<C-U>'] },
      { url: 'yahoo.com', keys: ['g', 'G'] },
    ]);

    await forms.addBlacklist();
    await forms.setBlacklist(0, 'bing.com');

    settings = (await browser.storage.local.get('settings')).settings;
    assert.deepStrictEqual(settings.form.blacklist, [
      { url: 'google.com', keys: ['j', 'k', '<C-U>'] },
      { url: 'yahoo.com', keys: ['g', 'G'] },
      'bing.com',
    ]);

    // delete first item
    await forms.removePartialBlackList(0);
    settings = (await browser.storage.local.get('settings')).settings;
    assert.deepStrictEqual(settings.form.blacklist, [
      { url: 'yahoo.com', keys: ['g', 'G'] },
      'bing.com',
    ])
  });

  it('add search engines', async () => {
    let page = await OptionPage.open(lanthan);
    let forms = await page.switchToForm();

    // assert default
    let settings = (await browser.storage.local.get('settings')).settings;
    assert.deepStrictEqual(settings.form.search.default, 'google');

    // change default
    await forms.setDefaultSearchEngine(2);
    settings = (await browser.storage.local.get('settings')).settings;
    assert.deepStrictEqual(settings.form.search.default, 'bing');

    await forms.addSearchEngine();
    await forms.setSearchEngine(6, 'yippy', 'https://www.yippy.com/search?query={}');

    settings = (await browser.storage.local.get('settings')).settings;
    assert.deepStrictEqual(settings.form.search.engines[6], ['yippy', 'https://www.yippy.com/search?query={}']);
  });
});