photoprism/frontend/tests/acceptance/acceptance-auth/authentication.js
Michael Mayer a02ecf12de Auth: Use "username" instead of "name" in the session API #98 #2796
Signed-off-by: Michael Mayer <michael@photoprism.app>
2022-10-24 09:21:39 +02:00

155 lines
4.8 KiB
JavaScript

import { Selector } from "testcafe";
import testcafeconfig from "../../testcafeconfig.json";
import Page from "../page-model/page";
import Account from "../page-model/account";
import Settings from "../page-model/settings";
import Menu from "../page-model/menu";
fixture`Test authentication`.page`${testcafeconfig.url}`;
const page = new Page();
const account = new Account();
const menu = new Menu();
const settings = new Settings();
test.meta("testID", "authentication-001").meta({ type: "short", mode: "auth" })(
"Common: Login and Logout",
async (t) => {
await t.navigateTo("/library/browse");
await t
.expect(page.usernameInput.visible)
.ok()
.expect(Selector(".input-search input").visible)
.notOk();
await t.typeText(page.usernameInput, "admin", { replace: true });
await t.expect(page.loginAction.hasAttribute("disabled", "disabled")).ok();
await t.typeText(page.passwordInput, "photoprism", { replace: true });
await t.expect(page.passwordInput.hasAttribute("type", "password")).ok();
await t.click(page.togglePasswordMode);
await t.expect(page.passwordInput.hasAttribute("type", "text")).ok();
await t.click(page.togglePasswordMode);
await t.expect(page.passwordInput.hasAttribute("type", "password")).ok();
await t.click(page.loginAction);
await t.expect(Selector(".input-search input", { timeout: 7000 }).visible).ok();
await page.logout();
await t
.expect(page.usernameInput.visible)
.ok()
.expect(Selector(".input-search input").visible)
.notOk();
await t.navigateTo("/library/settings");
await t
.expect(page.usernameInput.visible)
.ok()
.expect(Selector(".input-search input").visible)
.notOk();
}
);
test.meta("testID", "authentication-002").meta({ type: "short", mode: "auth" })(
"Common: Login with wrong credentials",
async (t) => {
await page.login("wrong", "photoprism");
await t.navigateTo("/library/favorites");
await t
.expect(page.usernameInput.visible)
.ok()
.expect(Selector(".input-search input").visible)
.notOk();
await page.login("admin", "abcdefg");
await t.navigateTo("/library/archive");
await t
.expect(page.usernameInput.visible)
.ok()
.expect(Selector(".input-search input").visible)
.notOk();
}
);
test.meta("testID", "authentication-003").meta({ type: "short", mode: "auth" })(
"Common: Change password",
async (t) => {
await t.navigateTo("/library/browse");
await page.login("admin", "photoprism");
await t.expect(Selector(".input-search input", { timeout: 15000 }).visible).ok();
await menu.openPage("settings");
await t
.click(settings.accountTab)
.click(account.changePasswordAction)
.typeText(account.currentPassword, "wrong", { replace: true })
.typeText(account.newPassword, "photoprism", { replace: true });
await t.expect(account.confirm.hasAttribute("disabled", "disabled")).ok();
await t.typeText(account.retypePassword, "photoprism", { replace: true });
await t.expect(account.confirm.hasAttribute("disabled", "disabled")).notOk();
await t
.click(account.confirm)
.typeText(account.currentPassword, "photoprism", { replace: true })
.typeText(account.newPassword, "1234567", { replace: true })
.typeText(account.retypePassword, "1234567", { replace: true });
await t.expect(account.confirm.hasAttribute("disabled", "disabled")).ok();
await t
.typeText(account.currentPassword, "photoprism", { replace: true })
.typeText(account.newPassword, "photoprism123", { replace: true });
await t.expect(account.confirm.hasAttribute("disabled", "disabled")).ok();
await t.typeText(account.retypePassword, "photoprism123", { replace: true });
await t.expect(account.confirm.hasAttribute("disabled", "disabled")).notOk();
await t.click(account.confirm);
await page.logout();
if (t.browser.platform === "mobile") {
await t.wait(7000);
}
await page.login("admin", "photoprism");
await t.navigateTo("/library/archive");
await t
.expect(page.usernameInput.visible)
.ok()
.expect(Selector(".input-search input").visible)
.notOk();
await page.login("admin", "photoprism123");
await t.expect(Selector(".input-search input").visible).ok();
await menu.openPage("settings");
await t
.click(settings.accountTab)
.click(account.changePasswordAction)
.typeText(account.currentPassword, "photoprism123", { replace: true })
.typeText(account.newPassword, "photoprism", { replace: true })
.typeText(account.retypePassword, "photoprism", { replace: true })
.click(account.confirm);
await page.logout();
await page.login("admin", "photoprism");
await t.expect(Selector(".input-search input").visible).ok();
await page.logout();
}
);