diff --git a/projects/components/package.json b/projects/components/package.json index 1404087..9b7f4b7 100644 --- a/projects/components/package.json +++ b/projects/components/package.json @@ -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", diff --git a/projects/components/table/src/table.component.spec.ts b/projects/components/table/src/table.component.spec.ts index 117ef91..ad87db2 100644 --- a/projects/components/table/src/table.component.spec.ts +++ b/projects/components/table/src/table.component.spec.ts @@ -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(() => { @@ -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(); diff --git a/projects/components/table/src/table.component.ts b/projects/components/table/src/table.component.ts index 441534a..f13d0f1 100644 --- a/projects/components/table/src/table.component.ts +++ b/projects/components/table/src/table.component.ts @@ -274,6 +274,7 @@ export class ZvTable implements OnInit, OnChanges, AfterContent public onSearchChanged(value: string | null) { this.requestUpdate({ searchText: value, + currentPage: 0, }); }