aboutsummaryrefslogtreecommitdiff
path: root/test/playwright/integration.spec.js
diff options
context:
space:
mode:
authorMarvNC <rotrobmin@gmail.com>2023-11-03 11:59:21 -0700
committerMarvNC <rotrobmin@gmail.com>2023-11-03 11:59:21 -0700
commitec62375c017f124570cf922647c530829714eee2 (patch)
treeaccb3968e083f6e59a243b840d7859d61b3fae9e /test/playwright/integration.spec.js
parent5e10b67c500b7af9d5af6d98caae9734ebdf984d (diff)
parentb64f51c3b13a46af4dd7f1e43048ac19c781ca7b (diff)
Merge remote-tracking branch 'upstream/master' into update-dictionaries
Diffstat (limited to 'test/playwright/integration.spec.js')
-rw-r--r--test/playwright/integration.spec.js94
1 files changed, 94 insertions, 0 deletions
diff --git a/test/playwright/integration.spec.js b/test/playwright/integration.spec.js
new file mode 100644
index 00000000..1bfd39ea
--- /dev/null
+++ b/test/playwright/integration.spec.js
@@ -0,0 +1,94 @@
+/*
+ * Copyright (C) 2023 Yomitan Authors
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <https://www.gnu.org/licenses/>.
+ */
+
+const path = require('path');
+const {
+ test,
+ expect,
+ root,
+ mockModelFieldNames,
+ mockModelFieldsToAnkiValues,
+ expectedAddNoteBody,
+ mockAnkiRouteHandler,
+ writeToClipboardFromPage
+} = require('./playwright-util');
+const {createDictionaryArchive} = require('../../dev/util');
+
+test.beforeEach(async ({context}) => {
+ // wait for the on-install welcome.html tab to load, which becomes the foreground tab
+ const welcome = await context.waitForEvent('page');
+ await welcome.close(); // close the welcome tab so our main tab becomes the foreground tab -- otherwise, the screenshot can hang
+});
+
+test('search clipboard', async ({page, extensionId}) => {
+ await page.goto(`chrome-extension://${extensionId}/search.html`);
+ await page.locator('#search-option-clipboard-monitor-container > label').click();
+ await page.waitForTimeout(200); // race
+
+ await writeToClipboardFromPage(page, 'あ');
+ await expect(page.locator('#search-textbox')).toHaveValue('あ');
+});
+
+test('anki add', async ({context, page, extensionId}) => {
+ // mock anki routes
+ let resolve;
+ const addNotePromise = new Promise((res) => {
+ resolve = res;
+ });
+ await context.route(/127.0.0.1:8765\/*/, (route) => {
+ mockAnkiRouteHandler(route);
+ const req = route.request();
+ if (req.url().includes('127.0.0.1:8765') && req.postDataJSON().action === 'addNote') {
+ resolve(req.postDataJSON());
+ }
+ });
+
+ // open settings
+ await page.goto(`chrome-extension://${extensionId}/settings.html`);
+
+ // load in test dictionary
+ const dictionary = createDictionaryArchive(path.join(root, 'test/data/dictionaries/valid-dictionary1'), 'valid-dictionary1');
+ const testDictionarySource = await dictionary.generateAsync({type: 'arraybuffer'});
+ await page.locator('input[id="dictionary-import-file-input"]').setInputFiles({name: 'valid-dictionary1.zip', buffer: Buffer.from(testDictionarySource)});
+ await expect(page.locator('id=dictionaries')).toHaveText('Dictionaries (1 installed, 1 enabled)', {timeout: 5 * 60 * 1000});
+
+ // connect to anki
+ await page.locator('.toggle', {has: page.locator('[data-setting="anki.enable"]')}).click();
+ await expect(page.locator('#anki-error-message')).toHaveText('Connected');
+
+ // prep anki deck
+ await page.locator('[data-modal-action="show,anki-cards"]').click();
+ await page.locator('select.anki-card-deck').selectOption('Mock Deck');
+ await page.locator('select.anki-card-model').selectOption('Mock Model');
+ for (const modelField of mockModelFieldNames) {
+ await page.locator(`[data-setting="anki.terms.fields.${modelField}"]`).fill(mockModelFieldsToAnkiValues[modelField]);
+ }
+ await page.locator('#anki-cards-modal > div > div.modal-footer > button:nth-child(2)').click();
+ await writeToClipboardFromPage(page, '読むの例文');
+
+ // add to anki deck
+ await page.goto(`chrome-extension://${extensionId}/search.html`);
+ await expect(async () => {
+ await page.locator('#search-textbox').clear();
+ await page.locator('#search-textbox').fill('読む');
+ await expect(page.locator('#search-textbox')).toHaveValue('読む');
+ }).toPass({timeout: 5000});
+ await page.locator('#search-textbox').press('Enter');
+ await page.locator('[data-mode="term-kanji"]').click();
+ const addNoteReqBody = await addNotePromise;
+ expect(addNoteReqBody).toMatchObject(expectedAddNoteBody);
+}); \ No newline at end of file