Skip to content
Merged
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
2 changes: 1 addition & 1 deletion projects/components/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@zvoove/components",
"description": "A set of angular components compatible with and/or dependent on @angular/material.",
"version": "19.3.0",
"version": "19.3.1",
"license": "MIT",
"repository": {
"type": "git",
Expand Down
45 changes: 45 additions & 0 deletions projects/components/table/src/table.component.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -470,10 +470,21 @@ describe('ZvTable', () => {
it('should update state when filter changes', fakeAsync(() => {
const table = createTableInstance(true);
spyOn(table as any, 'requestUpdate').and.callThrough();

// Set initial page to verify it gets reset
table.pageIndex = 5;

table.onSearchChanged('test');

expect((table as any).requestUpdate).toHaveBeenCalledTimes(1);
expect((table as any).requestUpdate).toHaveBeenCalledWith({
searchText: 'test',
currentPage: 0,
});

tick(1);
expect(table.filterText).toEqual('test');
expect(table.pageIndex).toEqual(0);
}));

it('should update state when page changes and emit output', fakeAsync(() => {
Expand Down Expand Up @@ -727,6 +738,40 @@ describe('ZvTable', () => {
expect(component.table.onSearchChanged).toHaveBeenCalledWith('asdf');
});

it('should reset page to 0 when filtering', async () => {
// Initialize with a data source that has enough data for multiple pages
await initTestComponent(
new ZvTableDataSource({
loadDataFn: () => of(Array.from({ length: 10 }, (_, i: number) => ({ id: i, str: `item ${i}` }))),
mode: 'client',
}),
(settingService) => {
settingService.settings$.next({
[component.tableId]: {
pageSize: 3, // This will create multiple pages
sortColumn: null,
sortDirection: null,
columnBlacklist: [],
},
});
}
);

// Set the page to 2 manually to simulate navigation
component.table.pageIndex = 1;
fixture.detectChanges();

// Verify we're on page 2
expect(component.table.pageIndex).toEqual(1);

// Apply a filter
const searchInput = await table.getSearchInput();
await searchInput.setValue('item');

// Verify that the page index is reset to 0
expect(component.table.pageIndex).toEqual(0);
});

it('should sort via dropdown', async () => {
const sort = await loader.getHarness(MatSortHarness);
expect(await sort.getActiveHeader()).toBeFalsy();
Expand Down
1 change: 1 addition & 0 deletions projects/components/table/src/table.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -274,6 +274,7 @@ export class ZvTable<TData = unknown> implements OnInit, OnChanges, AfterContent
public onSearchChanged(value: string | null) {
this.requestUpdate({
searchText: value,
currentPage: 0,
});
}

Expand Down