Skip to content

Playwright e2e test for filtering media by type #7946

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

Open
wants to merge 3 commits into
base: trunk
Choose a base branch
from
Open
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
Binary file added tests/e2e/assets/test-data.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added tests/e2e/assets/test-data1.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added tests/e2e/assets/test-mp3.mp3
Binary file not shown.
118 changes: 118 additions & 0 deletions tests/e2e/specs/media-library/filter-media-by-type.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,118 @@
/**
* WordPress dependencies
*/
const { test, expect } = require( '@wordpress/e2e-test-utils-playwright' );
import path from 'path';

test.describe( 'Filter wp-media-library by type test', () => {
test.beforeAll( async ( { requestUtils } ) => {

Check failure on line 8 in tests/e2e/specs/media-library/filter-media-by-type.spec.js

View workflow job for this annotation

GitHub Actions / Test with SCRIPT_DEBUG enabled / Run E2E tests

[chromium] › tests/e2e/specs/media-library/filter-media-by-type.spec.js:26:2 › Filter wp-media-library by type test › Should be able to filter the media based on media type in grid view

2) [chromium] › tests/e2e/specs/media-library/filter-media-by-type.spec.js:26:2 › Filter wp-media-library by type test › Should be able to filter the media based on media type in grid view "beforeAll" hook timeout of 100000ms exceeded. 6 | 7 | test.describe( 'Filter wp-media-library by type test', () => { > 8 | test.beforeAll( async ( { requestUtils } ) => { | ^ 9 | // delete all media 10 | await requestUtils.deleteAllMedia(); 11 | at /home/runner/work/wordpress-develop/wordpress-develop/tests/e2e/specs/media-library/filter-media-by-type.spec.js:8:7
// delete all media
await requestUtils.deleteAllMedia();

// upload files
const files = [
'tests/e2e/assets/test-data.jpg',
'tests/e2e/assets/test-data1.jpg',
'tests/e2e/assets/test-mp3.mp3'
];

for ( const file of files ) {
await requestUtils.uploadMedia(
path.resolve( process.cwd(), file )
);
}
} );

test( 'Should be able to filter the media based on media type in grid view', async ( {
page,
admin,
} ) => {
// navigate to url
await admin.visitAdminPage( '/upload.php?mode=grid' );

await expect(page.getByText('Showing 3 of 3 media items')).toBeVisible();

// validate media by video
await page
.getByRole( 'combobox', { name: 'Filter by type' } )
.selectOption( 'video' );

// validate media does not exist
await expect(page.getByText('No media items found.')).toBeVisible();

Check failure on line 41 in tests/e2e/specs/media-library/filter-media-by-type.spec.js

View workflow job for this annotation

GitHub Actions / Test with SCRIPT_DEBUG disabled / Run E2E tests

[chromium] › tests/e2e/specs/media-library/filter-media-by-type.spec.js:26:2 › Filter wp-media-library by type test › Should be able to filter the media based on media type in grid view

2) [chromium] › tests/e2e/specs/media-library/filter-media-by-type.spec.js:26:2 › Filter wp-media-library by type test › Should be able to filter the media based on media type in grid view Error: Timed out 5000ms waiting for expect(locator).toBeVisible() Locator: getByText('No media items found.') Expected: visible Received: hidden Call log: - expect.toBeVisible with timeout 5000ms - waiting for getByText('No media items found.') 9 × locator resolved to <p class="hidden no-media">No media items found.</p> - unexpected value "hidden" 39 | 40 | // validate media does not exist > 41 | await expect(page.getByText('No media items found.')).toBeVisible(); | ^ 42 | 43 | // validate media by audio 44 | await page at /home/runner/work/wordpress-develop/wordpress-develop/tests/e2e/specs/media-library/filter-media-by-type.spec.js:41:57

// validate media by audio
await page
.getByRole( 'combobox', { name: 'Filter by type' } )
.selectOption( 'audio' );

// validate media count
await expect(page.getByText('Showing 1 of 1 media items')).toBeVisible();

// open the file
await page.locator( '.thumbnail' ).click();

// validate file type
await expect(page.getByText('File type: audio/mpeg')).toBeVisible();

// close the modal
await page.getByRole('button', { name: ' Close dialog' }).click();

// validate filter by image
await page
.getByRole( 'combobox', { name: 'Filter by type' } )
.selectOption( 'image' );

// validate media count
await expect(page.getByText('Showing 2 of 2 media items')).toBeVisible();

// open the image
await page.getByLabel('test-data', { exact: true }).click();

// validate file type
await expect(page.getByText('File type: image/jpeg')).toBeVisible();

} );

test( 'Should be able to filter the media based on media type in list view', async ( {
page,
admin,
} ) => {
// navigate to url
await admin.visitAdminPage( '/upload.php?mode=list' );

await expect(page.getByText('3 items').first()).toBeVisible();

// validate media by audio
await page
.getByRole( 'combobox', { name: 'Filter by type' } )
.selectOption( 'Audio' );

await page.getByRole( 'button', { name: 'Filter' } ).click();

// validate media count
await expect(page.getByText('1 item').first()).toBeVisible();

await page.getByRole('link', { name: '“test-mp3” (Edit)'}).click();

// validate file type
await expect(page.getByText('File type: MP3 (audio/mpeg)')).toBeVisible();

await admin.visitAdminPage( '/upload.php?mode=list' );

// validate filter by image
await page
.getByRole( 'combobox', { name: 'Filter by type' } )
.selectOption( 'Images' );

await page.getByRole( 'button', { name: 'Filter' } ).click();

// validate media count
await expect(page.getByText('2 items').first()).toBeVisible();

// open the image
await page.locator( '.title a' ).first().click();

// validate file type
await expect(page.getByText('File type: JPG').first()).toBeVisible();
} );
} );
Loading