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

148 lines
4.7 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.p-search-field 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
.click(Selector('div.menuable__content__active div.v-select-list a').withText(option), {timeout: 15000})
} else {
await t
.click(Selector('div.menuable__content__active div.v-select-list a').nth(1), {timeout: 15000})
}
}
async search(term) {
await t
2020-06-02 13:07:18 +02:00
.typeText(this.search1, term, { replace: true })
.pressKey('enter')
}
async openNav() {
if (await Selector('button.p-navigation-show').visible) {
await t.click(Selector('button.p-navigation-show'));
} else if (await Selector('div.p-navigation-expand').exists) {
await t.click(Selector('div.p-navigation-expand i'));
}
}
2019-07-02 18:16:11 +02:00
2020-06-01 17:04:47 +02:00
async selectFromUID(uid) {
await t
.hover(Selector('div').withAttribute('data-uid', uid))
.click(Selector('.t-select.t-off'));
}
2020-06-01 17:04:47 +02: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 18:16:11 +02:00
await t
.hover(Selector('div[class="v-image__image v-image__image--cover"]', {timeout:4000}).nth(nPhoto))
.click(Selector('.t-select.t-off'));
2019-07-02 18:16:11 +02:00
}
async unselectPhoto(nPhoto) {
await t
.hover(Selector('div[class="v-image__image v-image__image--cover"]', {timeout:4000}).nth(nPhoto))
.click(Selector('.t-select.t-on'));
2019-07-02 18:16:11 +02:00
}
async likePhoto(uid) {
2019-07-02 18:16:11 +02:00
await t
.click(Selector('.t-like.t-off').withAttribute('data-uid', uid));
2019-07-02 18:16:11 +02:00
}
2019-11-21 18:56:11 +01:00
async dislikePhoto(uid) {
await t
.click(Selector('.t-like.t-on').withAttribute('data-uid', uid));
}
2020-06-01 17:04:47 +02:00
async archiveSelected() {
await t
.click(Selector('button.p-photo-clipboard-menu'))
.click(Selector('button.p-photo-clipboard-archive'))
.click(Selector('button.p-photo-dialog-confirm'));
}
2020-06-01 17:04:47 +02:00
async restoreSelected() {
await t
.click(Selector('button.p-photo-clipboard-menu'))
.click(Selector('button.p-photo-clipboard-restore'));
}
2020-06-01 17:04:47 +02:00
async editSelected() {
if (await Selector('button.p-photo-clipboard-edit').exists) {
await t.click(Selector('button.p-photo-clipboard-edit'));
} else if (await Selector('button.p-photo-clipboard-menu').exists) {
await t
.click(Selector('button.p-photo-clipboard-menu'))
.click(Selector('button.p-photo-clipboard-edit'));
}
}
2020-06-01 17:04:47 +02:00
async deleteSelectedAlbum() {
await t
.click(Selector('button.p-album-clipboard-menu'))
.click(Selector('button.p-album-clipboard-delete'))
2020-06-03 08:42:56 +02:00
.click(Selector('button.p-photo-dialog-confirm'));
2020-06-01 17:04:47 +02:00
}
async removeSelected() {
await t
.click(Selector('button.p-photo-clipboard-menu'))
.click(Selector('button.p-photo-clipboard-delete'));
}
async addSelectedToAlbum(name) {
await t
.click(Selector('button.p-photo-clipboard-menu'))
.click(Selector('button.p-photo-clipboard-album'))
.typeText(Selector('.input-album input'), name, { replace: true })
.click(Selector('div[role="listitem"]').withText(name))
.click(Selector('button.p-photo-dialog-confirm'));
}
2019-11-21 18:56:11 +01:00
async login(password) {
await t
.typeText(Selector('input[type="password"]'), password)
.pressKey('enter');
}
async logout() {
await t
.click(Selector('div.p-navigation-logout'));
}
}