Skip to content

Commit

Permalink
Extend test widget functionality (#2109)
Browse files Browse the repository at this point in the history
Co-authored-by: Farhad Alizada <falizada@microsoft.com>
  • Loading branch information
f-alizada and Farhad Alizada committed Feb 20, 2023
1 parent 26904e3 commit 6103542
Show file tree
Hide file tree
Showing 8 changed files with 24 additions and 10 deletions.
6 changes: 6 additions & 0 deletions tests/e2e/maps/apis.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,10 @@ export class ApisWidget {
await this.page.waitForSelector("api-list.block");
await this.page.waitForSelector("api-list div.table div.table-body div.table-row");
}

public async getApisCount(): Promise<number | undefined> {
return await this.page.evaluate(() =>
document.querySelector("api-list div.table div.table-body div.table-row")?.parentElement?.childElementCount
);
}
}
6 changes: 6 additions & 0 deletions tests/e2e/maps/products.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,10 @@ export class ProductseWidget {
await this.page.waitForSelector("product-list-runtime.block");
await this.page.waitForSelector("product-list-runtime div.table div.table-body div.table-row");
}

public async getProductsCount(): Promise<number | undefined> {
return await this.page.evaluate(() =>
document.querySelector("product-list-runtime div.table div.table-body div.table-row")?.parentElement?.childElementCount
);
}
}
5 changes: 5 additions & 0 deletions tests/e2e/maps/profile.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,9 @@ export class ProfileWidget {
await this.page.waitForSelector("profile-runtime .row");
await this.page.waitForSelector("subscriptions-runtime .table-row");
}

public async getUserEmail(): Promise<string | undefined | null> {
await this.page.waitForSelector("[data-bind='text: user().email']");
return await this.page.evaluate(() =>document.querySelector("[data-bind='text: user().email']")?.textContent);
}
}
3 changes: 3 additions & 0 deletions tests/e2e/maps/signup-basic.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,10 @@ export class SignupBasicWidget {
await this.page.type("#firstName", "Foo");
await this.page.type("#lastName", "Bar");
await this.page.click("#signup");
}

public async getConfirmationMessageValue(): Promise<string | undefined | null> {
await this.page.waitForSelector("#confirmationMessage");
return await this.page.evaluate(() => document.getElementById("confirmationMessage")?.textContent);
}
}
4 changes: 1 addition & 3 deletions tests/e2e/runtime/apis.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,6 @@ describe("Apis page", async () => {
const apiWidget = new ApisWidget(page);
await apiWidget.apis();

expect(await page.evaluate(() =>
document.querySelector("api-list div.table div.table-body div.table-row")?.parentElement?.childElementCount
)).to.equal(apis.apiList.length);
expect(await apiWidget.getApisCount()).to.equal(apis.apiList.length);
});
});
4 changes: 1 addition & 3 deletions tests/e2e/runtime/products.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,6 @@ describe("Products page", async () => {
const productWidget = new ProductseWidget(page);
await productWidget.products();

expect(await page.evaluate(() =>
document.querySelector("product-list-runtime div.table div.table-body div.table-row")?.parentElement?.childElementCount
)).to.equal(products.productList.length);
expect(await productWidget.getProductsCount()).to.equal(products.productList.length);
});
});
4 changes: 1 addition & 3 deletions tests/e2e/runtime/profile.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,6 @@ describe("User profile", async () => {
const profileWidget = new ProfileWidget(page);
await profileWidget.profile();

expect(await page.evaluate(() =>
document.querySelector("[data-bind='text: user().email']")?.textContent
)).to.equal(userInfo.email);
expect(await profileWidget.getUserEmail()).to.equal(userInfo.email);
});
});
2 changes: 1 addition & 1 deletion tests/e2e/runtime/signup.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ describe("User sign-up flow", async () => {
const signUpWidget = new SignupBasicWidget(page);
await signUpWidget.signUpWithBasic();

expect(await page.evaluate(() => document.getElementById("confirmationMessage")?.textContent))
expect(await signUpWidget.getConfirmationMessageValue())
.to.equal("Follow the instructions from the email to verify your account.");
});

Expand Down

0 comments on commit 6103542

Please sign in to comment.