photoprism/frontend/tests/acceptance/page-model/album.js

154 lines
4.6 KiB
JavaScript
Raw Normal View History

import { Selector, t } from "testcafe";
export default class Page {
constructor() {}
async getNthAlbumUid(type, nth) {
if (type === "all") {
const NthAlbum = await Selector("a.is-album").nth(nth).getAttribute("data-uid");
return NthAlbum;
} else {
const NthAlbum = await Selector("a.type-" + type)
.nth(nth)
.getAttribute("data-uid");
return NthAlbum;
}
}
async getAlbumCount(type) {
if (type === "all") {
if (t.browser.platform === "mobile") {
const AlbumCount = await Selector("a.is-album", { timeout: 8000 }).count;
return AlbumCount;
} else {
const AlbumCount = await Selector("a.is-album", { timeout: 5000 }).count;
return AlbumCount;
}
} else {
if (t.browser.platform === "mobile") {
const AlbumCount = await Selector("a.type-" + type, { timeout: 8000 }).count;
return AlbumCount;
} else {
const AlbumCount = await Selector("a.type-" + type, { timeout: 5000 }).count;
return AlbumCount;
}
}
}
async selectAlbumFromUID(uid) {
await t
.hover(Selector("a.is-album").withAttribute("data-uid", uid))
.click(Selector(`.uid-${uid} .input-select`));
}
async toggleSelectNthAlbum(nth, type) {
if (type === "all") {
await t
.hover(Selector("a.is-album", { timeout: 4000 }).nth(nth))
.click(Selector("a.is-album .input-select").nth(nth));
} else {
await t
.hover(Selector("a.type-" + type, { timeout: 4000 }).nth(nth))
.click(Selector("a.type-" + type + " .input-select").nth(nth));
}
}
2022-10-28 11:16:13 +02:00
async openNthAlbum(nth, type) {
if (!type || type === "all") {
if (await Selector("a.is-album").nth(nth).visible) {
await t.click(Selector("a.is-album").nth(nth));
}
} else {
if (await Selector("a.type-" + type).nth(nth).visible) {
await t.click(Selector("a.type-" + type).nth(nth));
}
}
}
async openAlbumWithUid(uid) {
await t.click(Selector("a.is-album").withAttribute("data-uid", uid));
}
async checkAlbumVisibility(uid, visible) {
if (visible) {
await t.expect(Selector("a").withAttribute("data-uid", uid).visible).ok();
} else {
await t.expect(Selector("a").withAttribute("data-uid", uid).visible).notOk();
}
}
async triggerHoverAction(mode, uidOrNth, action) {
if (mode === "uid") {
2022-04-14 20:07:55 +02:00
if (action === "share") {
await t.hover(Selector("a.uid-" + uidOrNth));
await t.click(Selector("a.uid-" + uidOrNth + " .action-" + action));
} else {
await t.hover(Selector("a.uid-" + uidOrNth));
await t.click(Selector("a.uid-" + uidOrNth + " .input-" + action));
}
}
if (mode === "nth") {
await t.hover(Selector("a.is-album").nth(uidOrNth));
await t.click(Selector(`.input-` + action));
}
}
async checkHoverActionAvailability(mode, uidOrNth, action, visible) {
if (mode === "uid") {
await t.hover(Selector("a.is-album").withAttribute("data-uid", uidOrNth));
if (visible) {
await t.expect(Selector(`.uid-${uidOrNth} .input-` + action).visible).ok();
} else {
await t.expect(Selector(`.uid-${uidOrNth} .input-` + action).visible).notOk();
}
}
if (mode === "nth") {
await t.hover(Selector("a.is-album").nth(uidOrNth));
2022-10-26 19:29:34 +02:00
if (action != "share") {
if (visible) {
await t.expect(Selector(`button.input-` + action).visible).ok();
} else {
await t.expect(Selector(`button.input-` + action).visible).notOk();
}
} else {
2022-10-26 19:29:34 +02:00
if (visible) {
await t.expect(Selector(`button.action-` + action).visible).ok();
} else {
await t.expect(Selector(`button.action-` + action).visible).notOk();
}
}
}
}
async checkHoverActionState(mode, uidOrNth, action, set) {
if (mode === "uid") {
await t.hover(Selector("a").withAttribute("data-uid", uidOrNth));
if (set) {
await t.expect(Selector(`a.uid-${uidOrNth}`).hasClass("is-" + action)).ok();
} else {
await t.expect(Selector(`a.uid-${uidOrNth}`).hasClass("is-" + action)).notOk();
}
}
if (mode === "nth") {
await t.hover(Selector("a.is-album").nth(uidOrNth));
if (set) {
await t
.expect(
Selector("a.is-album")
.nth(uidOrNth)
.hasClass("is-" + action)
)
.ok();
} else {
await t
.expect(
Selector("a.is-album")
.nth(uidOrNth)
.hasClass("is-" + action)
)
.notOk();
}
}
}
}