UNPKG

playwright-fluent

Version:
103 lines (102 loc) 4.75 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 unchecked', () => { 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 selector has no checked 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-unchecked.test.html')}`; await page.goto(url); await (0, utils_1.sleep)(1000); // When const handle = await page.$('p'); const result = await SUT.isHandleUnchecked(handle, is_handle_visible_1.defaultVerboseOptions); // Then expect(handle).toBeDefined(); expect(result).toBe(false); }); test('should return true when checkbox is unchecked', 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-unchecked.test.html')}`; await page.goto(url); await (0, utils_1.sleep)(1000); // When const label = await page.$('label[for="switch1"]'); // eslint-disable-next-line @typescript-eslint/no-non-null-assertion await label.click(); const handle = await page.$('#switch1'); const result = await SUT.isHandleUnchecked(handle, is_handle_visible_1.defaultVerboseOptions); // Then expect(handle).toBeDefined(); expect(result).toBe(true); }); test('should return false when checkbox is checked', 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-unchecked.test.html')}`; await page.goto(url); await (0, utils_1.sleep)(1000); // When const handle = await page.$('#switch1'); const result = await SUT.isHandleUnchecked(handle, is_handle_visible_1.defaultVerboseOptions); // Then expect(handle).toBeDefined(); expect(result).toBe(false); }); test('should return true when radio button is unchecked', 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-unchecked.test.html')}`; await page.goto(url); await (0, utils_1.sleep)(1000); // When const label = await page.$('label[for="unchecked-radio"]'); // eslint-disable-next-line @typescript-eslint/no-non-null-assertion await label.click(); const handle = await page.$('#checked-radio'); const result = await SUT.isHandleUnchecked(handle, is_handle_visible_1.defaultVerboseOptions); // Then expect(handle).toBeDefined(); expect(result).toBe(true); }); test('should return false when radio button is checked', 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-unchecked.test.html')}`; await page.goto(url); await (0, utils_1.sleep)(1000); // When const label = await page.$('label[for="unchecked-radio"]'); // eslint-disable-next-line @typescript-eslint/no-non-null-assertion await label.click(); const handle = await page.$('#unchecked-radio'); const result = await SUT.isHandleUnchecked(handle, is_handle_visible_1.defaultVerboseOptions); // Then expect(handle).toBeDefined(); expect(result).toBe(false); }); });