UNPKG

playwright-fluent

Version:
90 lines (89 loc) 4.64 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); const tslib_1 = require("tslib"); const path = tslib_1.__importStar(require("path")); const playwright_1 = require("playwright"); const SUT = tslib_1.__importStar(require("../index")); const double_click_on_handle_1 = require("../double-click-on-handle"); const has_handle_focus_1 = require("../../has-handle-focus"); const dom_actions_1 = require("../../../dom-actions"); describe('double-click on handle', () => { let browser = undefined; // eslint-disable-next-line @typescript-eslint/no-empty-function beforeEach(() => { }); afterEach(async () => { if (browser) { await browser.close(); } }); test('should throw when selector is undefined - chromium', async () => { // Given browser = await playwright_1.chromium.launch({ headless: true }); const browserContext = await browser.newContext({ viewport: null }); const page = await browserContext.newPage(); const url = `file:${path.join(__dirname, 'double-click-on-handle.test.html')}`; await page.goto(url); // When // Then const expectedError = new Error("Cannot double-click on 'foobar' because selector was not found in DOM"); await SUT.doubleClickOnHandle(undefined, 'foobar', page, double_click_on_handle_1.defaultDoubleClickOptions).catch((error) => expect(error).toMatchObject(expectedError)); }); test('should throw when selector is null - chromium', async () => { // Given browser = await playwright_1.chromium.launch({ headless: true }); const browserContext = await browser.newContext({ viewport: null }); const page = await browserContext.newPage(); const url = `file:${path.join(__dirname, 'double-click-on-handle.test.html')}`; await page.goto(url); // When // Then const expectedError = new Error("Cannot double-click on 'foobar' because selector was not found in DOM"); await SUT.doubleClickOnHandle(null, 'foobar', page, double_click_on_handle_1.defaultDoubleClickOptions).catch((error) => expect(error).toMatchObject(expectedError)); }); test('should wait for the selector to be enabled - chromium', async () => { // Given browser = await playwright_1.chromium.launch({ headless: true }); const browserContext = await browser.newContext({ viewport: null }); const page = await browserContext.newPage(); await (0, dom_actions_1.showMousePosition)(page); const url = `file:${path.join(__dirname, 'double-click-on-handle.test.html')}`; await page.goto(url); // When const selector = '#disabled-then-enabled'; const handle = await page.$('#disabled-then-enabled'); // eslint-disable-next-line @typescript-eslint/no-non-null-assertion await handle.click(); await page.keyboard.press('ArrowLeft'); await page.keyboard.press('ArrowLeft'); await page.keyboard.press('ArrowLeft'); await page.keyboard.press('ArrowLeft'); await SUT.doubleClickOnHandle(handle, selector, page, double_click_on_handle_1.defaultDoubleClickOptions); // Then expect(handle).toBeDefined(); expect(await (0, has_handle_focus_1.hasHandleFocus)(handle)).toBe(true); const selectedText = await page.evaluate(() => (document.getSelection() || '').toString()); expect(selectedText).toBe('disabled'); }); test.skip('should wait for the selector to be enabled (verbose) - chromium', async () => { // Given browser = await playwright_1.chromium.launch({ headless: true }); const browserContext = await browser.newContext({ viewport: null }); const page = await browserContext.newPage(); await (0, dom_actions_1.showMousePosition)(page); const url = `file:${path.join(__dirname, 'double-click-on-handle.test.html')}`; await page.goto(url); // When const selector = '#disabled-then-enabled'; const handle = await page.$('#disabled-then-enabled'); const options = { ...double_click_on_handle_1.defaultDoubleClickOptions, verbose: true, }; await SUT.doubleClickOnHandle(handle, selector, page, options); // Then expect(handle).toBeDefined(); expect(await (0, has_handle_focus_1.hasHandleFocus)(handle)).toBe(true); const selectedText = await page.evaluate(() => (document.getSelection() || '').toString()); expect(selectedText).toBe('disabled'); }); });