mirror of
https://github.com/bulwarkmail/webmail.git
synced 2026-10-31 00:12:39 +00:00
fix: keep the open folder when clearing search filters #1430
This commit is contained in:
@@ -32,6 +32,8 @@ function makeClient() {
|
||||
searchEmails: vi.fn().mockResolvedValue({ emails: [], hasMore: false, total: 0 }),
|
||||
advancedSearchEmails: vi.fn().mockResolvedValue({ emails: [], hasMore: false, total: 0 }),
|
||||
getSomeEmails: vi.fn().mockResolvedValue([]),
|
||||
getEmails: vi.fn().mockResolvedValue({ emails: [], hasMore: false, total: 0, state: 'email-state' }),
|
||||
getThreads: vi.fn().mockResolvedValue([]),
|
||||
getAccountId: () => 'me',
|
||||
} as unknown as IJMAPClient;
|
||||
}
|
||||
@@ -174,6 +176,21 @@ describe('search folder scope (#788)', () => {
|
||||
|
||||
expect(useEmailStore.getState().searchMailboxId).toBe('');
|
||||
});
|
||||
|
||||
// #1430: "Clear" in the filter panel re-runs the search with nothing left
|
||||
// to search for, which listed every message of the account in the folder.
|
||||
it('shows the open folder again when the filters are cleared', async () => {
|
||||
useEmailStore.setState({ searchFilters: { ...DEFAULT_SEARCH_FILTERS, from: 'bob@example.com' } });
|
||||
await useEmailStore.getState().advancedSearch(client);
|
||||
(client.advancedSearchEmails as ReturnType<typeof vi.fn>).mockClear();
|
||||
|
||||
useEmailStore.getState().clearSearchFilters();
|
||||
await useEmailStore.getState().advancedSearch(client);
|
||||
|
||||
expect(client.advancedSearchEmails).not.toHaveBeenCalled();
|
||||
expect(client.getEmails).toHaveBeenCalledTimes(1);
|
||||
expect((client.getEmails as ReturnType<typeof vi.fn>).mock.calls[0][0]).toBe('sent');
|
||||
});
|
||||
});
|
||||
|
||||
describe('unread badge scope', () => {
|
||||
|
||||
@@ -5393,6 +5393,15 @@ export const useEmailStore = create<EmailStore>((set, get) => ({
|
||||
const { query: searchQuery, filters: searchFilters } = transformed
|
||||
?? (emailHooks.onSearch.size > 0 ? await transformSearch(typedQuery, typedFilters) : { query: typedQuery, filters: typedFilters });
|
||||
if (controller.signal.aborted) return;
|
||||
// Clearing the filters leaves nothing to search for. Under the
|
||||
// all-folders scope that empty search listed every message of the
|
||||
// account in place of the open folder (#1430), so load the folder.
|
||||
if (!isUnifiedView && !selectedKeyword && get().selectedMailbox && isAllFoldersSearchScope(searchMailboxId)
|
||||
&& !searchQuery.trim() && isFilterEmpty(searchFilters)) {
|
||||
set({ searchAbortController: null });
|
||||
await get().fetchEmails(client);
|
||||
return;
|
||||
}
|
||||
startProvidedSearchResults(searchQuery, searchFilters, { get, set });
|
||||
const emailsPerPage = useSettingsStore.getState().emailsPerPage;
|
||||
let result;
|
||||
|
||||
Reference in New Issue
Block a user