|
|
import { createTestFile } from '../../../media-helper'; |
|
|
import { BlockFlow, EditorContext, PublishedPostContext } from '.'; |
|
|
|
|
|
interface ConfigurationData { |
|
|
imagePaths: string[]; |
|
|
} |
|
|
|
|
|
const blockParentSelector = '[aria-label="Block: Slideshow"]'; |
|
|
const selectors = { |
|
|
fileInput: `${ blockParentSelector } input[type=file]`, |
|
|
uploadingIndicator: `${ blockParentSelector } .swiper-slide-active .components-spinner`, |
|
|
publishedImage: ( fileName: string ) => `.wp-block-jetpack-slideshow img[src*="${ fileName }"]`, |
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
export class SlideshowBlockFlow implements BlockFlow { |
|
|
private configurationData: ConfigurationData; |
|
|
private preparedImageFileNames: string[]; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
constructor( configurationData: ConfigurationData ) { |
|
|
this.configurationData = configurationData; |
|
|
this.preparedImageFileNames = []; |
|
|
} |
|
|
|
|
|
blockSidebarName = 'Slideshow'; |
|
|
blockEditorSelector = blockParentSelector; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
async configure( context: EditorContext ): Promise< void > { |
|
|
for ( const imagePath of this.configurationData.imagePaths ) { |
|
|
|
|
|
const testFile = await createTestFile( imagePath ); |
|
|
|
|
|
this.preparedImageFileNames.push( testFile.basename ); |
|
|
|
|
|
const editorCanvas = await context.editorPage.getEditorCanvas(); |
|
|
const fileInputLocator = editorCanvas.locator( selectors.fileInput ); |
|
|
await Promise.all( [ |
|
|
fileInputLocator.setInputFiles( testFile.fullpath ), |
|
|
context.page.waitForResponse( |
|
|
( response ) => response.url().includes( 'media?' ) && response.ok() |
|
|
), |
|
|
] ); |
|
|
const uploadingIndicatorLocator = editorCanvas.locator( selectors.uploadingIndicator ).last(); |
|
|
await uploadingIndicatorLocator.waitFor( { state: 'detached' } ); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
async validateAfterPublish( context: PublishedPostContext ): Promise< void > { |
|
|
for ( const imageFileName of this.preparedImageFileNames ) { |
|
|
const expectedImageLocator = context.page |
|
|
.locator( selectors.publishedImage( imageFileName ) ) |
|
|
|
|
|
.first(); |
|
|
|
|
|
|
|
|
await expectedImageLocator.waitFor( { state: 'attached' } ); |
|
|
} |
|
|
} |
|
|
} |
|
|
|