Files
web2.0-frontend/tests/testcafe/admin.test.ts
T
Aarni Halinen 0e18968178 Fix E2E test
2020-10-08 19:31:04 +03:00

60 lines
1.7 KiB
TypeScript

/**
* TestCafé test fixtures.
* This file is used by TestCafé to run end-to-end tests with chrome against the site.
* Tests are grouped into fixtures and fixtures into files.
*/
import { Selector, ClientFunction } from "testcafe";
fixture`Admin login page functions correctly`.page("http://localhost:3000/admin/login");
test("Login form exists", async t => {
/**
* Test if the page contains a form.
*/
const form = Selector("form.admin-login-form");
await t.expect(form.exists).ok();
});
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"));
const frontPage = Selector(".admin-front-page");
await t.expect(frontPage.exists).ok();
});
test("User can log out and is redirected to login", async t => {
/**
* Test if the user can log out.
*/
await t.click(Selector("#login-submit"));
const logout = Selector("#admin-sidebar-logout");
await t.click(logout);
const loginForm = Selector("form.admin-login-form");
await t.expect(loginForm.exists).ok();
});
test("User is redirected to login when JWT token is invalid", async t => {
/**
* Test if the user is redirected to login when JWT token is invalid.
*/
const TOKEN = "FOOBAR";
const setCookie = ClientFunction(() => {
document.cookie = `jwt=${TOKEN}`;
});
await t.navigateTo("/admin/events");
const loginForm = Selector("form.admin-login-form");
await t.expect(loginForm.exists).ok();
});