-
-
Notifications
You must be signed in to change notification settings - Fork 132
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #24 from ramses-i/table_filtering
Component: <app-table-action> filtering implementation
- Loading branch information
Showing
12 changed files
with
170 additions
and
21 deletions.
There are no files selected for viewing
This file contains 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 |
---|---|---|
@@ -1,5 +1,5 @@ | ||
<div> | ||
<router-outlet></router-outlet> | ||
<app-responsive-helper></app-responsive-helper> | ||
<ngx-sonner-toaster [theme]="themeService.isDark ? 'dark' : 'light'"/> | ||
<ngx-sonner-toaster [theme]="themeService.isDark ? 'dark' : 'light'"></ngx-sonner-toaster> | ||
</div> |
This file contains 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 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,12 @@ | ||
import { Injectable, signal } from '@angular/core'; | ||
|
||
@Injectable({ | ||
providedIn: 'root', | ||
}) | ||
export class TableFilterService { | ||
searchField = signal<string>(''); | ||
statusField = signal<string>(''); | ||
orderField = signal<string>(''); | ||
|
||
constructor() {} | ||
} |
This file contains 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 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 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 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 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 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 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 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 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,56 @@ | ||
import { test, expect, Page } from '@playwright/test'; | ||
|
||
test.beforeEach(async ({ page }) => { | ||
await page.goto('/components/table', { waitUntil: 'networkidle' }); | ||
await page.getByRole('navigation').locator('div').filter({ hasText: 'Components' }).nth(3).click(); | ||
await page.getByRole('link', { name: 'Table' }).click(); | ||
}); | ||
|
||
async function checkTableRowCount(page: Page, filterSelector: string, value: string, expectedRowCount: number) { | ||
await page.locator(filterSelector).selectOption(value); | ||
|
||
await expect(page.locator('table tbody tr')).toHaveCount(expectedRowCount, { timeout: 5000 }); | ||
} | ||
|
||
async function checkCellInRow(page: Page, cellContent: string, expectedRowIndex: number) { | ||
const rows = await page.locator('table tbody tr'); | ||
const cellTexts = await rows.nth(expectedRowIndex).locator('td').allTextContents(); | ||
expect(cellTexts).toContain(cellContent); | ||
} | ||
|
||
test('check user filter updates table', async ({ page }) => { | ||
await page.fill('input[name="search"]', 'john'); | ||
|
||
await expect(page.locator('table tbody tr')).toHaveCount(2); | ||
}); | ||
|
||
test('check user filter empty restores table', async ({ page }) => { | ||
await page.fill('input[name="search"]', ''); | ||
|
||
await expect(page.locator('table tbody tr')).toHaveCount(8); | ||
}); | ||
|
||
test('check user status filter updates table', async ({ page }) => { | ||
const statusFilters = [ | ||
{ value: '', expectedRowCount: 8 }, // All | ||
{ value: '1', expectedRowCount: 5 }, // Active | ||
{ value: '2', expectedRowCount: 2 }, // Disabled | ||
{ value: '3', expectedRowCount: 1 }, // Pending | ||
]; | ||
|
||
for (const filter of statusFilters) { | ||
await checkTableRowCount(page, 'select[name="status"]', filter.value, filter.expectedRowCount); | ||
} | ||
}); | ||
|
||
test('check user order filter - newest first', async ({ page }) => { | ||
await page.locator('select[name="order"]').selectOption('1'); | ||
|
||
await checkCellInRow(page, 'emmawilson', 0); | ||
}); | ||
|
||
test('check user order filter - oldest first', async ({ page }) => { | ||
await page.locator('select[name="order"]').selectOption('2'); | ||
|
||
await checkCellInRow(page, 'johndoe', 0); | ||
}); |