-
-
Notifications
You must be signed in to change notification settings - Fork 736
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: read productivity report from profile
- Loading branch information
Showing
5 changed files
with
165 additions
and
53 deletions.
There are no files selected for viewing
105 changes: 105 additions & 0 deletions
105
frontend/src/component/user/Profile/ProfileTab/ProductivityEmailSubscription.test.tsx
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 |
---|---|---|
@@ -0,0 +1,105 @@ | ||
import { render } from 'utils/testRenderer'; | ||
import { screen } from '@testing-library/react'; | ||
import { testServerRoute, testServerSetup } from 'utils/testServer'; | ||
import { ProductivityEmailSubscription } from './ProductivityEmailSubscription'; | ||
import ToastRenderer from '../../../common/ToastRenderer/ToastRenderer'; | ||
|
||
const server = testServerSetup(); | ||
|
||
const setupSubscribeApi = () => { | ||
testServerRoute( | ||
server, | ||
'/api/admin/email-subscription/productivity-report', | ||
{}, | ||
'put', | ||
202, | ||
); | ||
}; | ||
|
||
const setupUnsubscribeApi = () => { | ||
testServerRoute( | ||
server, | ||
'/api/admin/email-subscription/productivity-report', | ||
{}, | ||
'delete', | ||
202, | ||
); | ||
}; | ||
|
||
const setupErrorApi = () => { | ||
testServerRoute( | ||
server, | ||
'/api/admin/email-subscription/productivity-report', | ||
{ message: 'user error' }, | ||
'delete', | ||
400, | ||
); | ||
}; | ||
|
||
test('unsubscribe', async () => { | ||
setupUnsubscribeApi(); | ||
let changed = false; | ||
render( | ||
<> | ||
<ProductivityEmailSubscription | ||
status='subscribed' | ||
onChange={() => { | ||
changed = true; | ||
}} | ||
/> | ||
<ToastRenderer /> | ||
</>, | ||
); | ||
const checkbox = screen.getByLabelText('Productivity Email Subscription'); | ||
expect(checkbox).toBeChecked(); | ||
|
||
checkbox.click(); | ||
|
||
await screen.findByText('Unsubscribed from productivity report'); | ||
expect(changed).toBe(true); | ||
}); | ||
|
||
test('subscribe', async () => { | ||
setupSubscribeApi(); | ||
let changed = false; | ||
render( | ||
<> | ||
<ProductivityEmailSubscription | ||
status='unsubscribed' | ||
onChange={() => { | ||
changed = true; | ||
}} | ||
/> | ||
<ToastRenderer /> | ||
</>, | ||
); | ||
const checkbox = screen.getByLabelText('Productivity Email Subscription'); | ||
expect(checkbox).not.toBeChecked(); | ||
|
||
checkbox.click(); | ||
|
||
await screen.findByText('Subscribed to productivity report'); | ||
expect(changed).toBe(true); | ||
}); | ||
|
||
test('handle error', async () => { | ||
setupErrorApi(); | ||
let changed = false; | ||
render( | ||
<> | ||
<ProductivityEmailSubscription | ||
status='subscribed' | ||
onChange={() => { | ||
changed = true; | ||
}} | ||
/> | ||
<ToastRenderer /> | ||
</>, | ||
); | ||
const checkbox = screen.getByLabelText('Productivity Email Subscription'); | ||
|
||
checkbox.click(); | ||
|
||
await screen.findByText('user error'); | ||
expect(changed).toBe(true); | ||
}); |
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
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
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
This file was deleted.
Oops, something went wrong.