Skip to content

Commit

Permalink
fix: Added test for story map notifications
Browse files Browse the repository at this point in the history
  • Loading branch information
josebui committed Sep 11, 2023
1 parent c694d67 commit 0491780
Showing 1 changed file with 19 additions and 9 deletions.
28 changes: 19 additions & 9 deletions src/account/components/AccountProfile.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -245,7 +245,7 @@ test('AccountProfile: Save language', async () => {
});
});

test('AccountProfile: Save group notifications', async () => {
const testNotificationsSetting = async (key, checkboxLabel) => {
terrasoApi.requestGraphQL.mockImplementation(query => {
const trimmedQuery = query.trim();

Expand Down Expand Up @@ -288,18 +288,16 @@ test('AccountProfile: Save group notifications', async () => {
}
if (trimmedQuery.startsWith('mutation updateUserPreference(')) {
return Promise.resolve(
_.set(
'updateUserPreference.preference',
{ key: 'group_notifications', value: 'true' },
{}
)
_.set('updateUserPreference.preference', { key, value: 'true' }, {})
);
}
});

await setup();

const checkbox = screen.getByRole('checkbox');
const checkbox = screen.getByRole('checkbox', {
name: checkboxLabel,
});

expect(checkbox.checked).toEqual(false);
await act(async () => fireEvent.click(checkbox));
Expand All @@ -311,12 +309,24 @@ test('AccountProfile: Save group notifications', async () => {
expect(terrasoApi.requestGraphQL).toHaveBeenCalledTimes(4);
expect(terrasoApi.requestGraphQL.mock.calls[3][1]).toStrictEqual({
input: {
key: 'group_notifications',
key,
userEmail: '[email protected]',
value: 'true',
},
});
});
};

test('AccountProfile: Save group notifications', async () =>
testNotificationsSetting(
'group_notifications',
'A group I manage has pending requests or my request to join a closed group is approved'
));

test('AccountProfile: Save story map notifications', async () =>
testNotificationsSetting(
'story_map_notifications',
'I am invited to edit a story map'
));

test('AccountProfile: Save error', async () => {
terrasoApi.requestGraphQL.mockImplementation(query => {
Expand Down

0 comments on commit 0491780

Please sign in to comment.