playwright-fluent
Version: 
Fluent API around playwright
103 lines (102 loc) • 4.95 kB
JavaScript
;
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"));
describe('is option by value available in 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 not a select - 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, 'is-option-by-value-available-in-handle.test.html')}`;
        await page.goto(url);
        const selector = '#empty-input';
        const handle = await page.$(selector);
        // When
        // Then
        const expectedError = new Error("Cannot find any options in selector '#empty-input'");
        await SUT.isOptionByValueAvailableInHandle(handle, selector, 'foo').catch((error) => expect(error).toMatchObject(expectedError));
    });
    test('should detect option is available - 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, 'is-option-by-value-available-in-handle.test.html')}`;
        await page.goto(url);
        // When
        const selector = '#disabled-select';
        const handle = await page.$(selector);
        const result = await SUT.isOptionByValueAvailableInHandle(handle, selector, 'value 1');
        // Then
        expect(result).toBe(true);
    });
    test('should detect option is not available - 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, 'is-option-by-value-available-in-handle.test.html')}`;
        await page.goto(url);
        // When
        const selector = '#disabled-select';
        const handle = await page.$(selector);
        const result = await SUT.isOptionByValueAvailableInHandle(handle, selector, 'foobar');
        // Then
        expect(result).toBe(false);
    });
    test('should be case sensitive - 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, 'is-option-by-value-available-in-handle.test.html')}`;
        await page.goto(url);
        // When
        const selector = '#disabled-select';
        const handle = await page.$(selector);
        const resultLowercase = await SUT.isOptionByValueAvailableInHandle(handle, selector, 'value 1');
        const resultUperCase = await SUT.isOptionByValueAvailableInHandle(handle, selector, 'Value 1');
        // Then
        expect(resultLowercase).toBe(true);
        expect(resultUperCase).toBe(false);
    });
    test('should detect empty option - 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, 'is-option-by-value-available-in-handle.test.html')}`;
        await page.goto(url);
        // When
        const selector = '#enabled-select';
        const handle = await page.$(selector);
        const result = await SUT.isOptionByValueAvailableInHandle(handle, selector, '');
        // Then
        expect(result).toBe(true);
    });
    test('should not detect empty option in an empty select - 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, 'is-option-by-value-available-in-handle.test.html')}`;
        await page.goto(url);
        // When
        const selector = '#no-options-select';
        const handle = await page.$(selector);
        const result = await SUT.isOptionByValueAvailableInHandle(handle, selector, '');
        // Then
        expect(result).toBe(false);
    });
});