playwright-fluent
Version:
Fluent API around playwright
125 lines (124 loc) • 5.14 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('handle has value', () => {
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.hasHandleValue(handle, 'foobar');
// Then
expect(result).toBe(false);
});
test('should return false when handle is null', async () => {
// Given
const handle = null;
// When
const result = await SUT.hasHandleValue(handle, 'foobar');
// Then
expect(result).toBe(false);
});
test('should return false when handle is null and expected value is empty', async () => {
// Given
const handle = null;
// When
const result = await SUT.hasHandleValue(handle, '');
// Then
expect(result).toBe(false);
});
test('should return false when handle is undefined and expected value is empty', async () => {
// Given
const handle = undefined;
// When
const result = await SUT.hasHandleValue(handle, '');
// Then
expect(result).toBe(false);
});
test('should return true when selector has value', 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, 'has-handle-value.test.html')}`;
await page.goto(url);
const inputSelector = '#emptyInput';
await page.click(inputSelector);
await page.type(inputSelector, ' yo ');
const handle = await page.$(inputSelector);
// When
const result = await SUT.hasHandleValue(handle, 'yo');
// Then
expect(handle).toBeDefined();
expect(result).toBe(true);
});
test('should return false when selector has not the value', 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, 'has-handle-value.test.html')}`;
await page.goto(url);
const inputSelector = '#emptyInput';
await page.click(inputSelector);
await page.type(inputSelector, ' yo ');
const handle = await page.$(inputSelector);
// When
const result = await SUT.hasHandleValue(handle, 'foobar');
// Then
expect(handle).toBeDefined();
expect(result).toBe(false);
});
test('should return true when selector has undefined value and expected is empty', 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, 'has-handle-value.test.html')}`;
await page.goto(url);
const handle = await page.$('#withUndefinedValue');
// When
const result = await SUT.hasHandleValue(handle, '');
// Then
expect(handle).toBeDefined();
expect(result).toBe(true);
});
test('should return true when selector has empty value and expected is empty', 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, 'has-handle-value.test.html')}`;
await page.goto(url);
const handle = await page.$('#emptyInput');
// When
const result = await SUT.hasHandleValue(handle, '');
// Then
expect(handle).toBeDefined();
expect(result).toBe(true);
});
test('should return true when selector has null value and expected is empty', 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, 'has-handle-value.test.html')}`;
await page.goto(url);
const handle = await page.$('#withNullValue');
// When
const result = await SUT.hasHandleValue(handle, '');
// Then
expect(handle).toBeDefined();
expect(result).toBe(true);
});
});
;