-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge remote-tracking branch 'clearcontracts/main' into test
- Loading branch information
Showing
134 changed files
with
4,721 additions
and
1,082 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
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,28 @@ | ||
import { http, HttpResponse } from 'msw'; | ||
|
||
export const downloadPollVotesPollIdNotValidHandler = [ | ||
http.post('/api/downloadPollVotes', async () => { | ||
return HttpResponse.json( | ||
{ success: false, message: 'Missing pollId' }, | ||
{ status: 400 }, | ||
); | ||
}), | ||
]; | ||
|
||
export const downloadPollVotesInternalErrorHandler = [ | ||
http.post('/api/downloadPollVotes', async () => { | ||
return HttpResponse.json( | ||
{ success: false, message: 'Failed to create CSV file' }, | ||
{ status: 500 }, | ||
); | ||
}), | ||
]; | ||
|
||
export const downloadPollVotesNotConcludedHandler = [ | ||
http.post('/api/downloadPollVotes', async () => { | ||
return HttpResponse.json( | ||
{ success: false, message: 'Poll is not concluded' }, | ||
{ status: 500 }, | ||
); | ||
}), | ||
]; |
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,9 @@ | ||
import { http, HttpResponse } from 'msw'; | ||
|
||
export const downloadPollVotesHandlers = [ | ||
http.post('/api/downloadPollVotes', () => { | ||
return HttpResponse.json({ | ||
status: 200, | ||
}); | ||
}), | ||
]; |
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,19 @@ | ||
import { http, HttpResponse } from 'msw'; | ||
|
||
export const downloadUserVotesPollIdNotValidHandler = [ | ||
http.post('/api/downloadUserVotes', async () => { | ||
return HttpResponse.json( | ||
{ success: false, message: 'Missing userId' }, | ||
{ status: 400 }, | ||
); | ||
}), | ||
]; | ||
|
||
export const downloadUserVotesInternalErrorHandler = [ | ||
http.post('/api/downloadUserVotes', async () => { | ||
return HttpResponse.json( | ||
{ success: false, message: 'Failed to create CSV file' }, | ||
{ status: 500 }, | ||
); | ||
}), | ||
]; |
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,10 @@ | ||
import { http, HttpResponse } from 'msw'; | ||
|
||
// TODO: Figure out how to properly mock the blob response | ||
export const downloadUserVotesHandlers = [ | ||
http.post('/api/downloadUserVotes', () => { | ||
return HttpResponse.json({ | ||
status: 200, | ||
}); | ||
}), | ||
]; |
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 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
29 changes: 29 additions & 0 deletions
29
__tests__/components/buttons/downloadPollVotesButton/alertsUserWhenError.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,29 @@ | ||
import { downloadPollVotesInternalErrorHandler } from '@/../__mocks__/downloadPollVotes/errorHandlers'; | ||
import { server } from '@/../__mocks__/server'; | ||
import { render, screen } from '@testing-library/react'; | ||
import userEvent from '@testing-library/user-event'; | ||
import { Toaster } from 'react-hot-toast'; | ||
import { expect, test } from 'vitest'; | ||
|
||
import { DownloadPollVotesButton } from '@/components/buttons/downloadPollVotesButton'; | ||
|
||
// This mock environment has difficulty simulating blob responses which is what the downloadPollVotes function returns. | ||
// This test is skipped because it will not work in the current environment. This will need to rely on E2E tests. | ||
test.skip('alerts user when internal error', async () => { | ||
server.use(...downloadPollVotesInternalErrorHandler); | ||
const user = userEvent.setup(); | ||
render( | ||
<> | ||
<Toaster /> | ||
<DownloadPollVotesButton pollId="1" /> | ||
</>, | ||
); | ||
|
||
const button = screen.getByRole('button', { | ||
name: /Download votes/i, | ||
}); | ||
expect(button).toBeDefined(); | ||
await user.click(button); | ||
const toast = await screen.findByText(/Failed to create CSV file/i); | ||
expect(toast).toBeDefined(); | ||
}); |
29 changes: 29 additions & 0 deletions
29
__tests__/components/buttons/downloadPollVotesButton/alertsUserWhenNoPollId.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,29 @@ | ||
import { downloadPollVotesPollIdNotValidHandler } from '@/../__mocks__/downloadPollVotes/errorHandlers'; | ||
import { server } from '@/../__mocks__/server'; | ||
import { render, screen } from '@testing-library/react'; | ||
import userEvent from '@testing-library/user-event'; | ||
import { Toaster } from 'react-hot-toast'; | ||
import { expect, test } from 'vitest'; | ||
|
||
import { DownloadPollVotesButton } from '@/components/buttons/downloadPollVotesButton'; | ||
|
||
// This mock environment has difficulty simulating blob responses which is what the downloadPollVotes function returns. | ||
// This test is skipped because it will not work in the current environment. This will need to rely on E2E tests. | ||
test.skip('alerts user when no poll ID', async () => { | ||
server.use(...downloadPollVotesPollIdNotValidHandler); | ||
const user = userEvent.setup(); | ||
render( | ||
<> | ||
<Toaster /> | ||
<DownloadPollVotesButton pollId="1" /> | ||
</>, | ||
); | ||
|
||
const button = screen.getByRole('button', { | ||
name: /Download Votes/i, | ||
}); | ||
expect(button).toBeDefined(); | ||
await user.click(button); | ||
const toast = await screen.findByText(/Missing pollId/i); | ||
expect(toast).toBeDefined(); | ||
}); |
29 changes: 29 additions & 0 deletions
29
__tests__/components/buttons/downloadPollVotesButton/alertsUserWhenPollNotConcluded.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,29 @@ | ||
import { downloadPollVotesNotConcludedHandler } from '@/../__mocks__/downloadPollVotes/errorHandlers'; | ||
import { server } from '@/../__mocks__/server'; | ||
import { render, screen } from '@testing-library/react'; | ||
import userEvent from '@testing-library/user-event'; | ||
import { Toaster } from 'react-hot-toast'; | ||
import { expect, test } from 'vitest'; | ||
|
||
import { DownloadPollVotesButton } from '@/components/buttons/downloadPollVotesButton'; | ||
|
||
// This mock environment has difficulty simulating blob responses which is what the downloadPollVotes function returns. | ||
// This test is skipped because it will not work in the current environment. This will need to rely on E2E tests. | ||
test.skip('alerts user when poll is not concluded', async () => { | ||
server.use(...downloadPollVotesNotConcludedHandler); | ||
const user = userEvent.setup(); | ||
render( | ||
<> | ||
<Toaster /> | ||
<DownloadPollVotesButton pollId="1" /> | ||
</>, | ||
); | ||
|
||
const button = screen.getByRole('button', { | ||
name: /Download Votes/i, | ||
}); | ||
expect(button).toBeDefined(); | ||
await user.click(button); | ||
const toast = await screen.findByText(/'Poll is not concluded'/i); | ||
expect(toast).toBeDefined(); | ||
}); |
26 changes: 26 additions & 0 deletions
26
__tests__/components/buttons/downloadPollVotesButton/alertsUserWhenSuccessful.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,26 @@ | ||
import { render, screen } from '@testing-library/react'; | ||
import userEvent from '@testing-library/user-event'; | ||
import { Toaster } from 'react-hot-toast'; | ||
import { expect, test } from 'vitest'; | ||
|
||
import { DownloadPollVotesButton } from '@/components/buttons/downloadPollVotesButton'; | ||
|
||
// This mock environment has difficulty simulating blob responses which is what the downloadPollVotes function returns. | ||
// This test is skipped because it will not work in the current environment. This will need to rely on E2E tests. | ||
test.skip('alerts user when successful', async () => { | ||
const user = userEvent.setup(); | ||
render( | ||
<> | ||
<Toaster /> | ||
<DownloadPollVotesButton pollId="1" /> | ||
</>, | ||
); | ||
|
||
const button = screen.getByRole('button', { | ||
name: /Download votes/i, | ||
}); | ||
expect(button).toBeDefined(); | ||
await user.click(button); | ||
const toast = await screen.findByText(/Poll votes downloaded/i); | ||
expect(toast).toBeDefined(); | ||
}); |
29 changes: 29 additions & 0 deletions
29
__tests__/components/buttons/downloadUserVotesButton/alertsUserWhenError.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,29 @@ | ||
import { downloadUserVotesInternalErrorHandler } from '@/../__mocks__/downloadUserVotes/errorHandlers'; | ||
import { server } from '@/../__mocks__/server'; | ||
import { render, screen } from '@testing-library/react'; | ||
import userEvent from '@testing-library/user-event'; | ||
import { Toaster } from 'react-hot-toast'; | ||
import { expect, test } from 'vitest'; | ||
|
||
import { DownloadUserVotesButton } from '@/components/buttons/downloadUserVotesButton'; | ||
|
||
// This mock environment has difficulty simulating blob responses which is what the downloadUserVotes function returns. | ||
// This test is skipped because it will not work in the current environment. This will need to rely on E2E tests. | ||
test.skip('alerts user when internal error', async () => { | ||
server.use(...downloadUserVotesInternalErrorHandler); | ||
const user = userEvent.setup(); | ||
render( | ||
<> | ||
<Toaster /> | ||
<DownloadUserVotesButton userId="1" /> | ||
</>, | ||
); | ||
|
||
const button = screen.getByRole('button', { | ||
name: /Download votes/i, | ||
}); | ||
expect(button).toBeDefined(); | ||
await user.click(button); | ||
const toast = await screen.findByText(/Failed to create CSV file/i); | ||
expect(toast).toBeDefined(); | ||
}); |
29 changes: 29 additions & 0 deletions
29
__tests__/components/buttons/downloadUserVotesButton/alertsUserWhenNoPollId.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,29 @@ | ||
import { downloadUserVotesPollIdNotValidHandler } from '@/../__mocks__/downloadUserVotes/errorHandlers'; | ||
import { server } from '@/../__mocks__/server'; | ||
import { render, screen } from '@testing-library/react'; | ||
import userEvent from '@testing-library/user-event'; | ||
import { Toaster } from 'react-hot-toast'; | ||
import { expect, test } from 'vitest'; | ||
|
||
import { DownloadUserVotesButton } from '@/components/buttons/downloadUserVotesButton'; | ||
|
||
// This mock environment has difficulty simulating blob responses which is what the downloadUserVotes function returns. | ||
// This test is skipped because it will not work in the current environment. This will need to rely on E2E tests. | ||
test.skip('alerts user when no poll ID', async () => { | ||
server.use(...downloadUserVotesPollIdNotValidHandler); | ||
const user = userEvent.setup(); | ||
render( | ||
<> | ||
<Toaster /> | ||
<DownloadUserVotesButton userId="1" /> | ||
</>, | ||
); | ||
|
||
const button = screen.getByRole('button', { | ||
name: /Download Votes/i, | ||
}); | ||
expect(button).toBeDefined(); | ||
await user.click(button); | ||
const toast = await screen.findByText(/Missing userId/i); | ||
expect(toast).toBeDefined(); | ||
}); |
26 changes: 26 additions & 0 deletions
26
__tests__/components/buttons/downloadUserVotesButton/alertsUserWhenSuccessful.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,26 @@ | ||
import { render, screen } from '@testing-library/react'; | ||
import userEvent from '@testing-library/user-event'; | ||
import { Toaster } from 'react-hot-toast'; | ||
import { expect, test } from 'vitest'; | ||
|
||
import { DownloadUserVotesButton } from '@/components/buttons/downloadUserVotesButton'; | ||
|
||
// This mock environment has difficulty simulating blob responses which is what the downloadUserVotes function returns. | ||
// This test is skipped because it will not work in the current environment. This will need to rely on E2E tests. | ||
test.skip('alerts user when successful', async () => { | ||
const user = userEvent.setup(); | ||
render( | ||
<> | ||
<Toaster /> | ||
<DownloadUserVotesButton userId="1" /> | ||
</>, | ||
); | ||
|
||
const button = screen.getByRole('button', { | ||
name: /Download votes/i, | ||
}); | ||
expect(button).toBeDefined(); | ||
await user.click(button); | ||
const toast = await screen.findByText(/User votes downloaded/i); | ||
expect(toast).toBeDefined(); | ||
}); |
42 changes: 42 additions & 0 deletions
42
__tests__/components/buttons/voteOnPollButton/alertsUserWhenPollIsArchived.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,42 @@ | ||
import { pollIsArchivedHandler } from '@/../__mocks__/newPollVote/errorHandlers'; | ||
import { server } from '@/../__mocks__/server'; | ||
import { render, screen } from '@testing-library/react'; | ||
import userEvent from '@testing-library/user-event'; | ||
import { SessionProvider } from 'next-auth/react'; | ||
import { Toaster } from 'react-hot-toast'; | ||
import { expect, test } from 'vitest'; | ||
|
||
import { VoteOnPollButtons } from '@/components/buttons/voteOnPollButtons'; | ||
|
||
test.skip('alerts user when poll is archived', async () => { | ||
server.use(...pollIsArchivedHandler); | ||
const user = userEvent.setup(); | ||
render( | ||
<SessionProvider | ||
session={{ | ||
expires: '1', | ||
user: { | ||
id: '1', | ||
stakeAddress: 'stakeAddress', | ||
walletName: 'walletName', | ||
}, | ||
}} | ||
> | ||
<Toaster /> | ||
<VoteOnPollButtons | ||
pollId="1" | ||
disabled={false} | ||
setDisabled={() => {}} | ||
isActiveVoter={true} | ||
/> | ||
</SessionProvider>, | ||
); | ||
|
||
const yesVoteButton = screen.getByRole('button', { | ||
name: /yes/i, | ||
}); | ||
expect(yesVoteButton).toBeDefined(); | ||
await user.click(yesVoteButton); | ||
const toast = await screen.findByText(/Poll is archived/i); | ||
expect(toast).toBeDefined(); | ||
}); |
Oops, something went wrong.