Skip to content

Commit

Permalink
only reset if delete actually happened
Browse files Browse the repository at this point in the history
  • Loading branch information
shakyShane committed Feb 26, 2025
1 parent b59d1c9 commit 3bad912
Show file tree
Hide file tree
Showing 5 changed files with 43 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,11 @@ export function HistoryServiceProvider({ service, children }) {
service
.deleteRange(range)
// eslint-disable-next-line promise/prefer-await-to-then
.then(() => queryDispatch({ kind: 'reset' }))
.then((resp) => {
if (resp.kind === 'range-deleted') {
queryDispatch({ kind: 'reset' });
}
})
// eslint-disable-next-line promise/prefer-await-to-then
.catch(console.error);
}
Expand Down
8 changes: 6 additions & 2 deletions special-pages/pages/history/app/history.service.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { OVERSCAN_AMOUNT } from './constants.js';
import { HistoryRangeService } from './history.range.service.js';

/**
* @import {ActionResponse} from "../types/history.js"
* @typedef {import('../types/history.js').Range} Range
* @typedef {import('../types/history.js').HistoryQuery} HistoryQuery
* @typedef {import("../types/history.js").HistoryQueryInfo} HistoryQueryInfo
Expand Down Expand Up @@ -306,14 +307,17 @@ export class HistoryService {

/**
* @param {Range} range
* @return {Promise<{kind: 'none'} | {kind: "range-deleted"}>}
*/
async deleteRange(range) {
console.log('📤 [deleteRange]: ', JSON.stringify({ range }));
const resp = await this.range.deleteRange(range);
if (resp.action === 'delete' && range === 'all') {
this.reset();
}
return resp;
if (resp.action === 'delete') {
return { kind: 'range-deleted' };
}
return { kind: 'none' };
}

/**
Expand Down
3 changes: 1 addition & 2 deletions special-pages/pages/history/app/mocks/mock-transport.js
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,6 @@ export function mockTransport() {
return Promise.resolve({ action: 'none' });
}
case 'title_menu': {
// console.log('📤 [deleteRange]: ', JSON.stringify(msg.params));
// prettier-ignore
const lines = [
`title_menu: ${JSON.stringify(msg.params)}`,
Expand All @@ -115,7 +114,7 @@ export function mockTransport() {
return Promise.resolve({ action: 'none' });
}
case 'deleteRange': {
console.log('📤 [deleteRange]: ', JSON.stringify(msg.params));
// console.log('📤 [deleteRange]: ', JSON.stringify(msg.params));
// prettier-ignore
const lines = [
`deleteRange: ${JSON.stringify(msg.params)}`,
Expand Down
8 changes: 8 additions & 0 deletions special-pages/pages/history/integration-tests/history.page.js
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,14 @@ export class HistoryTestPage {
expect(params).toStrictEqual({ query, limit: 150, offset: 0 });
}

/**
* @param {number} n
*/
async didMakeNQueries(n) {
const calls = await this.mocks.outgoing({ names: ['query'] });
expect(calls).toHaveLength(n);
}

/**
* @param {object} props
* @param {number} props.nth
Expand Down
24 changes: 23 additions & 1 deletion special-pages/pages/history/integration-tests/history.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ test.describe('history', () => {
await hp.openPage({});
await hp.opensLinks();
});
test('deleting sidebar items', async ({ page }, workerInfo) => {
test('deleting range from sidebar items + resetting the query state', async ({ page }, workerInfo) => {
const hp = HistoryTestPage.create(page, workerInfo).withEntries(2000);
await hp.openPage({});
await hp.didMakeNthQuery({ nth: 0, query: { term: '' } });
Expand All @@ -111,6 +111,28 @@ test.describe('history', () => {
await hp.deletesHistoryForYesterday({ action: 'none' });
await hp.sidebarHasItem('Show history for today');
});
test(
'presses delete on range, but dismisses the modal',
{
annotation: {
type: 'issue',
description: 'https://app.asana.com/0/1201141132935289/1209501378934498',
},
},
async ({ page }, workerInfo) => {
const hp = HistoryTestPage.create(page, workerInfo).withEntries(2000);
await hp.openPage({});

// simulate a modal appearing, but the user dismissing it
await hp.deletesHistoryForYesterday({ action: 'none' });

// this timeout is needed to simulate the bug - a small delay after closing the modal
await page.waitForTimeout(100);

// now check only the first query occurred (on page load)
await hp.didMakeNQueries(1);
},
);
test('deleting from the header', async ({ page }, workerInfo) => {
const hp = HistoryTestPage.create(page, workerInfo).withEntries(2000);
await hp.openPage({});
Expand Down

0 comments on commit 3bad912

Please sign in to comment.