[ADF-5581] Reset filterValue when navigating to a new folder to ensur… (#10978)

* [ADF-5581] Reset filterValue when navigating to a new folder to ensure filters are cleared

* [ADF-5581] Added unit tests to verify filterValue reset

* [ADF-5581] Add unit tests to verify filter reset on navigation and preservation on sorting

* [ADF-5581] Use SpyObj<ShareDataTableAdapter> in unit test to avoid any type

* [ADF-5581] Remove redundant type on mockData declaration in unit test

* Revert loadFolder() to reload() in onSortingChanged and update unit test accordingly
This commit is contained in:
Shivangi Shree 2025-07-02 17:48:13 +05:30 committed by GitHub
parent d776c7c77d
commit c7f28d54d6
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 42 additions and 0 deletions

View File

@ -1023,6 +1023,46 @@ describe('DocumentList', () => {
expect(documentList.currentFolderId).toBe('normal-folder');
});
it('should reset filterValue and update currentFolderId when navigating with a string folder ID', () => {
documentList.filterValue = { name: 'test' };
const result = documentList.navigateTo('folder-123');
expect(result).toBeTrue();
expect(documentList.filterValue).toEqual({});
expect(documentList.currentFolderId).toBe('folder-123');
});
it('should reset filterValue and update currentFolderId when navigating with a Node', () => {
const node = new Node({ id: 'node-456', isFolder: true });
spyOn(documentList, 'canNavigateFolder').and.returnValue(true);
documentList.filterValue = { name: 'test' };
const result = documentList.navigateTo(node);
expect(result).toBeTrue();
expect(documentList.filterValue).toEqual({});
expect(documentList.currentFolderId).toBe('node-456');
});
it('should update sorting and call reload when sorting is changed and preserve filterValue', () => {
const reloadSpy = spyOn(documentList, 'reload').and.callThrough();
documentList.sortingMode = 'server';
documentList.filterValue = { name: 'abc' };
documentList.currentFolderId = 'folder-789';
const event = new CustomEvent('sortingChanged', {
detail: { sortingKey: 'name', direction: 'asc' }
});
documentList.onSortingChanged(event);
expect(documentList.sorting).toEqual(['name', 'asc']);
expect(reloadSpy).toHaveBeenCalled();
expect(documentList.filterValue).toEqual({ name: 'abc' });
});
it('should require valid node for file preview', () => {
const file = new FileNode();
file.entry = null;

View File

@ -719,6 +719,7 @@ export class DocumentListComponent extends DataTableSchema implements OnInit, On
if (typeof node === 'string') {
this.resetNewFolderPagination();
this.currentFolderId = node;
this.filterValue = {};
this.folderChange.emit(new NodeEntryEvent({ id: node } as Node));
this.reload();
return true;
@ -726,6 +727,7 @@ export class DocumentListComponent extends DataTableSchema implements OnInit, On
if (this.canNavigateFolder(node)) {
this.resetNewFolderPagination();
this.currentFolderId = this.getNodeFolderDestinationId(node);
this.filterValue = {};
this.folderChange.emit(new NodeEntryEvent({ id: this.currentFolderId } as Node));
this.reload();
return true;