diff --git a/tests/testcafe/admin/common/login.ts b/tests/testcafe/admin/common/login.ts new file mode 100644 index 0000000..3b43c3c --- /dev/null +++ b/tests/testcafe/admin/common/login.ts @@ -0,0 +1,10 @@ +import { Selector } from "testcafe"; + +const USERNAME = "admin"; +const PASSWORD = "password123"; + +export const doLogin = async (t: TestController) => { + await t.typeText(Selector("#login-username"), USERNAME); + await t.typeText(Selector("#login-password"), PASSWORD); + await t.click(Selector("#login-submit")); +} \ No newline at end of file diff --git a/tests/testcafe/login.test.ts b/tests/testcafe/login.test.ts index 6500a11..122c05c 100644 --- a/tests/testcafe/login.test.ts +++ b/tests/testcafe/login.test.ts @@ -1,5 +1,6 @@ import { Selector, ClientFunction } from "testcafe"; import { getSiteRoot } from "./utils"; +import { doLogin } from "./admin/common/login"; fixture`Admin login page functions correctly`.page(`${getSiteRoot}/admin/login`); @@ -15,12 +16,7 @@ test("User can log in with default credentials", async t => { /** * Test if the user can log in with default credentials. */ - const USERNAME = "admin"; - const PASSWORD = "password123"; - - await t.typeText(Selector("#login-username"), USERNAME); - await t.typeText(Selector("#login-password"), PASSWORD); - await t.click(Selector("#login-submit")); + await doLogin(t); const frontPage = Selector("[data-e2e=\"admin-front-page\"]"); await t.expect(frontPage.exists).ok(); diff --git a/tsconfig.json b/tsconfig.json index b5ba85b..743db21 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -60,6 +60,6 @@ "include": [ "./src/**/*", "./types/**/*", - "./tests/testcafe" + "./tests/testcafe/**/*" ], } \ No newline at end of file