Skip to content

Commit

Permalink
Fix format
Browse files Browse the repository at this point in the history
  • Loading branch information
SannyNguyenHung committed Oct 23, 2023
1 parent ad3a76d commit d97b49d
Show file tree
Hide file tree
Showing 3 changed files with 75 additions and 31 deletions.
88 changes: 64 additions & 24 deletions tests/TestHelper/TroiPage.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
import { expect } from "@playwright/test";
import {
TimeoutConfig
} from "./TestHelper/TestHelper";
import { TimeoutConfig } from "./TestHelper/TestHelper";

export default class TroiPage {
constructor(page) {
Expand Down Expand Up @@ -45,41 +43,83 @@ export default class TroiPage {
const hoursTestId = "hours-" + projectId;
const descriptionTestId = "description-" + projectId;
if (hidden) {
await expect(this.page.getByTestId(hoursTestId)).toBeHidden(TimeoutConfig);
await expect(this.page.getByTestId(descriptionTestId)).toBeHidden(TimeoutConfig);
await expect(this.page.getByTestId(hoursTestId)).toBeHidden(
TimeoutConfig
);
await expect(this.page.getByTestId(descriptionTestId)).toBeHidden(
TimeoutConfig
);
} else {
await expect(this.page.getByTestId(hoursTestId)).toBeVisible(TimeoutConfig);
await expect(this.page.getByTestId(descriptionTestId)).toBeVisible(TimeoutConfig);
await expect(this.page.getByTestId(hoursTestId)).toBeVisible(
TimeoutConfig
);
await expect(this.page.getByTestId(descriptionTestId)).toBeVisible(
TimeoutConfig
);
}
}

async _expectOnlyDeleteAndEditVisible(projectId) {
await expect(this.page.getByTestId(`delete-${projectId}`)).toBeVisible(TimeoutConfig);
await expect(this.page.getByTestId(`edit-${projectId}`)).toBeVisible(TimeoutConfig);
await expect(this.page.getByTestId(`add-${projectId}`)).toBeHidden(TimeoutConfig);
await expect(this.page.getByTestId(`cancel-${projectId}`)).toBeHidden(TimeoutConfig);
await expect(this.page.getByTestId(`save-${projectId}`)).toBeHidden(TimeoutConfig);
await expect(this.page.getByTestId(`delete-${projectId}`)).toBeVisible(
TimeoutConfig
);
await expect(this.page.getByTestId(`edit-${projectId}`)).toBeVisible(
TimeoutConfig
);
await expect(this.page.getByTestId(`add-${projectId}`)).toBeHidden(
TimeoutConfig
);
await expect(this.page.getByTestId(`cancel-${projectId}`)).toBeHidden(
TimeoutConfig
);
await expect(this.page.getByTestId(`save-${projectId}`)).toBeHidden(
TimeoutConfig
);
}

async _expectOnlyAddVisible(projectId) {
await expect(this.page.getByTestId(`delete-${projectId}`)).toBeHidden(TimeoutConfig);
await expect(this.page.getByTestId(`edit-${projectId}`)).toBeHidden(TimeoutConfig);
await expect(this.page.getByTestId(`add-${projectId}`)).toBeVisible(TimeoutConfig);
await expect(this.page.getByTestId(`cancel-${projectId}`)).toBeHidden(TimeoutConfig);
await expect(this.page.getByTestId(`save-${projectId}`)).toBeHidden(TimeoutConfig);
await expect(this.page.getByTestId(`delete-${projectId}`)).toBeHidden(
TimeoutConfig
);
await expect(this.page.getByTestId(`edit-${projectId}`)).toBeHidden(
TimeoutConfig
);
await expect(this.page.getByTestId(`add-${projectId}`)).toBeVisible(
TimeoutConfig
);
await expect(this.page.getByTestId(`cancel-${projectId}`)).toBeHidden(
TimeoutConfig
);
await expect(this.page.getByTestId(`save-${projectId}`)).toBeHidden(
TimeoutConfig
);
}

async expectOnlyCancelAndSaveVisible(projectId) {
await expect(this.page.getByTestId(`delete-${projectId}`)).toBeHidden(TimeoutConfig);
await expect(this.page.getByTestId(`edit-${projectId}`)).toBeHidden(TimeoutConfig);
await expect(this.page.getByTestId(`add-${projectId}`)).toBeHidden(TimeoutConfig);
await expect(this.page.getByTestId(`cancel-${projectId}`)).toBeVisible(TimeoutConfig);
await expect(this.page.getByTestId(`save-${projectId}`)).toBeVisible(TimeoutConfig);
await expect(this.page.getByTestId(`delete-${projectId}`)).toBeHidden(
TimeoutConfig
);
await expect(this.page.getByTestId(`edit-${projectId}`)).toBeHidden(
TimeoutConfig
);
await expect(this.page.getByTestId(`add-${projectId}`)).toBeHidden(
TimeoutConfig
);
await expect(this.page.getByTestId(`cancel-${projectId}`)).toBeVisible(
TimeoutConfig
);
await expect(this.page.getByTestId(`save-${projectId}`)).toBeVisible(
TimeoutConfig
);
}

async expectLoading() {
await expect(this.page.getByTestId("loadingOverlay")).toBeVisible(TimeoutConfig);
await expect(this.page.getByTestId("loadingOverlay")).toBeHidden(TimeoutConfig);
await expect(this.page.getByTestId("loadingOverlay")).toBeVisible(
TimeoutConfig
);
await expect(this.page.getByTestId("loadingOverlay")).toBeHidden(
TimeoutConfig
);
}

async clickOnWeekDay(dayIndex) {
Expand Down
8 changes: 4 additions & 4 deletions tests/login.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,7 @@ import { expect, test } from "@playwright/test";
import LoginPage from "./TestHelper/LoginPage";
import TroiApiStub, { username, password } from "./TestHelper/TroiApiStub";
import { initializeTestSetup } from "./TestHelper/TestHelper";
import {
TimeoutConfig
} from "./TestHelper/TestHelper";
import { TimeoutConfig } from "./TestHelper/TestHelper";

test.beforeEach(async ({ context, page }) => {
page.on("console", (msg) => console.log(msg.text()));
Expand All @@ -26,6 +24,8 @@ test.describe("Auth", async () => {
).toBeVisible();

await page.locator("text=LOGOUT").click();
await expect(page.locator("h2 >> text=Enter. Time.")).toBeVisible(TimeoutConfig);
await expect(page.locator("h2 >> text=Enter. Time.")).toBeVisible(
TimeoutConfig
);
});
});
10 changes: 7 additions & 3 deletions tests/timeEntriesOneProject.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import {
fixedCurrentDate,
initializeTestSetup,
setFixedCurrentDate,
TimeoutConfig
TimeoutConfig,
} from "./TestHelper/TestHelper";
import TroiApiStub from "./TestHelper/TroiApiStub";
import { username, password } from "./TestHelper/TroiApiStub";
Expand Down Expand Up @@ -101,10 +101,14 @@ test("add entry with invalid data shows error", async ({ context, page }) => {
await troiPage.expectLoading();

await troiPage.fillForm(entryToAdd);
await expect(page.getByTestId(`error-${entryToAdd.projectId}`)).toBeHidden(TimeoutConfig);
await expect(page.getByTestId(`error-${entryToAdd.projectId}`)).toBeHidden(
TimeoutConfig
);
await troiPage.submitForm(entryToAdd.projectId);
await expect(page.getByTestId("loadingOverlay")).toBeHidden(TimeoutConfig);
await expect(page.getByTestId("error-" + entryToAdd.projectId)).toBeVisible(TimeoutConfig);
await expect(page.getByTestId("error-" + entryToAdd.projectId)).toBeVisible(
TimeoutConfig
);
});

test("delete existing entry works", async ({ context, page }) => {
Expand Down

0 comments on commit d97b49d

Please sign in to comment.