photoprism/frontend/tests/acceptance/photos-upload-delete.js

267 lines
9.9 KiB
JavaScript
Raw Normal View History

2021-01-29 10:36:26 +01:00
import { Selector } from "testcafe";
import testcafeconfig from "./testcafeconfig";
import fs from "fs";
2022-04-15 15:46:25 +02:00
import Menu from "../page-model/menu";
import Toolbar from "../page-model/toolbar";
import ContextMenu from "../page-model/context-menu";
import Photo from "../page-model/photo";
import Page from "../page-model/page";
import PhotoEdit from "../page-model/photo-edit";
import Originals from "../page-model/originals";
import Album from "../page-model/album";
import Library from "../page-model/library";
2021-01-29 10:36:26 +01:00
fixture`Test photos upload and delete`.page`${testcafeconfig.url}`;
2022-04-15 15:46:25 +02:00
const menu = new Menu();
const album = new Album();
const toolbar = new Toolbar();
const contextmenu = new ContextMenu();
const photo = new Photo();
2021-01-29 10:36:26 +01:00
const page = new Page();
2022-04-15 15:46:25 +02:00
const photoedit = new PhotoEdit();
const originals = new Originals();
const library = new Library();
2021-01-29 10:36:26 +01:00
2022-04-15 15:46:25 +02:00
test.meta("testID", "photos-upload-delete-001").meta({ type: "smoke" })(
"Upload + Delete jpg/json",
async (t) => {
await t.expect(fs.existsSync("../storage/acceptance/originals/2020/10")).notOk();
await toolbar.search("digikam");
const PhotoCount = await photo.getPhotoCount("all");
await t.expect(PhotoCount).eql(0);
await toolbar.triggerToolbarAction("upload");
await t
.setFilesToUpload(Selector(".input-upload"), [
"./upload-files/digikam.jpg",
"./upload-files/digikam.json",
])
.wait(15000);
const PhotoCountAfterUpload = await photo.getPhotoCount("all");
await t.expect(PhotoCountAfterUpload).eql(1);
const UploadedPhoto = await photo.getNthPhotoUid("all", 0);
await t.navigateTo("/library/files/2020/10");
const FileCount = await originals.getFileCount();
await t.expect(FileCount).eql(2);
await menu.openPage("browse");
await toolbar.search("digikam");
await photo.triggerHoverAction("uid", UploadedPhoto, "select");
await contextmenu.triggerContextMenuAction("edit", "");
await t.click(photoedit.filesTab);
await t
.expect(Selector("div.caption").withText(".json").visible)
.ok()
.expect(Selector("div.caption").withText(".jpg").visible)
.ok();
await t.click(photoedit.dialogClose);
if (t.browser.platform !== "mobile") {
await t.expect(fs.existsSync("../storage/acceptance/originals/2020/10")).ok();
const originalsLength = fs.readdirSync("../storage/acceptance/originals/2020/10").length;
await t.expect(originalsLength).eql(2);
}
await contextmenu.triggerContextMenuAction("archive", "");
await menu.openPage("archive");
await photo.triggerHoverAction("uid", UploadedPhoto, "select");
await contextmenu.triggerContextMenuAction("delete", "");
await menu.openPage("browse");
await toolbar.search("digikam");
await photo.checkPhotoVisibility(UploadedPhoto, false);
await t.navigateTo("/library/files/2020/10");
const FileCountAfterDelete = await originals.getFileCount();
await t.expect(FileCountAfterDelete).eql(0);
if (t.browser.platform !== "mobile") {
const originalsLengthAfterDelete = fs.readdirSync(
"../storage/acceptance/originals/2020/10"
).length;
await t.expect(originalsLengthAfterDelete).eql(0);
}
}
);
2021-01-29 10:36:26 +01:00
test.meta("testID", "photos-upload-delete-002")("Upload + Delete video", async (t) => {
await t.expect(fs.existsSync("../storage/acceptance/originals/2020/06")).notOk();
2022-04-15 15:46:25 +02:00
await toolbar.search("korn");
const PhotoCount = await photo.getPhotoCount("all");
await t.expect(PhotoCount).eql(0);
await toolbar.triggerToolbarAction("upload");
await t.setFilesToUpload(Selector(".input-upload"), ["./upload-files/korn.mp4"]).wait(15000);
const PhotoCountAfterUpload = await photo.getPhotoCount("all");
await t.expect(PhotoCountAfterUpload).eql(1);
2022-04-15 15:46:25 +02:00
const UploadedPhoto = await photo.getNthPhotoUid("all", 0);
await t.navigateTo("/library/files/2020/06");
2022-04-15 15:46:25 +02:00
const FileCount = await originals.getFileCount();
await t.expect(FileCount).eql(1);
2022-04-15 15:46:25 +02:00
await menu.openPage("browse");
await toolbar.search("korn");
await photo.triggerHoverAction("uid", UploadedPhoto, "select");
await contextmenu.triggerContextMenuAction("edit", "");
await t.click(photoedit.filesTab);
await t
.expect(Selector("div.caption").withText(".mp4").visible)
.ok()
.expect(Selector("div.caption").withText(".jpg").visible)
2022-04-15 15:46:25 +02:00
.ok();
await t.click(photoedit.dialogClose);
if (t.browser.platform !== "mobile") {
await t.expect(fs.existsSync("../storage/acceptance/originals/2020/06")).ok();
const originalsLength = fs.readdirSync("../storage/acceptance/originals/2020/06").length;
await t.expect(originalsLength).eql(1);
const sidecarLength = fs.readdirSync("../storage/acceptance/originals/2020/06").length;
await t.expect(sidecarLength).eql(1);
}
await contextmenu.triggerContextMenuAction("archive", "");
await menu.openPage("archive");
await photo.triggerHoverAction("uid", UploadedPhoto, "select");
await contextmenu.triggerContextMenuAction("delete", "");
await menu.openPage("browse");
await toolbar.search("korn");
await photo.checkPhotoVisibility(UploadedPhoto, false);
await t.navigateTo("/library/files/2020/06");
const FileCountAfterDelete = await originals.getFileCount();
await t.expect(FileCountAfterDelete).eql(0);
2022-04-15 15:46:25 +02:00
if (t.browser.platform !== "mobile") {
const originalsLengthAfterDelete = fs.readdirSync(
"../storage/acceptance/originals/2020/06"
).length;
await t.expect(originalsLengthAfterDelete).eql(0);
const sidecarLengthAfterDelete = fs.readdirSync(
"../storage/acceptance/originals/2020/06"
).length;
await t.expect(sidecarLengthAfterDelete).eql(0);
}
});
test.meta("testID", "photos-upload-delete-003")("Upload to existing Album + Delete", async (t) => {
2022-04-15 15:46:25 +02:00
await menu.openPage("albums");
await toolbar.search("Christmas");
const AlbumUid = await album.getNthAlbumUid("all", 0);
await album.openAlbumWithUid(AlbumUid);
const PhotoCount = await photo.getPhotoCount("all");
await toolbar.triggerToolbarAction("upload");
2021-01-29 10:36:26 +01:00
await t
.click(Selector(".input-albums"))
2022-04-15 15:46:25 +02:00
.click(page.selectOption.withText("Christmas"))
2021-01-29 10:36:26 +01:00
.setFilesToUpload(Selector(".input-upload"), ["./upload-files/ladybug.jpg"])
.wait(15000);
2022-04-15 15:46:25 +02:00
const PhotoCountAfterUpload = await photo.getPhotoCount("all");
2021-01-29 10:36:26 +01:00
await t.expect(PhotoCountAfterUpload).eql(PhotoCount + 1);
2022-04-15 15:46:25 +02:00
await menu.openPage("browse");
await toolbar.search("ladybug");
const UploadedPhotoUid = await photo.getNthPhotoUid("all", 0);
await photo.triggerHoverAction("uid", UploadedPhotoUid, "select");
await contextmenu.triggerContextMenuAction("archive", "");
await menu.openPage("archive");
await photo.triggerHoverAction("uid", UploadedPhotoUid, "select");
await contextmenu.triggerContextMenuAction("delete", "");
await menu.openPage("browse");
await toolbar.search("ladybug");
await photo.checkPhotoVisibility(UploadedPhotoUid, false);
await menu.openPage("albums");
await album.openAlbumWithUid(AlbumUid);
await photo.checkPhotoVisibility(UploadedPhotoUid, false);
const PhotoCountAfterDelete = await photo.getPhotoCount("all");
2021-01-29 10:36:26 +01:00
await t.expect(PhotoCountAfterDelete).eql(PhotoCount);
});
test.meta("testID", "photos-upload-delete-004")("Upload jpg to new Album + Delete", async (t) => {
2022-04-15 15:46:25 +02:00
await menu.openPage("albums");
const AlbumCount = await album.getAlbumCount("all");
await toolbar.triggerToolbarAction("upload");
2021-01-29 10:36:26 +01:00
await t
.click(Selector(".input-albums"))
.typeText(Selector(".input-albums input"), "NewCreatedAlbum")
.pressKey("enter")
.setFilesToUpload(Selector(".input-upload"), ["./upload-files/digikam.jpg"])
.wait(15000);
if (t.browser.platform === "mobile") {
await t.eval(() => location.reload());
} else {
2022-04-15 15:46:25 +02:00
await toolbar.triggerToolbarAction("reload");
2021-01-29 10:36:26 +01:00
}
2022-04-15 15:46:25 +02:00
const AlbumCountAfterUpload = await album.getAlbumCount("all");
2021-01-29 10:36:26 +01:00
await t.expect(AlbumCountAfterUpload).eql(AlbumCount + 1);
2022-04-15 15:46:25 +02:00
await toolbar.search("NewCreatedAlbum");
await album.openNthAlbum(0);
const PhotoCount = await photo.getPhotoCount("all");
2021-01-29 10:36:26 +01:00
await t.expect(PhotoCount).eql(1);
2022-04-15 15:46:25 +02:00
await menu.openPage("browse");
await toolbar.search("digikam");
const UploadedPhotoUid = await photo.getNthPhotoUid("all", 0);
await photo.triggerHoverAction("uid", UploadedPhotoUid, "select");
await contextmenu.triggerContextMenuAction("archive", "");
await menu.openPage("archive");
await photo.triggerHoverAction("uid", UploadedPhotoUid, "select");
await contextmenu.triggerContextMenuAction("delete", "");
await menu.openPage("browse");
await toolbar.search("digikam");
await photo.checkPhotoVisibility(UploadedPhotoUid, false);
await menu.openPage("albums");
await toolbar.search("NewCreatedAlbum");
await album.openNthAlbum(0);
await photo.checkPhotoVisibility(UploadedPhotoUid, false);
const PhotoCountAfterDelete = await photo.getPhotoCount("all");
2021-01-29 10:36:26 +01:00
await t.expect(PhotoCountAfterDelete).eql(0);
2022-04-15 15:46:25 +02:00
await menu.openPage("albums");
await toolbar.search("NewCreatedAlbum");
await album.triggerHoverAction("nth", 0, "select");
await contextmenu.checkContextMenuCount("1");
await contextmenu.triggerContextMenuAction("delete", "");
2021-01-29 10:36:26 +01:00
});
2022-04-15 15:46:25 +02:00
test.meta("testID", "photos-upload-delete-005").meta({ type: "smoke" })(
"Try uploading nsfw file",
async (t) => {
await toolbar.triggerToolbarAction("upload");
await t
.setFilesToUpload(Selector(".input-upload"), ["./upload-files/hentai_2.jpg"])
.wait(15000);
await menu.openPage("library");
await t.click(library.logsTab);
await t.expect(Selector("p").withText("hentai_2.jpg might be offensive").visible).ok();
}
);
test.meta("testID", "photos-upload-delete-006").meta({ type: "smoke" })(
"Try uploading txt file",
async (t) => {
await toolbar.triggerToolbarAction("upload");
await t.setFilesToUpload(Selector(".input-upload"), ["./upload-files/foo.txt"]).wait(15000);
await menu.openPage("library");
await t.click(library.logsTab);
await t.expect(Selector("p").withText(" foo.txt is not a jpeg file").visible).ok();
}
);