|
| 1 | +/** |
| 2 | + * WordPress dependencies |
| 3 | + */ |
| 4 | +import { test, expect } from '@wordpress/e2e-test-utils-playwright'; |
| 5 | + |
| 6 | +test.describe( 'Query Monitor plugin', () => { |
| 7 | + async function deactivateQueryMonitor( requestUtils ) { |
| 8 | + await requestUtils.deactivatePlugin( 'query-monitor' ); |
| 9 | + const plugin = await requestUtils.rest( { |
| 10 | + path: 'wp/v2/plugins/query-monitor/query-monitor', |
| 11 | + } ); |
| 12 | + expect( plugin.status ).toBe( 'inactive' ); |
| 13 | + } |
| 14 | + |
| 15 | + test.beforeEach( async ( { requestUtils }) => { |
| 16 | + await deactivateQueryMonitor( requestUtils ); |
| 17 | + } ); |
| 18 | + |
| 19 | + test.afterEach( async ( { requestUtils }) => { |
| 20 | + await deactivateQueryMonitor( requestUtils ); |
| 21 | + } ); |
| 22 | + |
| 23 | + test( 'should activate', async ( { admin, page } ) => { |
| 24 | + // Activate the Query Monitor plugin on the plugins page. |
| 25 | + await admin.visitAdminPage( '/plugins.php' ); |
| 26 | + await page.getByLabel( 'Activate Query Monitor', { exact: true } ).click(); |
| 27 | + await page.getByText( 'Plugin activated.', { exact: true } ).waitFor(); |
| 28 | + |
| 29 | + // Click on the Query Monitor menu item in the WordPress admin bar. |
| 30 | + await page.locator('a[role="menuitem"][href="#qm-overview"][aria-expanded="false"]').click(); |
| 31 | + |
| 32 | + // Wait for the Query Monitor panel to open. |
| 33 | + await page.locator( '#query-monitor-main' ).waitFor(); |
| 34 | + await page.getByRole( 'heading', { name: 'Query Monitor', exact: true } ).waitFor(); |
| 35 | + |
| 36 | + // Click on the Database Queries tab. |
| 37 | + await page.getByRole( 'tab', { name: 'Database Queries' } ).click(); |
| 38 | + |
| 39 | + // Verify the first logged query. |
| 40 | + const sqlCell = page.locator( '.qm-row-sql' ).first(); |
| 41 | + await expect( sqlCell ).toContainText( 'SELECT option_name, option_value' ); |
| 42 | + |
| 43 | + // Check that the query is logged with SQLite information. |
| 44 | + await sqlCell.getByLabel( 'Toggle SQLite queries' ).click(); |
| 45 | + expect( page.locator('.qm-sqlite-query', { hasText: 'SELECT `option_name` , `option_value` FROM `wp_options`' }).first() ).toBeVisible(); |
| 46 | + } ); |
| 47 | +} ); |
0 commit comments