-
Notifications
You must be signed in to change notification settings - Fork 1
feat(filtering): support columnOverrides.read in findRow/findRows/countRows #398
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
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,76 @@ | ||
| import { test, expect, type Page } from '@playwright/test'; | ||
| import { useTable } from '../src/index'; | ||
|
|
||
| const TABLE = ` | ||
| <table id="t"> | ||
| <thead><tr><th>Name</th><th>Link</th><th>Status</th></tr></thead> | ||
| <tbody> | ||
| <tr><td>Alpha</td><td><a href="/d/alpha">link</a></td><td>Active</td></tr> | ||
| <tr><td>Beta</td><td><a href="/d/beta">link</a></td><td>Active</td></tr> | ||
| <tr><td>Gamma</td><td><a href="/d/gamma">link</a></td><td>Inactive</td></tr> | ||
| </tbody> | ||
| </table> | ||
| `; | ||
|
|
||
| test.describe('findRow/findRows with columnOverride filters (#385)', () => { | ||
| const makeTable = (page: Page) => | ||
| useTable(page.locator('#t'), { | ||
| columnOverrides: { | ||
| Link: { | ||
| read: async (cell) => { | ||
| const anchor = cell.locator('a'); | ||
| if (await anchor.count() > 0) { | ||
| return await anchor.getAttribute('href') ?? cell.innerText(); | ||
| } | ||
| return cell.innerText(); | ||
| }, | ||
| }, | ||
| }, | ||
| }); | ||
|
|
||
| test('findRow filters on override-produced value', async ({ page }) => { | ||
| await page.setContent(TABLE); | ||
| const table = await makeTable(page).init(); | ||
|
|
||
| const row = await table.findRow({ Link: '/d/beta' }, { exact: true }); | ||
| const data = await row.toJSON() as Record<string, string>; | ||
| expect(data.Name).toBe('Beta'); | ||
| }); | ||
|
|
||
| test('findRows filters on override-produced value', async ({ page }) => { | ||
| await page.setContent(TABLE); | ||
| const table = await makeTable(page).init(); | ||
|
|
||
| const rows = await table.findRows({ Link: '/d/beta' }, { exact: true }); | ||
| expect(rows.length).toBe(1); | ||
| const data = await rows[0].toJSON() as Record<string, string>; | ||
| expect(data.Name).toBe('Beta'); | ||
| }); | ||
|
rickcedwhat marked this conversation as resolved.
|
||
|
|
||
| test('findRow combines DOM filter + override filter', async ({ page }) => { | ||
| await page.setContent(TABLE); | ||
| const table = await makeTable(page).init(); | ||
|
|
||
| const row = await table.findRow({ Status: 'Active', Link: '/d/alpha' }, { exact: true }); | ||
| const data = await row.toJSON() as Record<string, string>; | ||
| expect(data.Name).toBe('Alpha'); | ||
| }); | ||
|
|
||
| test('findRow throws Ambiguous when override filter matches multiple', async ({ page }) => { | ||
| await page.setContent(TABLE); | ||
| const table = await makeTable(page).init(); | ||
|
|
||
| await expect( | ||
| table.findRow({ Link: '/d/' }) | ||
| ).rejects.toThrow(/Ambiguous Row/); | ||
| }); | ||
|
|
||
| test('countRows with override filter counts only matching rows', async ({ page }) => { | ||
| await page.setContent(TABLE); | ||
| const table = await makeTable(page).init(); | ||
|
|
||
| expect(await table.countRows({ Link: '/d/alpha' }, { exact: true })).toBe(1); | ||
| expect(await table.countRows({ Link: '/d/' })).toBe(3); | ||
| expect(await table.countRows({ Link: '/d/nonexistent' }, { exact: true })).toBe(0); | ||
| }); | ||
| }); | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.