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

151 lines
4.5 KiB
JavaScript
Raw Normal View History

import {Selector, t} from 'testcafe';
export default class Page {
constructor() {
this.view = Selector('div.p-view-select', {timeout: 15000});
this.camera = Selector('div.p-camera-select', {timeout: 15000});
this.countries = Selector('div.p-countries-select', {timeout: 15000});
this.time = Selector('div.p-time-select', {timeout: 15000});
this.search1 = Selector('div.input-search input', {timeout: 15000});
}
async setFilter(filter, option) {
let filterSelector = "";
switch (filter) {
case 'view':
filterSelector = 'div.p-view-select';
break;
case 'camera':
filterSelector = 'div.p-camera-select';
break;
case 'time':
filterSelector = 'div.p-time-select';
break;
case 'countries':
filterSelector = 'div.p-countries-select';
break;
default:
throw "unknown filter";
}
await t
.click(filterSelector, {timeout: 15000});
if (option) {
await t
2020-06-04 16:25:29 +00:00
.click(Selector('div[role="listitem"]').withText(option), {timeout: 15000})
} else {
await t
2020-06-04 16:25:29 +00:00
.click(Selector('div[role="listitem"]').nth(1), {timeout: 15000})
}
}
async search(term) {
await t
2020-06-02 11:07:18 +00:00
.typeText(this.search1, term, { replace: true })
.pressKey('enter')
}
async openNav() {
if (await Selector('button.nav-show').exists) {
await t.click(Selector('button.nav-show'));
} else if (await Selector('div.nav-expand').exists) {
await t.click(Selector('div.nav-expand i'));
}
}
2019-07-02 16:16:11 +00:00
2020-06-01 15:04:47 +00:00
async selectFromUID(uid) {
await t
.hover(Selector('div').withAttribute('data-uid', uid))
.click(Selector('.t-select.t-off'));
}
2020-06-01 15:04:47 +00:00
async unselectFromUID(uid) {
await t
.hover(Selector('div').withAttribute('data-uid', uid))
.click(Selector('.t-select.t-on'));
}
async selectNthPhoto(nPhoto) {
2019-07-02 16:16:11 +00:00
await t
2020-06-05 13:22:16 +00:00
.hover(Selector('.p-photo', {timeout:4000}).nth(nPhoto))
.click(Selector('.t-select.t-off'));
2019-07-02 16:16:11 +00:00
}
async unselectPhoto(nPhoto) {
await t
2020-06-05 13:22:16 +00:00
.hover(Selector('.p-photo', {timeout:4000}).nth(nPhoto))
.click(Selector('.t-select.t-on'));
2019-07-02 16:16:11 +00:00
}
async likePhoto(uid) {
2019-07-02 16:16:11 +00:00
await t
.click(Selector('.t-like.t-off').withAttribute('data-uid', uid));
2019-07-02 16:16:11 +00:00
}
2019-11-21 17:56:11 +00:00
async dislikePhoto(uid) {
await t
.click(Selector('.t-like.t-on').withAttribute('data-uid', uid));
}
2020-06-01 15:04:47 +00:00
async archiveSelected() {
await t
2020-06-23 11:06:55 +00:00
.click(Selector('button.action-menu'))
.click(Selector('button.action-archive'))
.click(Selector('button.action-confirm'));
}
2020-06-01 15:04:47 +00:00
async restoreSelected() {
await t
2020-06-23 11:06:55 +00:00
.click(Selector('button.action-menu'))
.click(Selector('button.action-restore'));
}
2020-06-01 15:04:47 +00:00
async editSelected() {
2020-06-23 11:06:55 +00:00
if (await Selector('button.action-edit').visible) {
await t.click(Selector('button.action-edit'));
} else if (await Selector('button.action-menu').exists) {
await t
2020-06-23 11:06:55 +00:00
.click(Selector('button.action-menu'))
.click(Selector('button.action-edit'));
}
}
2020-06-23 11:06:55 +00:00
async deleteSelected() {
2020-06-01 15:04:47 +00:00
await t
2020-06-23 11:06:55 +00:00
.click(Selector('button.action-menu'))
.click(Selector('button.action-delete'))
.click(Selector('button.action-confirm'));
2020-06-01 15:04:47 +00:00
}
async removeSelected() {
await t
2020-06-23 11:06:55 +00:00
.click(Selector('button.action-menu'))
.click(Selector('button.action-delete'));
2020-06-01 15:04:47 +00:00
}
async addSelectedToAlbum(name) {
await t
2020-06-23 11:06:55 +00:00
.click(Selector('button.action-menu'))
.click(Selector('button.action-album'))
2020-06-01 15:04:47 +00:00
.typeText(Selector('.input-album input'), name, { replace: true })
2020-06-23 11:06:55 +00:00
.pressKey('enter');
if (await Selector('div[role="listitem"]').withText(name).visible) {
await t.click(Selector('div[role="listitem"]').withText(name));
}
await t.click(Selector('button.action-confirm'));
2020-06-01 15:04:47 +00:00
}
2019-11-21 17:56:11 +00:00
async login(password) {
await t
.typeText(Selector('input[type="password"]'), password)
.pressKey('enter');
}
async logout() {
await t
.click(Selector('div.nav-logout'));
2019-11-21 17:56:11 +00:00
}
}