Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Image block: Fix flaky tests #52442

Merged
merged 2 commits into from
Jul 27, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
182 changes: 169 additions & 13 deletions test/e2e/specs/editor/blocks/image.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -774,15 +774,18 @@ test.describe( 'Image - interactivity', () => {
test.describe( 'tests using uploaded image', () => {
let filename = null;

test.beforeEach( async ( { editor, imageBlockUtils } ) => {
test( 'should toggle "lightbox" in saved attributes', async ( {
editor,
page,
imageBlockUtils,
} ) => {
const imageBlock = editor.canvas.locator(
'role=document[name="Block: Image"i]'
);
await expect( imageBlock ).toBeVisible();

filename = await imageBlockUtils.upload(
imageBlock.locator( 'data-testid=form-file-upload-input' ),
'3200x2400_e2e_test_image_responsive_lightbox.jpeg'
imageBlock.locator( 'data-testid=form-file-upload-input' )
);
const image = imageBlock.locator( 'role=img' );
await expect( image ).toBeVisible();
Expand All @@ -792,12 +795,7 @@ test.describe( 'Image - interactivity', () => {
);

await editor.openDocumentSettingsSidebar();
} );

test( 'should toggle "lightbox" in saved attributes', async ( {
editor,
page,
} ) => {
await page.getByRole( 'button', { name: 'Advanced' } ).click();
await page
.getByRole( 'combobox', { name: 'Behaviors' } )
Expand Down Expand Up @@ -830,14 +828,35 @@ test.describe( 'Image - interactivity', () => {
} );

test.describe( 'should open and close the image in a lightbox when using a mouse and dynamically load src', () => {
test.beforeEach( async ( { page } ) => {
test( 'zoom animation', async ( {
editor,
page,
imageBlockUtils,
} ) => {
const imageBlock = editor.canvas.locator(
'role=document[name="Block: Image"i]'
);
await expect( imageBlock ).toBeVisible();

filename = await imageBlockUtils.upload(
imageBlock.locator( 'data-testid=form-file-upload-input' ),
'3200x2400_e2e_test_image_responsive_lightbox.jpeg'
);
const image = imageBlock.locator( 'role=img' );
await expect( image ).toBeVisible();
await expect( image ).toHaveAttribute(
'src',
new RegExp( filename ),
{ timeout: 10_000 }
);

await editor.openDocumentSettingsSidebar();

await page.getByRole( 'button', { name: 'Advanced' } ).click();
await page
.getByRole( 'combobox', { name: 'Behaviors' } )
.selectOption( 'lightbox' );
} );

test( 'zoom animation', async ( { editor, page } ) => {
await page
.getByRole( 'combobox', { name: 'Animation' } )
.selectOption( 'zoom' );
Expand Down Expand Up @@ -933,7 +952,34 @@ test.describe( 'Image - interactivity', () => {
await expect( lightbox ).toBeHidden();
} );

test( 'fade animation', async ( { editor, page } ) => {
test( 'fade animation', async ( {
editor,
page,
imageBlockUtils,
} ) => {
const imageBlock = editor.canvas.locator(
'role=document[name="Block: Image"i]'
);
await expect( imageBlock ).toBeVisible();

filename = await imageBlockUtils.upload(
imageBlock.locator( 'data-testid=form-file-upload-input' ),
'3200x2400_e2e_test_image_responsive_lightbox.jpeg'
);
const image = imageBlock.locator( 'role=img' );
await expect( image ).toBeVisible();
await expect( image ).toHaveAttribute(
'src',
new RegExp( filename ),
{ timeout: 10_000 }
);

await editor.openDocumentSettingsSidebar();

await page.getByRole( 'button', { name: 'Advanced' } ).click();
await page
.getByRole( 'combobox', { name: 'Behaviors' } )
.selectOption( 'lightbox' );
await page
.getByRole( 'combobox', { name: 'Animation' } )
.selectOption( 'fade' );
Expand Down Expand Up @@ -1005,7 +1051,25 @@ test.describe( 'Image - interactivity', () => {
test( 'lightbox should be overriden when link is configured for image', async ( {
editor,
page,
imageBlockUtils,
} ) => {
const imageBlock = editor.canvas.locator(
'role=document[name="Block: Image"i]'
);
await expect( imageBlock ).toBeVisible();

filename = await imageBlockUtils.upload(
imageBlock.locator( 'data-testid=form-file-upload-input' )
);
const image = imageBlock.locator( 'role=img' );
await expect( image ).toBeVisible();
await expect( image ).toHaveAttribute(
'src',
new RegExp( filename )
);

await editor.openDocumentSettingsSidebar();

await page.getByRole( 'button', { name: 'Advanced' } ).click();
const behaviorSelect = page.getByRole( 'combobox', {
name: 'Behaviors',
Expand Down Expand Up @@ -1040,7 +1104,25 @@ test.describe( 'Image - interactivity', () => {
test( 'markup should not appear if Lightbox is disabled', async ( {
editor,
page,
imageBlockUtils,
} ) => {
const imageBlock = editor.canvas.locator(
'role=document[name="Block: Image"i]'
);
await expect( imageBlock ).toBeVisible();

filename = await imageBlockUtils.upload(
imageBlock.locator( 'data-testid=form-file-upload-input' )
);
const image = imageBlock.locator( 'role=img' );
await expect( image ).toBeVisible();
await expect( image ).toHaveAttribute(
'src',
new RegExp( filename )
);

await editor.openDocumentSettingsSidebar();

await page.getByRole( 'button', { name: 'Advanced' } ).click();
const behaviorSelect = page.getByRole( 'combobox', {
name: 'Behaviors',
Expand All @@ -1058,8 +1140,27 @@ test.describe( 'Image - interactivity', () => {

test.describe( 'Animation Select visibility', () => {
test( 'Animation selector should appear if Behavior is Lightbox', async ( {
editor,
page,
imageBlockUtils,
} ) => {
const imageBlock = editor.canvas.locator(
'role=document[name="Block: Image"i]'
);
await expect( imageBlock ).toBeVisible();

filename = await imageBlockUtils.upload(
imageBlock.locator( 'data-testid=form-file-upload-input' )
);
const image = imageBlock.locator( 'role=img' );
await expect( image ).toBeVisible();
await expect( image ).toHaveAttribute(
'src',
new RegExp( filename )
);

await editor.openDocumentSettingsSidebar();

await page.getByRole( 'button', { name: 'Advanced' } ).click();
const behaviorSelect = page.getByRole( 'combobox', {
name: 'Behaviors',
Expand All @@ -1073,7 +1174,26 @@ test.describe( 'Image - interactivity', () => {
} );
test( 'Animation selector should NOT appear if Behavior is None', async ( {
page,
editor,
imageBlockUtils,
} ) => {
const imageBlock = editor.canvas.locator(
'role=document[name="Block: Image"i]'
);
await expect( imageBlock ).toBeVisible();

filename = await imageBlockUtils.upload(
imageBlock.locator( 'data-testid=form-file-upload-input' )
);
const image = imageBlock.locator( 'role=img' );
await expect( image ).toBeVisible();
await expect( image ).toHaveAttribute(
'src',
new RegExp( filename )
);

await editor.openDocumentSettingsSidebar();

await page.getByRole( 'button', { name: 'Advanced' } ).click();
const behaviorSelect = page.getByRole( 'combobox', {
name: 'Behaviors',
Expand All @@ -1087,7 +1207,26 @@ test.describe( 'Image - interactivity', () => {
} );
test( 'Animation selector should NOT appear if Behavior is Default', async ( {
page,
editor,
imageBlockUtils,
} ) => {
const imageBlock = editor.canvas.locator(
'role=document[name="Block: Image"i]'
);
await expect( imageBlock ).toBeVisible();

filename = await imageBlockUtils.upload(
imageBlock.locator( 'data-testid=form-file-upload-input' )
);
const image = imageBlock.locator( 'role=img' );
await expect( image ).toBeVisible();
await expect( image ).toHaveAttribute(
'src',
new RegExp( filename )
);

await editor.openDocumentSettingsSidebar();

await page.getByRole( 'button', { name: 'Advanced' } ).click();
const behaviorSelect = page.getByRole( 'combobox', {
name: 'Behaviors',
Expand All @@ -1106,7 +1245,24 @@ test.describe( 'Image - interactivity', () => {
let lightbox;
let closeButton;

test.beforeEach( async ( { page, editor } ) => {
test.beforeEach( async ( { page, editor, imageBlockUtils } ) => {
const imageBlock = editor.canvas.locator(
'role=document[name="Block: Image"i]'
);
await expect( imageBlock ).toBeVisible();

filename = await imageBlockUtils.upload(
imageBlock.locator( 'data-testid=form-file-upload-input' )
);
const image = imageBlock.locator( 'role=img' );
await expect( image ).toBeVisible();
await expect( image ).toHaveAttribute(
'src',
new RegExp( filename )
);

await editor.openDocumentSettingsSidebar();

await page.getByRole( 'button', { name: 'Advanced' } ).click();
await page
.getByRole( 'combobox', { name: 'Behaviors' } )
Expand Down