-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: Added test for story map notifications
- Loading branch information
Showing
1 changed file
with
19 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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(); | ||
|
||
|
@@ -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)); | ||
|
@@ -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 => { | ||
|