UNPKG

playwright-fluent

Version:
115 lines (114 loc) 5.56 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 has_handle_focus_1 = require("../../has-handle-focus"); const dom_actions_1 = require("../../../dom-actions"); const is_handle_checked_1 = require("../../is-handle-checked"); const check_handle_1 = require("../../check-handle"); describe('uncheck 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, 'uncheck-handle.test.html')}`; await page.goto(url); // When // Then const expectedError = new Error("Cannot uncheck 'foobar' because selector was not found in DOM"); await SUT.uncheckHandle(undefined, 'foobar', page, check_handle_1.defaultCheckOptions).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, 'uncheck-handle.test.html')}`; await page.goto(url); // When // Then const expectedError = new Error("Cannot uncheck 'foobar' because selector was not found in DOM"); await SUT.uncheckHandle(null, 'foobar', page, check_handle_1.defaultCheckOptions).catch((error) => expect(error).toMatchObject(expectedError)); }); test('should throw when selector is disabled and checked - 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, 'uncheck-handle.test.html')}`; await page.goto(url); const checkOptions = { ...check_handle_1.defaultCheckOptions, timeoutInMilliseconds: 1000, verbose: false, }; // When const selector = '#checked-and-disabled'; const handle = await page.$(selector); let result = undefined; try { await SUT.uncheckHandle(handle, selector, page, checkOptions); } catch (error) { result = error; } // Then expect(handle).toBeDefined(); expect(await (0, is_handle_checked_1.isHandleChecked)(handle, { verbose: checkOptions.verbose })).toBe(true); expect(result && result.message).toContain("Cannot uncheck '#checked-and-disabled' because this selector is disabled"); }); test('should do nothing when selector is already unchecked - 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, 'uncheck-handle.test.html')}`; await page.goto(url); const checkOptions = { ...check_handle_1.defaultCheckOptions, verbose: false, }; // When const selector = '#already-unchecked'; const handle = await page.$(selector); await SUT.uncheckHandle(handle, selector, page, checkOptions); // Then expect(handle).toBeDefined(); expect(await (0, is_handle_checked_1.isHandleChecked)(handle, { verbose: checkOptions.verbose })).toBe(false); }); 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, 'uncheck-handle.test.html')}`; await page.goto(url); const checkOptions = { ...check_handle_1.defaultCheckOptions, verbose: false, }; // When const selector = '#disabled-then-enabled'; const handle = await page.$('#disabled-then-enabled'); expect(await (0, is_handle_checked_1.isHandleChecked)(handle, { verbose: checkOptions.verbose })).toBe(true); await SUT.uncheckHandle(handle, selector, page, checkOptions); // Then expect(handle).toBeDefined(); expect(await (0, has_handle_focus_1.hasHandleFocus)(handle)).toBe(true); expect(await (0, is_handle_checked_1.isHandleChecked)(handle, { verbose: checkOptions.verbose })).toBe(false); }); });