|
| 1 | +/** |
| 2 | + * External dependencies |
| 3 | + */ |
| 4 | +import { randomUUID } from 'node:crypto'; |
| 5 | + |
1 | 6 | /** |
2 | 7 | * WordPress dependencies |
3 | 8 | */ |
@@ -146,4 +151,59 @@ test.describe( 'Theme management', () => { |
146 | 151 | themes.find( ( theme ) => theme.status === 'active' ).stylesheet |
147 | 152 | ).toBe( previousTheme ); |
148 | 153 | } ); |
| 154 | + |
| 155 | + test( 'searches for an installed theme', async ( { admin, page } ) => { |
| 156 | + await admin.visitAdminPage( 'themes.php' ); |
| 157 | + const search = page.getByRole( 'searchbox', { |
| 158 | + name: 'Search installed themes', |
| 159 | + exact: true, |
| 160 | + } ); |
| 161 | + await expect( search ).toBeVisible(); |
| 162 | + const themeDetailsButtons = page.getByRole( 'button', { |
| 163 | + name: /View Theme Details for /, |
| 164 | + } ); |
| 165 | + // Confirm search starts from a broader results set before filtering. |
| 166 | + await expect |
| 167 | + .poll( async () => themeDetailsButtons.count() ) |
| 168 | + .toBeGreaterThan( 1 ); |
| 169 | + await search.fill( themeName ); |
| 170 | + |
| 171 | + // Wait for the debounced filter, then require a single matching result. |
| 172 | + await expect( themeDetailsButtons ).toHaveCount( 1 ); |
| 173 | + await expect( |
| 174 | + page.getByRole( 'button', { |
| 175 | + name: `View Theme Details for ${ themeName }`, |
| 176 | + exact: true, |
| 177 | + } ) |
| 178 | + ).toBeVisible(); |
| 179 | + } ); |
| 180 | + |
| 181 | + test( 'shows an empty result when searching for a missing theme', async ( { |
| 182 | + admin, |
| 183 | + page, |
| 184 | + } ) => { |
| 185 | + // Fixture theme from beforeEach keeps the library non-empty so ignoring |
| 186 | + // search cannot vacuously pass. |
| 187 | + const missing = `e2e-missing-theme-${ randomUUID().slice( 0, 8 ) }`; |
| 188 | + await admin.visitAdminPage( 'themes.php' ); |
| 189 | + const search = page.getByRole( 'searchbox', { |
| 190 | + name: 'Search installed themes', |
| 191 | + exact: true, |
| 192 | + } ); |
| 193 | + await expect( search ).toBeVisible(); |
| 194 | + await search.fill( missing ); |
| 195 | + |
| 196 | + // Scope to the empty-state paragraph; the same copy is also spoken via |
| 197 | + // wp.a11y.speak() into a live region. |
| 198 | + const emptyState = page.locator( 'p.no-themes' ); |
| 199 | + await expect( emptyState ).toBeVisible(); |
| 200 | + await expect( emptyState ).toHaveText( |
| 201 | + 'No themes found. Try a different search.' |
| 202 | + ); |
| 203 | + await expect( |
| 204 | + page.getByRole( 'button', { |
| 205 | + name: /View Theme Details for /, |
| 206 | + } ) |
| 207 | + ).toHaveCount( 0 ); |
| 208 | + } ); |
149 | 209 | } ); |
0 commit comments