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 ) {
2024-01-20 00:42:01 +08:00
const firstSlideSrc = await test . page . evaluate ( selector => document . querySelector ( selector )
2024-04-04 02:56:38 +08:00
? . style
2024-01-20 00:42:01 +08:00
. backgroundImage
. split ( '"' ) [ 1 ] ,
[ 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 ) ;
2024-07-31 06:49:02 +08:00
await test . hasElement ( e . presentationFileUpload , 'should display the presentation space for uploading a new file, when the manage presentations is opened' ) ;
2021-11-26 02:23:58 +08:00
2024-01-20 00:42:01 +08:00
await test . page . setInputFiles ( e . presentationFileUpload , path . join ( _ _dirname , ` ../core/media/ ${ fileName } ` ) ) ;
2024-07-31 06:49:02 +08:00
await test . hasText ( 'body' , e . statingUploadPresentationToast , 'should display the toast message uploading the presentation' ) ;
2021-11-26 02:23:58 +08:00
2022-01-20 21:03:18 +08:00
await test . waitAndClick ( e . confirmManagePresentation ) ;
2024-07-31 06:49:02 +08:00
await test . hasElement ( e . presentationUploadProgressToast , 'should display the toast presentation upload progress after confiming the presentation to be uploaded' , ELEMENT _WAIT _EXTRA _LONG _TIME ) ;
2023-04-06 05:02:40 +08:00
await test . page . waitForFunction ( ( [ selector , firstSlideSrc ] ) => {
2024-01-20 00:42:01 +08:00
const currentSrc = document . querySelector ( selector )
? . style ? . backgroundImage ? . split ( '"' ) [ 1 ] ;
2023-04-06 05:02:40 +08:00
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 ) ;
2024-07-31 06:49:02 +08:00
await test . hasElement ( e . presentationFileUpload , 'should display the modal for uploading a new presentation after opening the manage presentations' ) ;
2022-06-21 07:02:10 +08:00
2024-01-20 00:42:01 +08:00
await test . page . setInputFiles ( e . presentationFileUpload , fileNames . map ( ( fileName ) => path . join ( _ _dirname , ` ../core/media/ ${ fileName } ` ) ) ) ;
2024-07-31 06:49:02 +08:00
await test . hasText ( 'body' , e . statingUploadPresentationToast , 'should display the toast of a presentation to be uploaded after selecting the files to upload' ) ;
2022-06-21 07:02:10 +08:00
await test . waitAndClick ( e . confirmManagePresentation ) ;
2024-07-31 06:49:02 +08:00
await test . hasText ( e . presentationStatusInfo , [ e . convertingPresentationFileToast ] , 'should display the presentation status info after confimation to upload the new file' , uploadTimeout ) ;
await test . hasText ( e . smallToastMsg , e . presentationUploadedToast , 'should display the toast notification saying that the presentation is uploaded' , uploadTimeout ) ;
2022-06-21 07:02:10 +08:00
}
2024-01-20 00:42:01 +08:00
async function skipSlide ( page ) {
const selectSlideLocator = page . getLocator ( e . skipSlide ) ;
const currentSlideNumber = await selectSlideLocator . inputValue ( ) ;
await page . waitAndClick ( e . nextSlide ) ;
await expect ( selectSlideLocator ) . not . toHaveValue ( currentSlideNumber ) ;
}
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 ;
2024-01-20 00:42:01 +08:00
exports . skipSlide = skipSlide ;