-
Notifications
You must be signed in to change notification settings - Fork 0
PLT-9674: Added Landing page unit and integration tests #73
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -2,7 +2,7 @@ | |||||||||||||||
|
|
||||||||||||||||
| | Statements | Branches | Functions | Lines | | ||||||||||||||||
| | --------------------------- | ----------------------- | ------------------------- | ----------------- | | ||||||||||||||||
| |  |  |  |  | | ||||||||||||||||
| |  |  |  |  | | ||||||||||||||||
|
Comment on lines
3
to
+5
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Clean up repeated whitespaces in the table headers for better readability. -| Statements | Branches | Functions | Lines |
+| Statements | Branches | Functions | Lines |Committable suggestion
Suggested change
|
||||||||||||||||
|
|
||||||||||||||||
| Front-end repository for Certification Service integration | ||||||||||||||||
|
|
||||||||||||||||
|
|
||||||||||||||||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,122 @@ | ||
| import React from 'react'; | ||
| import { screen } from '@testing-library/react'; | ||
| import userEvent from '@testing-library/user-event'; | ||
| import '@testing-library/jest-dom'; | ||
|
|
||
| import { renderWithProviders } from 'utils/test-utils'; | ||
| import RegisterModal from './RegisterModal'; | ||
|
|
||
|
|
||
| describe('Landing page > Register modal', () => { | ||
|
|
||
| test('should not render register modal if show property is false', () => { | ||
|
|
||
| const props = { | ||
| show: false, | ||
| success: false, | ||
| transactionId: null, | ||
| onClose: () => {} | ||
| }; | ||
|
|
||
| renderWithProviders(<RegisterModal {...props} />); | ||
|
|
||
| const dialogElement = screen.queryByTestId('register-modal'); | ||
|
|
||
| expect(dialogElement).not.toBeInTheDocument(); | ||
|
|
||
| }); | ||
|
|
||
| test('should render register modal if show property is true', () => { | ||
|
|
||
| const props = { | ||
| show: true, | ||
| success: false, | ||
| transactionId: null, | ||
| onClose: () => {} | ||
| }; | ||
|
|
||
| renderWithProviders(<RegisterModal {...props} />); | ||
|
|
||
| const dialogElement = screen.getByTestId('register-modal'); | ||
|
|
||
| expect(dialogElement).toBeVisible(); | ||
|
|
||
| }); | ||
|
|
||
| test('should render register modal with success message if show and success properties are true', () => { | ||
|
|
||
| const props = { | ||
| show: true, | ||
| success: true, | ||
| transactionId: null, | ||
| onClose: () => {} | ||
| }; | ||
|
|
||
| renderWithProviders(<RegisterModal {...props} />); | ||
|
|
||
| const successTitleElement = screen.queryByText('Successfully initiated subscription'); | ||
|
|
||
| expect(successTitleElement).toBeVisible(); | ||
|
|
||
| const loadingTitleElement = screen.queryByText('Setting up your subscription...'); | ||
|
|
||
| expect(loadingTitleElement).not.toBeInTheDocument(); | ||
|
|
||
| }); | ||
|
|
||
| test('should render register modal with loading message if show property is true and success property is false', () => { | ||
|
|
||
| const props = { | ||
| show: true, | ||
| success: false, | ||
| transactionId: null, | ||
| onClose: () => {} | ||
| }; | ||
|
|
||
| renderWithProviders(<RegisterModal {...props} />); | ||
|
|
||
| const loadingTitleElement = screen.queryByText('Setting up your subscription...'); | ||
|
|
||
| expect(loadingTitleElement).toBeVisible(); | ||
|
|
||
| const successTitleElement = screen.queryByText('Successfully initiated subscription'); | ||
|
|
||
| expect(successTitleElement).not.toBeInTheDocument(); | ||
|
|
||
| }); | ||
|
|
||
| test('should render register modal with transaction link if show and success properties are true and transactionId is not null', () => { | ||
|
|
||
| const props = { | ||
| show: true, | ||
| success: true, | ||
| transactionId: '1234', | ||
| onClose: () => {} | ||
| }; | ||
|
|
||
| renderWithProviders(<RegisterModal {...props} />); | ||
|
|
||
| const transactionElement = screen.queryByText('View your performed payment transaction'); | ||
|
|
||
| expect(transactionElement).toBeVisible(); | ||
|
|
||
| }); | ||
|
|
||
| test('should render register modal and close after a click event on continue button', async () => { | ||
|
|
||
| const props = { | ||
| show: true, | ||
| success: true, | ||
| transactionId: null, | ||
| onClose: jest.fn() | ||
| }; | ||
|
|
||
| renderWithProviders(<RegisterModal {...props} />); | ||
|
|
||
| await userEvent.click(screen.getByRole('button', { name: /Continue/i })); | ||
|
|
||
| expect(props.onClose.mock.calls).toHaveLength(1); | ||
|
|
||
| }); | ||
|
|
||
| }); |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,107 @@ | ||
| import React from 'react'; | ||
| import { http, HttpResponse, delay } from 'msw'; | ||
| import { setupServer } from 'msw/node'; | ||
| import { screen, fireEvent } from '@testing-library/react'; | ||
| import userEvent from '@testing-library/user-event'; | ||
| import '@testing-library/jest-dom'; | ||
|
|
||
| import { renderWithProviders } from 'utils/test-utils'; | ||
| import RegisterSection from './RegisterSection'; | ||
|
|
||
| import type { Tier } from "store/slices/tiers.slice"; | ||
|
|
||
| const server = setupServer( | ||
| http.get('/ada-usd-price', async () => { | ||
| await delay(150); | ||
| return HttpResponse.json(10.0); | ||
| }), | ||
| ); | ||
|
|
||
| const tier: Tier = { | ||
| id: '1', | ||
| name: 'Sample Tier', | ||
| subtitle: 'Sample Tier', | ||
| features: [], | ||
| usdPrice: 100, | ||
| enabled: true | ||
| }; | ||
|
|
||
| beforeAll(() => server.listen()); | ||
| afterEach(() => server.resetHandlers()); | ||
| afterAll(() => server.close()); | ||
|
|
||
| describe('Landing page > Register section', () => { | ||
|
|
||
| test('should render the register section', async () => { | ||
|
|
||
| renderWithProviders(<RegisterSection tier={tier} onSubmit={() => {}} />); | ||
|
|
||
| expect(screen.queryByText('Auditor profile')).toBeInTheDocument(); | ||
|
|
||
| }); | ||
|
|
||
| test('should render the subscription price correctly', async () => { | ||
|
|
||
| renderWithProviders(<RegisterSection tier={tier} onSubmit={() => {}} />); | ||
|
|
||
| const submitButton = await screen.findByText(/10.00/i); | ||
|
|
||
| expect(submitButton).toBeInTheDocument(); | ||
|
|
||
| }); | ||
|
|
||
| test('should render disabled form if the fetched price is zero', async () => { | ||
|
|
||
| setupServer( | ||
| http.get('/ada-usd-price', async () => { | ||
| await delay(150); | ||
| return HttpResponse.json(0.0); | ||
| }), | ||
| ); | ||
|
|
||
| renderWithProviders(<RegisterSection tier={tier} onSubmit={() => {}} />); | ||
|
|
||
| const submitButton = await screen.findByText(/0.00/i); | ||
|
|
||
| expect(submitButton).toBeDisabled(); | ||
|
|
||
| }); | ||
|
|
||
| test('should submit the form successfully', async () => { | ||
|
|
||
| const onSubmit = jest.fn(); | ||
|
|
||
| renderWithProviders(<RegisterSection tier={tier} onSubmit={onSubmit} />); | ||
|
|
||
| const submitButton = await screen.findByText(/10.00/i); | ||
|
|
||
| const companyNameInput = screen.getByRole('textbox', { name: 'Company name *' }); | ||
| const contactEmailInput = screen.getByRole('textbox', { name: 'Contact email *' }); | ||
| const companyEmailInput = screen.getByRole('textbox', { name: 'Company Email *' }); | ||
| const fullNameInput = screen.getByRole('textbox', { name: 'Full name *' }); | ||
| const twitterInput = screen.getByRole('textbox', { name: 'Twitter' }); | ||
| const linkedinInput = screen.getByRole('textbox', { name: 'LinkedIn' }); | ||
| const websiteInput = screen.getByRole('textbox', { name: 'Website' }); | ||
|
|
||
| fireEvent.change(companyNameInput, { target: { value: 'Test company' } }); | ||
| fireEvent.change(contactEmailInput, { target: { value: 'contact@test.com' } }); | ||
| fireEvent.change(companyEmailInput, { target: { value: 'company@test.com' } }); | ||
| fireEvent.change(fullNameInput, { target: { value: 'Full Name' } }); | ||
| fireEvent.change(twitterInput, { target: { value: 'test' } }); | ||
| fireEvent.change(linkedinInput, { target: { value: 'https://www.linkedin.com/profile/test' } }); | ||
| fireEvent.change(websiteInput, { target: { value: 'https://www.test.com' } }); | ||
|
|
||
| await userEvent.click(submitButton); | ||
|
|
||
| expect(onSubmit.mock.calls).toHaveLength(1); | ||
| expect(onSubmit.mock.calls[0][0].companyName).toBe('Test company'); | ||
| expect(onSubmit.mock.calls[0][0].contactEmail).toBe('contact@test.com'); | ||
| expect(onSubmit.mock.calls[0][0].email).toBe('company@test.com'); | ||
| expect(onSubmit.mock.calls[0][0].fullName).toBe('Full Name'); | ||
| expect(onSubmit.mock.calls[0][0].twitter).toBe('test'); | ||
| expect(onSubmit.mock.calls[0][0].linkedin).toBe('https://www.linkedin.com/profile/test'); | ||
| expect(onSubmit.mock.calls[0][0].website).toBe('https://www.test.com'); | ||
|
|
||
| }); | ||
|
|
||
| }); |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -41,9 +41,6 @@ const initialState: WalletConnectionState = { | |
| // Add this export to your walletConnectionSlice file | ||
| export { initialState as walletConnectionInitialState }; | ||
|
|
||
|
|
||
| const CardanoNS = window.cardano; | ||
|
|
||
| type StakeAddressHex = string; | ||
| type StakeAddressBech32 = `stake${string}`; | ||
| type ChangeAddressBech32 = `addr${string}`; | ||
|
|
@@ -69,6 +66,8 @@ const getAddresses = async (wallet: any): Promise<[StakeAddressHex, StakeAddress | |
| } | ||
|
|
||
| export const connectWallet = createAsyncThunk('connectWallet', async (payload: { walletName: string }, thunkApi) => { | ||
| const CardanoNS = window.cardano; | ||
|
|
||
|
Comment on lines
+69
to
+70
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Tip Codebase Verification Review SummaryThe review comment suggested that localizing the Verification ResultsThe executed script searched for occurrences of ConclusionGiven that Action Required: Analysis chainLocalizing the Scripts ExecutedThe following scripts were executed for the analysis: Script: #!/bin/bash
# Verify that `CardanoNS` is not used globally elsewhere in the codebase that might be affected by this change.
rg --type ts "CardanoNS" --glob '!src/store/slices/walletConnection.slice.ts'
Length of output: 762 |
||
| try { | ||
| const { walletName } = payload; | ||
| const wallet = await CardanoNS[walletName].enable(); | ||
|
|
@@ -115,6 +114,7 @@ export const connectWallet = createAsyncThunk('connectWallet', async (payload: { | |
| }); | ||
|
|
||
| export const startListenWalletChanges = createAsyncThunk('listenWalletChanges', async (payload: any, { dispatch, getState }) => { | ||
| const CardanoNS = window.cardano; | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Tip Codebase Verification Review SummaryThe review comment approved the localization of the Verification FindingsThe script output indicates that ConclusionGiven the usage of Action Required: Analysis chainLocalizing the Scripts ExecutedThe following scripts were executed for the analysis: Script: #!/bin/bash
# Verify that `CardanoNS` is not used globally elsewhere in the codebase that might be affected by this change.
rg --type ts "CardanoNS" --glob '!src/store/slices/walletConnection.slice.ts'
Length of output: 762 |
||
| const { authToken, networkId } = (getState() as RootState).session; | ||
| const { wallet, walletName, stakeAddress } = (getState() as RootState).walletConnection; | ||
|
|
||
|
|
@@ -151,7 +151,6 @@ export const startListenWalletChanges = createAsyncThunk('listenWalletChanges', | |
| } | ||
| } | ||
| } catch (error) { | ||
| console.log(error); | ||
| await new Promise(resolve => setTimeout(resolve, 1000)); | ||
| } | ||
| } | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.