playwright-fluent
Version:
Fluent API around playwright
64 lines (63 loc) • 2.86 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"));
const dom_actions_1 = require("../../../dom-actions");
describe('get intersection ratio of handle', () => {
let browser = undefined;
// eslint-disable-next-line @typescript-eslint/no-empty-function
beforeEach(() => { });
afterEach(async () => {
if (browser) {
await browser.close();
}
});
test('should return 0 when selector is out of viewport - 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, 'get-intersection-ratio-of-handle.test.html')}`;
await page.goto(url);
const selector = '#out-of-view-port';
const handle = await page.$(selector);
// When
const result = await SUT.getIntersectionRatioOfHandle(handle);
// Then
expect(result).toBe(0);
});
test('should return 1 when selector is inside of viewport - 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, 'get-intersection-ratio-of-handle.test.html')}`;
await page.goto(url);
const selector = '#in-view-port';
const handle = await page.$(selector);
// When
const result = await SUT.getIntersectionRatioOfHandle(handle);
// Then
expect(result).toBe(1);
});
test('should return a ratio when selector is intersecting viewport - 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, 'get-intersection-ratio-of-handle.test.html')}`;
await page.goto(url);
const selector = 'playwright-mouse-pointer';
const handle = await page.$(selector);
// When
const result = await SUT.getIntersectionRatioOfHandle(handle);
// Then
expect(result).toBeGreaterThan(0.1);
expect(result).toBeLessThan(0.5);
});
});
;