UNPKG

playwright-fluent

Version:
80 lines (79 loc) 3.39 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 is_handle_visible_1 = require("../../is-handle-visible"); const utils_1 = require("../../../../utils"); describe('handle is read-only', () => { let browser = undefined; // eslint-disable-next-line @typescript-eslint/no-empty-function beforeEach(() => { }); afterEach(async () => { if (browser) { await browser.close(); } }); test('should return false when handle is undefined', async () => { // Given const handle = undefined; // When const result = await SUT.isHandleReadOnly(handle, is_handle_visible_1.defaultVerboseOptions); // Then expect(result).toBe(false); }); test('should return false when handle is null', async () => { // Given const handle = null; // When const result = await SUT.isHandleReadOnly(handle, is_handle_visible_1.defaultVerboseOptions); // Then expect(result).toBe(false); }); test('should return false when selector has no readOnly property', 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, 'is-handle-read-only.test.html')}`; await page.goto(url); await (0, utils_1.sleep)(1000); // When const handle = await page.$('p'); const result = await SUT.isHandleReadOnly(handle, is_handle_visible_1.defaultVerboseOptions); // Then expect(handle).toBeDefined(); expect(result).toBe(false); }); test('should return true when selector is read-only', 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, 'is-handle-read-only.test.html')}`; await page.goto(url); await (0, utils_1.sleep)(1000); // When const handle = await page.$('#readonlyInput'); const result = await SUT.isHandleReadOnly(handle, is_handle_visible_1.defaultVerboseOptions); // Then expect(handle).toBeDefined(); expect(result).toBe(true); }); test('should return false when selector is not readonly', 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, 'is-handle-read-only.test.html')}`; await page.goto(url); await (0, utils_1.sleep)(1000); // When const handle = await page.$('#enabledInput'); const result = await SUT.isHandleReadOnly(handle, is_handle_visible_1.defaultVerboseOptions); // Then expect(handle).toBeDefined(); expect(result).toBe(false); }); });