Skip to content

Commit

Permalink
accountsReducer tests [nfc]: Put more work into make-event helper
Browse files Browse the repository at this point in the history
So we don't have to be as repetitive at the callsites.
  • Loading branch information
chrisbobbe committed Jan 23, 2024
1 parent 1ed0a06 commit 18dd4d2
Showing 1 changed file with 21 additions and 33 deletions.
54 changes: 21 additions & 33 deletions src/account/__tests__/accountsReducer-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import { ZulipVersion } from '../../utils/zulipVersion';
import * as eg from '../../__tests__/lib/exampleData';
import { identityOfAccount } from '../accountMisc';
import { EventTypes } from '../../api/eventTypes';
import type { RealmUpdateDictEvent } from '../../api/eventTypes';

describe('accountsReducer', () => {
describe('REGISTER_COMPLETE', () => {
Expand Down Expand Up @@ -229,60 +230,47 @@ describe('accountsReducer', () => {
{ ...eg.plusReduxState.accounts[0], lastDismissedServerPushSetupNotice: null },
];

const eventCommon = { id: 0, type: EventTypes.realm, op: 'update_dict', property: 'default' };
const eventWith = (data: RealmUpdateDictEvent['data']) => ({
type: EVENT,
event: { id: 0, type: EventTypes.realm, op: 'update_dict', property: 'default', data },
});

test('data.push_notifications_enabled is true, on state with dismissed notice', () => {
expect(
accountsReducer(stateWithDismissedNotice, {
type: EVENT,
event: { ...eventCommon, data: { push_notifications_enabled: true } },
}),
accountsReducer(stateWithDismissedNotice, eventWith({ push_notifications_enabled: true })),
).toEqual(stateWithoutDismissedNotice);
});

test('data.push_notifications_enabled is true, on state without dismissed notice', () => {
expect(
accountsReducer(stateWithoutDismissedNotice, {
type: EVENT,
event: { ...eventCommon, data: { push_notifications_enabled: true } },
}),
).toEqual(stateWithoutDismissedNotice);
const actualState = accountsReducer(
stateWithoutDismissedNotice,
eventWith({ push_notifications_enabled: true }),
);
expect(actualState).toEqual(stateWithoutDismissedNotice);
});

test('data.push_notifications_enabled is false, on state with dismissed notice', () => {
expect(
accountsReducer(stateWithDismissedNotice, {
type: EVENT,
event: { ...eventCommon, data: { push_notifications_enabled: false } },
}),
accountsReducer(stateWithDismissedNotice, eventWith({ push_notifications_enabled: false })),
).toEqual(stateWithDismissedNotice);
});

test('data.push_notifications_enabled is false, on state without dismissed notice', () => {
expect(
accountsReducer(stateWithoutDismissedNotice, {
type: EVENT,
event: { ...eventCommon, data: { push_notifications_enabled: false } },
}),
).toEqual(stateWithoutDismissedNotice);
const actualState = accountsReducer(
stateWithoutDismissedNotice,
eventWith({ push_notifications_enabled: false }),
);
expect(actualState).toEqual(stateWithoutDismissedNotice);
});

test('data.push_notifications_enabled is absent, on state with dismissed notice', () => {
expect(
accountsReducer(stateWithDismissedNotice, {
type: EVENT,
event: { ...eventCommon, data: {} },
}),
).toEqual(stateWithDismissedNotice);
const actualState = accountsReducer(stateWithDismissedNotice, eventWith({}));
expect(actualState).toEqual(stateWithDismissedNotice);
});

test('data.push_notifications_enabled is absent, on state without dismissed notice', () => {
expect(
accountsReducer(stateWithoutDismissedNotice, {
type: EVENT,
event: { ...eventCommon, data: {} },
}),
).toEqual(stateWithoutDismissedNotice);
const actualState = accountsReducer(stateWithoutDismissedNotice, eventWith({}));
expect(actualState).toEqual(stateWithoutDismissedNotice);
});
});
});

0 comments on commit 18dd4d2

Please sign in to comment.