Skip to content

Commit

Permalink
Move upload logic outside of beforeEach()
Browse files Browse the repository at this point in the history
  • Loading branch information
artemiomorales committed Jul 7, 2023
1 parent aaf6f8f commit ac2b74d
Showing 1 changed file with 172 additions and 11 deletions.
183 changes: 172 additions & 11 deletions test/e2e/specs/editor/blocks/image.spec.js
Expand Up @@ -774,7 +774,11 @@ 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]'
);
Expand All @@ -792,12 +796,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 +829,34 @@ 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 )
);

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,33 @@ 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 )
);

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 +1050,26 @@ 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' ),
'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 )
);

await editor.openDocumentSettingsSidebar();

await page.getByRole( 'button', { name: 'Advanced' } ).click();
const behaviorSelect = page.getByRole( 'combobox', {
name: 'Behaviors',
Expand Down Expand Up @@ -1040,7 +1104,26 @@ 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' ),
'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 )
);

await editor.openDocumentSettingsSidebar();

await page.getByRole( 'button', { name: 'Advanced' } ).click();
const behaviorSelect = page.getByRole( 'combobox', {
name: 'Behaviors',
Expand All @@ -1058,8 +1141,28 @@ 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' ),
'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 )
);

await editor.openDocumentSettingsSidebar();

await page.getByRole( 'button', { name: 'Advanced' } ).click();
const behaviorSelect = page.getByRole( 'combobox', {
name: 'Behaviors',
Expand All @@ -1073,7 +1176,27 @@ 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' ),
'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 )
);

await editor.openDocumentSettingsSidebar();

await page.getByRole( 'button', { name: 'Advanced' } ).click();
const behaviorSelect = page.getByRole( 'combobox', {
name: 'Behaviors',
Expand All @@ -1087,7 +1210,27 @@ 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' ),
'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 )
);

await editor.openDocumentSettingsSidebar();

await page.getByRole( 'button', { name: 'Advanced' } ).click();
const behaviorSelect = page.getByRole( 'combobox', {
name: 'Behaviors',
Expand All @@ -1106,7 +1249,25 @@ 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' ),
'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 )
);

await editor.openDocumentSettingsSidebar();

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

0 comments on commit ac2b74d

Please sign in to comment.