diff --git a/.github/workflows/node.js.yml b/.github/workflows/node.js.yml index 0e5e9b4..d541545 100644 --- a/.github/workflows/node.js.yml +++ b/.github/workflows/node.js.yml @@ -16,7 +16,7 @@ jobs: strategy: matrix: os: [ubuntu-latest] - node-version: [16.x] + node-version: [16.13] steps: - uses: actions/checkout@v2 @@ -54,7 +54,7 @@ jobs: strategy: matrix: os: [ubuntu-latest] - node-version: [16.x] + node-version: [16.13] # See supported Node.js release schedule at https://nodejs.org/en/about/releases/ steps: diff --git a/src/components/button.ts b/src/components/button.ts index 6256857..7803114 100644 --- a/src/components/button.ts +++ b/src/components/button.ts @@ -3,17 +3,19 @@ import { CypressIonicComponentClass, SupportedSelectors } from '@interfaces'; import { IonButton } from '@ionic/core/components/ion-button'; class IonButtonCypress - implements CypressIonicComponentClass + implements CypressIonicComponentClass { public click(selector: SupportedSelectors) { - return getFromSupportedSelector(selector).then(($ionButton) => { - return cy - .wrap($ionButton) - .shadow() - .find('button') - .click() - .then(() => $ionButton); - }); + return getFromSupportedSelector(selector).then( + ($ionButton) => { + return cy + .wrap($ionButton) + .shadow() + .find('button') + .click({ force: true }) + .then(() => $ionButton); + } + ); } // @ts-expect-error This is a special case diff --git a/src/components/input.ts b/src/components/input.ts index 1b1e978..2f94f13 100644 --- a/src/components/input.ts +++ b/src/components/input.ts @@ -1,28 +1,31 @@ import { CypressIonicComponentClass, SupportedSelectors } from '@interfaces'; -import { IonInput } from '@ionic/core/components/ion-input'; import { getFromSupportedSelector } from '@helpers'; class IonInputCypress - implements CypressIonicComponentClass + implements CypressIonicComponentClass { public write(selector: SupportedSelectors, text: string) { - return getFromSupportedSelector(selector).then(($ionInput) => { - return cy - .wrap($ionInput) - .find('input') - .type(text) - .then(() => $ionInput); - }); + return getFromSupportedSelector(selector).then( + ($ionInput) => { + return cy + .wrap($ionInput) + .find('input') + .type(text) + .then(() => $ionInput); + } + ); } public clear(selector: SupportedSelectors) { - return getFromSupportedSelector(selector).then(($ionInput) => { - return cy - .wrap($ionInput) - .find('input') - .clear() - .then(() => $ionInput); - }); + return getFromSupportedSelector(selector).then( + ($ionInput) => { + return cy + .wrap($ionInput) + .find('input') + .clear() + .then(() => $ionInput); + } + ); } } diff --git a/src/components/range.ts b/src/components/range.ts index feaae84..85c61cd 100644 --- a/src/components/range.ts +++ b/src/components/range.ts @@ -11,7 +11,7 @@ import { } from '@interfaces'; import { getFromSupportedSelector } from '@helpers'; -type GenericIonRange = IonRange & { +type GenericIonRange = HTMLIonRangeElement & { value: T; }; @@ -32,7 +32,7 @@ export interface IonRangeCypressMoveToValueOptions { } class IonRangeCypress - implements CypressIonicComponentClass + implements CypressIonicComponentClass { /** * Sets the value or the {@link IonRange} programmatically and triggers @@ -42,8 +42,8 @@ class IonRangeCypress public setValue( ionCssSelector: SupportedSelectors, value: RangeValue - ): CypressIonicReturn { - return getFromSupportedSelector(ionCssSelector).then( + ): CypressIonicReturn { + return getFromSupportedSelector(ionCssSelector).then( ($ionRange) => { const ionRange = $ionRange[0]; @@ -74,9 +74,9 @@ class IonRangeCypress public moveToValue( ionCssSelector: SupportedSelectors, options: IonRangeCypressMoveToValueOptions - ): CypressIonicReturn { + ): CypressIonicReturn { return getFromSupportedSelector(ionCssSelector).then(($ionRange) => { - const ionRange = $ionRange[0] as IonRange; + const ionRange = $ionRange[0] as HTMLIonRangeElement; options.targetValue = this.normalizeRangeValue( options.targetValue, @@ -104,11 +104,11 @@ class IonRangeCypress knobSelector, options, }: { - ionRange: IonRange; + ionRange: HTMLIonRangeElement; currentValue: number; knobSelector: RangeKnobSelector; options: IonRangeCypressMoveToValueOptions; - }): CypressIonicReturn { + }): CypressIonicReturn { if (currentValue === options.targetValue) { return cy.wrap(ionRange); } @@ -163,7 +163,7 @@ class IonRangeCypress private moveToObjectValue( ionRange: GenericIonRange, options: IonRangeCypressMoveToValueOptions - ): Cypress.Chainable> { + ): Cypress.Chainable> { // Move upper return this.moveToNumberValue({ ionRange, @@ -252,7 +252,7 @@ class IonRangeCypress /** If the wanted value is big, just set it to the max allowed */ private normalizeRangeValue( value: RangeValue, - ionRange: IonRange + ionRange: HTMLIonRangeElement ): RangeValue { if (typeof value === 'number') { return this.normalizeNumberValue(value, ionRange); @@ -264,7 +264,10 @@ class IonRangeCypress return value; } - private normalizeNumberValue(value: number, ionRange: IonRange): number { + private normalizeNumberValue( + value: number, + ionRange: HTMLIonRangeElement + ): number { if (value < ionRange.min) { cy.log( `${value} is below the accepted min, setting it to ${ionRange.min}` diff --git a/src/components/select/action-sheet-select.ts b/src/components/select/action-sheet-select.ts index 5a032dd..4098c14 100644 --- a/src/components/select/action-sheet-select.ts +++ b/src/components/select/action-sheet-select.ts @@ -1,5 +1,4 @@ import { CypressIonicReturn } from '@interfaces'; -import { IonSelect } from '@ionic/core/components/ion-select'; import { IonSelectFunctions } from './ion-select-functions.abstract'; @@ -9,9 +8,9 @@ export class ActionSheetSelect extends IonSelectFunctions { } selectByOptionText( - $ionSelect: JQuery, + $ionSelect: JQuery, optionText: string - ): CypressIonicReturn { + ): CypressIonicReturn { return this.getOptionButtonsContainer($ionSelect) .findByText(optionText) .parent() @@ -20,9 +19,9 @@ export class ActionSheetSelect extends IonSelectFunctions { } selectByOptionIndex( - $ionSelect: JQuery, + $ionSelect: JQuery, optionIndex: number - ): CypressIonicReturn { + ): CypressIonicReturn { return this.clickOnWantedOption($ionSelect, optionIndex); } } diff --git a/src/components/select/alert-select.ts b/src/components/select/alert-select.ts index fbacd8a..e588c71 100644 --- a/src/components/select/alert-select.ts +++ b/src/components/select/alert-select.ts @@ -1,5 +1,3 @@ -import { IonSelect } from '@ionic/core/components/ion-select'; - import { IonSelectFunctions } from './ion-select-functions.abstract'; export class AlertSelect extends IonSelectFunctions { @@ -7,16 +5,19 @@ export class AlertSelect extends IonSelectFunctions { super('ion-alert.hydrated [role="radiogroup"]', 'button'); } - selectByOptionIndex($ionSelect: JQuery, optionIndex: number) { + selectByOptionIndex( + $ionSelect: JQuery, + optionIndex: number + ) { return this.clickOnWantedOption($ionSelect, optionIndex) .then(() => this.clickOkOnAlert()) .then(() => $ionSelect); } selectByOptionText( - $ionSelect: JQuery, + $ionSelect: JQuery, optionText: string - ): Cypress.Chainable> { + ): Cypress.Chainable> { return this.getOptionButtonsContainer($ionSelect) .findByText(optionText) .click() @@ -24,7 +25,7 @@ export class AlertSelect extends IonSelectFunctions { .then(() => $ionSelect); } - private clickOkOnAlert(): Cypress.Chainable { + private clickOkOnAlert(): Cypress.Chainable { return cy .get('ion-alert.hydrated .alert-button-group button') .then((actionButtons) => { @@ -32,7 +33,7 @@ export class AlertSelect extends IonSelectFunctions { return cy.wrap(okayButton).click(); }) .then(() => { - return cy.wrap(void 0); + return cy.wrap(undefined); }); } } diff --git a/src/components/select/ion-select-functions.abstract.ts b/src/components/select/ion-select-functions.abstract.ts index 3780d25..bb8d5c0 100644 --- a/src/components/select/ion-select-functions.abstract.ts +++ b/src/components/select/ion-select-functions.abstract.ts @@ -1,5 +1,4 @@ import { CypressIonicReturn } from '@interfaces'; -import { IonSelect } from '@ionic/core/components/ion-select'; /** @internal */ export abstract class IonSelectFunctions { @@ -9,17 +8,17 @@ export abstract class IonSelectFunctions { ) {} abstract selectByOptionIndex( - $ionSelect: JQuery, + $ionSelect: JQuery, optionIndex: number - ): CypressIonicReturn; + ): CypressIonicReturn; abstract selectByOptionText( - $ionSelect: JQuery, + $ionSelect: JQuery, optionText: string - ): CypressIonicReturn; + ): CypressIonicReturn; protected getOptionButtonsContainer( - $ionSelect: JQuery + $ionSelect: JQuery ): Cypress.Chainable> { return cy .wrap($ionSelect[0]) @@ -30,9 +29,9 @@ export abstract class IonSelectFunctions { } protected clickOnWantedOption( - $ionSelect: JQuery, + $ionSelect: JQuery, optionIndex: number - ): Cypress.Chainable> { + ): Cypress.Chainable> { return this.getOptionButtonsContainer($ionSelect) .children(this.optionItemCSSSelector) .then((optionButtons) => { diff --git a/src/components/select/ion-select-functions.interface.ts b/src/components/select/ion-select-functions.interface.ts index 1ee9f7e..2a2a58e 100644 --- a/src/components/select/ion-select-functions.interface.ts +++ b/src/components/select/ion-select-functions.interface.ts @@ -1,15 +1,14 @@ import { CypressIonicReturn, SupportedSelectors } from '@interfaces'; -import { IonSelect } from '@ionic/core/components/ion-select'; /** @internal */ export interface IIonSelectFunctions { selectByOptionIndex( selector: SupportedSelectors, optionIndex: number - ): CypressIonicReturn; + ): CypressIonicReturn; selectByOptionText( selector: SupportedSelectors, optionText: string - ): CypressIonicReturn; + ): CypressIonicReturn; } diff --git a/src/components/select/popover-select.ts b/src/components/select/popover-select.ts index 0ebe5b1..4280a4c 100644 --- a/src/components/select/popover-select.ts +++ b/src/components/select/popover-select.ts @@ -1,5 +1,4 @@ import { CypressIonicReturn, SupportedSelectors } from '@interfaces'; -import { IonSelect } from '@ionic/core/components/ion-select'; import { getFromSupportedSelector } from '@helpers'; import { IonSelectFunctions } from './ion-select-functions.abstract'; @@ -14,22 +13,26 @@ export class PopoverSelect extends IonSelectFunctions { public selectByOptionText( selector: SupportedSelectors, optionText: string - ): CypressIonicReturn { - return getFromSupportedSelector(selector).then(($ionSelect) => { - return this.getOptionButtonsContainer($ionSelect) - .findByText(optionText) - .parent() - .click() - .then(() => $ionSelect); - }); + ): CypressIonicReturn { + return getFromSupportedSelector(selector).then( + ($ionSelect) => { + return this.getOptionButtonsContainer($ionSelect) + .findByText(optionText) + .parent() + .click() + .then(() => $ionSelect); + } + ); } selectByOptionIndex( selector: SupportedSelectors, optionIndex: number - ): CypressIonicReturn { - return getFromSupportedSelector(selector).then(($ionSelect) => { - return this.clickOnWantedOption($ionSelect, optionIndex); - }); + ): CypressIonicReturn { + return getFromSupportedSelector(selector).then( + ($ionSelect) => { + return this.clickOnWantedOption($ionSelect, optionIndex); + } + ); } } diff --git a/src/components/select/select.ts b/src/components/select/select.ts index 13c84c2..bc2ff50 100644 --- a/src/components/select/select.ts +++ b/src/components/select/select.ts @@ -1,5 +1,3 @@ -import { IonSelect } from '@ionic/core/components/ion-select'; - import { getFromSupportedSelector } from '../../helpers'; import { CypressIonicReturn, SupportedSelectors } from '../../interfaces'; import { ActionSheetSelect } from './action-sheet-select'; @@ -14,9 +12,9 @@ const popoverSelect = new PopoverSelect(); class Select implements IIonSelectFunctions { private getSelectInterfaceImplementor( - selector: JQuery + selector: JQuery ): Cypress.Chainable { - return getFromSupportedSelector(selector).then( + return getFromSupportedSelector(selector).then( ($ionSelectElement) => { const interfaceOfSelect = $ionSelectElement[0].interface; switch ($ionSelectElement[0].interface) { @@ -34,40 +32,46 @@ class Select implements IIonSelectFunctions { } selectByOptionIndex(selector: SupportedSelectors, optionIndex: number) { - return getFromSupportedSelector(selector).then(($ionSelect) => { - return this.getSelectInterfaceImplementor($ionSelect).then( - (ionsSelectFunctionImplementor) => { - return ionsSelectFunctionImplementor.selectByOptionIndex( - $ionSelect, - optionIndex - ); - } - ); - }); + return getFromSupportedSelector(selector).then( + ($ionSelect) => { + return this.getSelectInterfaceImplementor($ionSelect).then( + (ionsSelectFunctionImplementor) => { + return ionsSelectFunctionImplementor.selectByOptionIndex( + $ionSelect, + optionIndex + ); + } + ); + } + ); } selectByOptionText( selector: SupportedSelectors, optionText: string - ): CypressIonicReturn { - return getFromSupportedSelector(selector).then(($ionSelect) => { - return cy - .log(`Finding ion-select option with text "${optionText}"`) - .then(() => { - return this.getSelectInterfaceImplementor($ionSelect).then( - (ionsSelectFunctionImplementor) => { - return ionsSelectFunctionImplementor - .selectByOptionText($ionSelect, optionText) - .then((v) => { - return cy.wrap(v); - }); - } - ); - }); - }); + ): CypressIonicReturn { + return getFromSupportedSelector(selector).then( + ($ionSelect) => { + return cy + .log(`Finding ion-select option with text "${optionText}"`) + .then(() => { + return this.getSelectInterfaceImplementor($ionSelect).then( + (ionsSelectFunctionImplementor) => { + return ionsSelectFunctionImplementor + .selectByOptionText($ionSelect, optionText) + .then((v) => { + return cy.wrap(v); + }); + } + ); + }); + } + ); } - findIonSelectByLabelText(text: string): CypressIonicReturn { + findIonSelectByLabelText( + text: string + ): CypressIonicReturn { const wantedWords = text.split(' '); const wantedSelectors = wantedWords.map( (word) => `[aria-label~="${word}"]` @@ -76,7 +80,7 @@ class Select implements IIonSelectFunctions { return cy .log(`finding ion select with label "${text}"`) - .get(finalSelector) + .get(finalSelector) .then(($item) => { const ariaLabelIncludesText = $item[0] .getAttribute('aria-label') diff --git a/src/interfaces/supported-selectors.interface.ts b/src/interfaces/supported-selectors.interface.ts index d84b5cd..97a0a33 100644 --- a/src/interfaces/supported-selectors.interface.ts +++ b/src/interfaces/supported-selectors.interface.ts @@ -1,4 +1,7 @@ -export type SupportedSelectors = +import type { HTMLStencilElement } from '@ionic/core'; + +export type SupportedSelectors = | string | Cypress.Chainable> - | JQuery; + | JQuery + | JQuery;