2021-11-27 03:04:28 +08:00
|
|
|
const { expect } = require('@playwright/test');
|
2021-11-26 02:23:58 +08:00
|
|
|
const path = require('path');
|
|
|
|
const e = require('../core/elements');
|
2023-07-20 04:45:30 +08:00
|
|
|
const { UPLOAD_PDF_WAIT_TIME, ELEMENT_WAIT_EXTRA_LONG_TIME, ELEMENT_WAIT_LONGER_TIME } = require('../core/constants');
|
2021-11-26 02:23:58 +08:00
|
|
|
|
2021-11-27 03:04:28 +08:00
|
|
|
async function checkSvgIndex(test, element) {
|
2022-07-02 04:55:32 +08:00
|
|
|
const check = await test.page.evaluate(([el, slideImg]) => {
|
|
|
|
return document.querySelector(slideImg).outerHTML.indexOf(el) !== -1;
|
|
|
|
}, [element, e.currentSlideImg]);
|
2021-11-27 03:04:28 +08:00
|
|
|
await expect(check).toBeTruthy();
|
|
|
|
}
|
|
|
|
|
2022-07-02 04:55:32 +08:00
|
|
|
async function getSlideOuterHtml(testPage) {
|
|
|
|
return testPage.page.evaluate(([slideImg]) => {
|
|
|
|
return document.querySelector(slideImg).outerHTML;
|
|
|
|
}, [e.currentSlideImg]);
|
2021-11-27 03:04:28 +08:00
|
|
|
}
|
|
|
|
|
2022-12-01 22:15:55 +08:00
|
|
|
async function getCurrentPresentationHeight(locator) {
|
|
|
|
return locator.evaluate((e) => {
|
|
|
|
return window.getComputedStyle(e).getPropertyValue("height");
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2023-04-06 05:02:40 +08:00
|
|
|
async function uploadSinglePresentation(test, fileName, uploadTimeout = UPLOAD_PDF_WAIT_TIME) {
|
|
|
|
const firstSlideSrc = await test.page.evaluate(selector => document.querySelector(selector).src, [e.currentSlideImg]);
|
2021-11-26 02:23:58 +08:00
|
|
|
await test.waitAndClick(e.actions);
|
2022-01-20 21:03:18 +08:00
|
|
|
await test.waitAndClick(e.managePresentations);
|
2021-11-26 02:23:58 +08:00
|
|
|
await test.waitForSelector(e.fileUpload);
|
|
|
|
|
2022-04-08 02:34:25 +08:00
|
|
|
await test.page.setInputFiles(e.fileUpload, path.join(__dirname, `../core/media/${fileName}`));
|
2022-01-20 21:03:18 +08:00
|
|
|
await test.hasText('body', e.statingUploadPresentationToast);
|
2021-11-26 02:23:58 +08:00
|
|
|
|
2022-01-20 21:03:18 +08:00
|
|
|
await test.waitAndClick(e.confirmManagePresentation);
|
2023-08-23 04:25:50 +08:00
|
|
|
await test.hasElement(e.presentationUploadProgressToast, ELEMENT_WAIT_LONGER_TIME);
|
2023-04-06 05:02:40 +08:00
|
|
|
await test.page.waitForFunction(([selector, firstSlideSrc]) => {
|
|
|
|
const currentSrc = document.querySelector(selector).src;
|
|
|
|
return currentSrc != firstSlideSrc;
|
|
|
|
}, [e.currentSlideImg, firstSlideSrc], {
|
|
|
|
timeout: uploadTimeout,
|
|
|
|
});
|
2021-11-26 02:23:58 +08:00
|
|
|
}
|
|
|
|
|
2023-07-20 04:45:30 +08:00
|
|
|
async function uploadMultiplePresentations(test, fileNames, uploadTimeout = ELEMENT_WAIT_EXTRA_LONG_TIME) {
|
2022-06-21 07:02:10 +08:00
|
|
|
await test.waitAndClick(e.actions);
|
|
|
|
await test.waitAndClick(e.managePresentations);
|
|
|
|
await test.waitForSelector(e.fileUpload);
|
|
|
|
|
2023-04-06 05:02:40 +08:00
|
|
|
await test.page.setInputFiles(e.fileUpload, fileNames.map((fileName) => path.join(__dirname, `../core/media/${fileName}`)));
|
2022-06-21 07:02:10 +08:00
|
|
|
await test.hasText('body', e.statingUploadPresentationToast);
|
|
|
|
|
|
|
|
await test.waitAndClick(e.confirmManagePresentation);
|
2022-06-30 23:01:00 +08:00
|
|
|
await test.hasText(e.presentationStatusInfo, [e.convertingPresentationFileToast], uploadTimeout);
|
2022-06-21 07:02:10 +08:00
|
|
|
await test.hasText(e.smallToastMsg, e.presentationUploadedToast, uploadTimeout);
|
|
|
|
}
|
|
|
|
|
2021-11-27 03:04:28 +08:00
|
|
|
exports.checkSvgIndex = checkSvgIndex;
|
2022-07-02 04:55:32 +08:00
|
|
|
exports.getSlideOuterHtml = getSlideOuterHtml;
|
2022-06-21 07:02:10 +08:00
|
|
|
exports.uploadSinglePresentation = uploadSinglePresentation;
|
|
|
|
exports.uploadMultiplePresentations = uploadMultiplePresentations;
|
2022-12-01 22:15:55 +08:00
|
|
|
exports.getCurrentPresentationHeight = getCurrentPresentationHeight;
|