Skip to content

Commit 77d3299

Browse files
Copilotrenemadsen
andcommitted
Update Cypress page objects to use actions menu pattern
Co-authored-by: renemadsen <[email protected]>
1 parent f4764e3 commit 77d3299

File tree

4 files changed

+54
-21
lines changed

4 files changed

+54
-21
lines changed

eform-client/cypress/e2e/DeviceUsers.page.ts

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,9 @@ class DeviceUsersPage extends PageWithNavbarPage{
156156
name = '',
157157
surname = ''
158158
): void {
159-
deviceUser.editBtn().should('be.visible').click();
159+
const index = deviceUser.index - 1;
160+
deviceUser.openRowMenu();
161+
cy.get(`#editDeviceUserBtn${index}`).should('be.visible').click();
160162
// @ts-ignore
161163
cy.get('#firstName').should('be.visible');
162164
if (name !== '') {
@@ -178,6 +180,7 @@ const deviceUsersPage = new DeviceUsersPage();
178180
export default deviceUsersPage;
179181

180182
export class DeviceUsersRowObject {
183+
index: number;
181184
siteId: number;
182185
firstName: string;
183186
lastName: string;
@@ -187,6 +190,7 @@ export class DeviceUsersRowObject {
187190
deleteBtn: Cypress.Chainable<JQuery<HTMLElement>>;
188191

189192
getRow(rowNum: number) {
193+
this.index = rowNum;
190194
// @ts-ignore
191195
if (cy.get('#deviceUserId').eq(rowNum - 1).should('exist')) {
192196
// @ts-ignore
@@ -203,8 +207,16 @@ export class DeviceUsersRowObject {
203207
return this;
204208
}
205209

210+
openRowMenu() {
211+
const index = this.index - 1;
212+
cy.get(`#action-items-${index} #actionMenu`).should('be.visible').click();
213+
cy.wait(200);
214+
}
215+
206216
delete() {
207-
this.deleteBtn.should('be.visible').click();
217+
const index = this.index - 1;
218+
this.openRowMenu();
219+
cy.get(`#deleteDeviceUserBtn${index}`).should('be.visible').click();
208220
deviceUsersPage.saveDeleteBtn().should('be.visible').click();
209221
// @ts-ignore
210222
cy.get('#spinner-animation').should('not.exist', { timeout: 40000 });

eform-client/cypress/e2e/Sites.page.ts

Lines changed: 15 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,7 @@ export default sitesPage;
125125
export class SitesRowObject {
126126
constructor() {}
127127

128+
index: number;
128129
element: Cypress.Chainable<JQuery<HTMLElement>>;
129130
siteId: number;
130131
units: string;
@@ -134,6 +135,7 @@ export class SitesRowObject {
134135
deleteBtn: Cypress.Chainable<JQuery<HTMLElement>>;
135136

136137
getRow(rowNum): Promise<SitesRowObject> {
138+
this.index = rowNum;
137139
this.element = cy.get('tbody > tr').eq(rowNum - 1);
138140
if (this.element) {
139141
this.siteId = +(this.element.find('#siteUUId').invoke('text'));
@@ -146,6 +148,13 @@ export class SitesRowObject {
146148
}
147149
return this;
148150
}
151+
152+
openRowMenu() {
153+
const index = this.index - 1;
154+
cy.get(`#action-items-${index} #actionMenu`).should('be.visible').click();
155+
cy.wait(200);
156+
}
157+
149158
closeEditModal(clickCancel = false) {
150159
if (clickCancel) {
151160
sitesPage.siteEditCancelBtn().click();
@@ -156,22 +165,10 @@ export class SitesRowObject {
156165
sitesPage.sitesManageTagsBtn().should('be.visible', { timeout: 40000 });
157166
}
158167

159-
getRow(rowNum): Promise<SitesRowObject> {
160-
this.element = Cypress.$$('tbody > tr').eq(rowNum - 1);
161-
if (this.element) {
162-
this.siteId = +this.element.find('#siteUUId').text();
163-
this.units = this.element.find('#units').text();
164-
this.siteName = this.element.find('#siteName').text();
165-
const list = this.element.find('mat-chip-list mat-chip > span');
166-
this.tags = Promise.all(list.map((_, element) => Cypress.$(element).text()));
167-
this.editBtn = this.element.find('#editSiteBtn');
168-
this.deleteBtn = this.element.find('#deleteSiteBtn');
169-
}
170-
return this;
171-
}
172-
173168
openEditModal(site?: { name?: string; tags?: string[] }) {
174-
this.editBtn.click();
169+
const index = this.index - 1;
170+
this.openRowMenu();
171+
cy.get(`#editSiteBtn${index}`).should('be.visible').click();
175172
cy.wait(500);
176173
sitesPage.siteEditCancelBtn().should('be.visible', {timeout: 40000});
177174
if (site) {
@@ -196,7 +193,9 @@ export class SitesRowObject {
196193
}
197194

198195
openDeleteModal() {
199-
this.deleteBtn.click();
196+
const index = this.index - 1;
197+
this.openRowMenu();
198+
cy.get(`#deleteSiteBtn${index}`).should('be.visible').click();
200199
cy.wait(500);
201200
sitesPage.siteDeleteCancelBtn().should('be.visible', {timeout: 40000}).click();
202201
}

eform-client/cypress/e2e/UserAdministration.page.ts

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,7 @@ const userAdministrationPage = new UserAdministrationPage();
170170
export default userAdministrationPage;
171171

172172
export class UserAdministrationRowObject {
173+
index: number;
173174
id: number;
174175
email: string;
175176
fullName: string;
@@ -178,6 +179,7 @@ export class UserAdministrationRowObject {
178179
deleteBtn: Cypress.Chainable<JQuery<HTMLElement>>;
179180

180181
getRow(rowNum: number) {
182+
this.index = rowNum;
181183
const index = rowNum - 1;
182184

183185
cy.get(`#userAdministrationId-${index}`).invoke('text').then(text => {
@@ -199,8 +201,16 @@ export class UserAdministrationRowObject {
199201
return this;
200202
}
201203

204+
openRowMenu() {
205+
const index = this.index - 1;
206+
cy.get(`#action-items-${index} #actionMenu`).should('be.visible').click();
207+
cy.wait(200);
208+
}
209+
202210
edit(user: UserAdministrationObject, clickCancel = false) {
203-
this.editBtn.should('be.visible').click();
211+
const index = this.index - 1;
212+
this.openRowMenu();
213+
cy.get(`#userAdministrationEditBtn-${index}`).should('be.visible').click();
204214
cy.get('#editFirstName').should('be.visible');
205215

206216
if (user.firstName) {
@@ -257,7 +267,9 @@ export class UserAdministrationRowObject {
257267
}
258268

259269
delete(clickCancel = false) {
260-
this.deleteBtn.should('be.visible').click();
270+
const index = this.index - 1;
271+
this.openRowMenu();
272+
cy.get(`#userAdministrationDeleteBtn-${index}`).should('be.visible').click();
261273
cy.get('#userDeleteCancelBtn').should('be.visible');
262274

263275
if (clickCancel) {

eform-client/cypress/e2e/Workers.page.ts

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,9 @@ class WorkersPage extends PageWithNavbarPage {
127127
firstName = '',
128128
lastName = ''
129129
): void {
130-
worker.editBtn().should('be.visible').click();
130+
const index = worker.index - 1;
131+
worker.openRowMenu();
132+
cy.get(`#workerEditBtn${index}`).should('be.visible').click();
131133
// @ts-ignore
132134
cy.get('#firstNameEdit').should('be.visible');
133135
if (firstName !== '') {
@@ -152,6 +154,7 @@ const workersPage = new WorkersPage();
152154
export default workersPage;
153155

154156
export class WorkersRowObject {
157+
index: number;
155158
siteId: number;
156159
firstName: string;
157160
lastName: string;
@@ -161,6 +164,7 @@ export class WorkersRowObject {
161164
deleteBtn: Cypress.Chainable<JQuery<HTMLElement>>;
162165

163166
getRow(rowNum: number) {
167+
this.index = rowNum;
164168
// @ts-ignore
165169
if (cy.get('#workerUID').eq(rowNum - 1).should('exist')) {
166170
// @ts-ignore
@@ -176,4 +180,10 @@ export class WorkersRowObject {
176180
}
177181
return this;
178182
}
183+
184+
openRowMenu() {
185+
const index = this.index - 1;
186+
cy.get(`#action-items-${index} #actionMenu`).should('be.visible').click();
187+
cy.wait(200);
188+
}
179189
}

0 commit comments

Comments
 (0)