Skip to content

Commit

Permalink
Fixing e2e - changing toggles
Browse files Browse the repository at this point in the history
  • Loading branch information
VitoAlbano committed Dec 11, 2023
1 parent cb9e556 commit 0279f0f
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ export class DataTableComponentPage {
selectedRowNumber: ElementFinder;
allSelectedRows: ElementArrayFinder;
selectAll: ElementFinder;
selectAllChecked: ElementFinder;
emptyList: ElementFinder;
emptyListTitle: ElementFinder;
emptyListSubtitle: ElementFinder;
Expand All @@ -50,6 +51,7 @@ export class DataTableComponentPage {
this.selectedRowNumber = this.rootElement.$(`adf-datatable-row[class*='is-selected'] div[data-automation-id*='text_']`);
this.allSelectedRows = this.rootElement.$$(`adf-datatable-row[class*='is-selected']`);
this.selectAll = this.rootElement.$(`div[class*='adf-datatable-header'] mat-checkbox`);
this.selectAllChecked = this.rootElement.$(`div[class*='adf-datatable-header'] mat-checkbox.mat-mdc-checkbox-checked`);
this.emptyList = this.rootElement.$(`adf-empty-content`);
this.emptyListTitle = this.rootElement.$(`.adf-empty-content__title`);
this.emptyListSubtitle = this.rootElement.$(`.adf-empty-content__subtitle`);
Expand All @@ -66,12 +68,12 @@ export class DataTableComponentPage {

async checkAllRows(): Promise<void> {
await BrowserActions.click(this.selectAll);
await BrowserVisibility.waitUntilElementIsVisible(this.selectAll.$('input[aria-checked="true"]'));
await BrowserVisibility.waitUntilElementIsVisible(this.selectAllChecked);
}

async uncheckAllRows(): Promise<void> {
await BrowserActions.click(this.selectAll);
await BrowserVisibility.waitUntilElementIsNotVisible(this.selectAll.$('input[aria-checked="true"]'));
await BrowserVisibility.waitUntilElementIsNotVisible(this.selectAll.$('.mat-mdc-checkbox-checked'));
}

async clickCheckbox(columnName: string, columnValue: string): Promise<void> {
Expand All @@ -80,18 +82,23 @@ export class DataTableComponentPage {
}

async checkRowIsNotChecked(columnName: string, columnValue: string): Promise<void> {
await BrowserVisibility.waitUntilElementIsNotVisible(this.getRowCheckbox(columnName, columnValue).$('input[aria-checked="true"]'));
const rowSelector = this.getRowCheckboxChecked(columnName, columnValue);
await BrowserVisibility.waitUntilElementIsNotVisible(rowSelector);
}

async checkRowIsChecked(columnName: string, columnValue: string): Promise<void> {
const rowCheckbox = this.getRowCheckbox(columnName, columnValue);
await BrowserVisibility.waitUntilElementIsVisible(rowCheckbox.$('input[aria-checked="true"]'));
const rowCheckbox = this.getRowCheckboxChecked(columnName, columnValue);
await BrowserVisibility.waitUntilElementIsVisible(rowCheckbox);
}

getRowCheckbox(columnName: string, columnValue: string): ElementFinder {
return this.getRow(columnName, columnValue).$('mat-checkbox');
}

getRowCheckboxChecked(columnName: string, columnValue: string): ElementFinder {
return this.getRow(columnName, columnValue).$('mat-checkbox.mat-mdc-checkbox-checked');
}

async checkNoRowIsSelected(): Promise<void> {
await BrowserVisibility.waitUntilElementIsNotVisible(this.selectedRowNumber);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,14 @@ export class CheckboxPage {

static async uncheck(el: ElementFinder) {
const classList = await BrowserActions.getAttribute(el, 'class');
if (classList && classList.indexOf('mat-checked') > -1) {
if (classList && classList.indexOf('mdc-checkbox--selected') > -1) {
await BrowserActions.click(el);
}
}

static async check(el: ElementFinder) {
const classList = await BrowserActions.getAttribute(el, 'class');
if (classList && classList.indexOf('mat-checked') === -1) {
if (classList && classList.indexOf('mdc-checkbox--selected') === -1) {
await BrowserActions.click(el);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,15 @@ export class TogglePage {

async enableToggle(toggle: ElementFinder): Promise<void> {
const check = await BrowserActions.getAttribute(toggle, 'class');
if (check.indexOf('mat-checked') < 0) {
if (check.indexOf('mdc-switch--checked') < 0) {
const elem = toggle.$$('input').first();
await BrowserActions.clickScript(elem);
}
}

async disableToggle(toggle: ElementFinder): Promise<void> {
const check = await BrowserActions.getAttribute(toggle, 'class');
if (check.indexOf('mat-checked') >= 0) {
if (check.indexOf('mdc-switch--checked') >= 0) {
const elem = toggle.$$('input').first();
await BrowserActions.clickScript(elem);
}
Expand Down
30 changes: 20 additions & 10 deletions lib/testing/src/lib/protractor/core/pages/settings.page.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,9 @@ export class SettingsPage {
logoutUrlText = $('input[id="logout-url"]');
identityHostText = $('input[id="identityHost"]');
ssoRadioButton = element(by.cssContainingText('[id*="mat-radio"]', 'SSO'));
silentLoginToggleLabel = $('mat-slide-toggle[formcontrolname="silentLogin"] label');
silentLoginToggleElement = $('mat-slide-toggle[formcontrolname="silentLogin"]');
implicitFlowLabel = $('mat-slide-toggle[formcontrolname="implicitFlow"] label');
implicitFlowElement = $('mat-slide-toggle[formcontrolname="implicitFlow"]');
silentLoginToggleButton = $('button[name="silentLogin"]');
implicitFlowButton = $('button[name="implicitFlow"]');
codeFlowButton = $('button[name="codeFlow"]');
applyButton = $('button[data-automation-id="settings-apply-button"]');
providerDropdown = new DropdownPage($('mat-select[id="adf-provider-selector"]'));

Expand Down Expand Up @@ -67,6 +66,7 @@ export class SettingsPage {
await this.setIdentityHost(identityHost);
await this.setSilentLogin(silentLogin);
await this.setImplicitFlow(implicitFlow);
await this.setCodeFlow(true);
await this.setClientId(clientId);
await this.setLogoutUrl(logoutUrl);
await this.clickApply();
Expand Down Expand Up @@ -99,22 +99,32 @@ export class SettingsPage {
}

async setSilentLogin(enableToggle) {
await BrowserVisibility.waitUntilElementIsVisible(this.silentLoginToggleElement);
await BrowserVisibility.waitUntilElementIsVisible(this.silentLoginToggleButton);

const isChecked = (await BrowserActions.getAttribute(this.silentLoginToggleElement, 'class')).includes('mat-checked');
const isChecked = (await BrowserActions.getAttribute(this.silentLoginToggleButton, 'aria-checked')) === 'true';

if (isChecked && !enableToggle || !isChecked && enableToggle) {
await BrowserActions.click(this.silentLoginToggleLabel);
await BrowserActions.click(this.silentLoginToggleButton);
}
}

async setImplicitFlow(enableToggle) {
await BrowserVisibility.waitUntilElementIsVisible(this.implicitFlowElement);
await BrowserVisibility.waitUntilElementIsVisible(this.implicitFlowButton);

const isChecked = (await BrowserActions.getAttribute(this.implicitFlowElement, 'class')).includes('mat-checked');
const isChecked = (await BrowserActions.getAttribute(this.implicitFlowButton, 'aria-checked')) === 'true';;

if (isChecked && !enableToggle || !isChecked && enableToggle) {
await BrowserActions.click(this.implicitFlowLabel);
await BrowserActions.click(this.implicitFlowButton);
}
}

async setCodeFlow(enableToggle) {
await BrowserVisibility.waitUntilElementIsVisible(this.codeFlowButton);

const isChecked = (await BrowserActions.getAttribute(this.codeFlowButton, 'aria-checked')) === 'true';

if (isChecked && !enableToggle || !isChecked && enableToggle) {
await BrowserActions.click(this.codeFlowButton);
}
}
}

0 comments on commit 0279f0f

Please sign in to comment.