UNPKG

@o3r/testing

Version:

The module provides testing (e2e, unit test) utilities to help you build your own E2E pipeline integrating visual testing.

66 lines 2.27 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.O3rCheckboxElement = void 0; const element_1 = require("../element"); /** * Implementation dedicated to Playwright. */ class O3rCheckboxElement extends element_1.O3rElement { constructor(sourceElement) { super(sourceElement); } async getInputElement() { try { const subInputElement = this.sourceElement.element.locator('input[type="checkbox"]'); if (await subInputElement.count()) { return subInputElement; } return this.sourceElement.element; } catch { return this.sourceElement.element; } } async getLabelElement() { try { const element = this.sourceElement.element.locator('label'); if (await element.count()) { return element; } } catch (err) { // eslint-disable-next-line no-console -- no other logger available console.warn('Failed to retrieve label of O3rCheckboxElement', err); return; } } /** * Check the checkbox element * @param value If specified, determine the value of the checkbox button * If the element contains a label, the label will be used to (un)check the checkbox. */ async check(value = true) { const labelElement = await this.getLabelElement(); if (labelElement) { const currentValue = await this.isChecked(); if (currentValue === value) { // eslint-disable-next-line no-console -- no other logger available console.warn(`Checkbox is already ${currentValue ? 'checked' : 'unchecked'}`); return Promise.resolve(); } return labelElement.click(); } return (await this.getInputElement()).setChecked(value); } /** @inheritDoc */ uncheck() { return this.check(false); } /** @inheritDoc */ async isChecked() { const inputElement = await this.getInputElement(); return inputElement.isChecked(); } } exports.O3rCheckboxElement = O3rCheckboxElement; //# sourceMappingURL=checkbox-element.js.map