This repository was archived by the owner on May 13, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 30
feat: added testcase and popup #187
Merged
hubert-deriv
merged 15 commits into
binary-com:master
from
utkarsha-deriv:utkarsha/display-popup-upon-token-creation
Jul 31, 2023
Merged
Changes from all commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
69d4132
feat: added testcase and popup
utkarsha-deriv 5b6e9a6
test: test cov
utkarsha-deriv 42d21d9
test: testcases and refactoring
utkarsha-deriv c54abd4
Merge branch 'binary-com:master' into utkarsha/display-popup-upon-tok…
utkarsha-deriv 70987e0
chore: fix warning
utkarsha-deriv b40eee9
Merge branch 'utkarsha/display-popup-upon-token-creation' of github.c…
utkarsha-deriv b0e6fa8
feat: disable btn on empty token
utkarsha-deriv 834981c
test: testcase for disable btn state
utkarsha-deriv 13b9765
chore: add validation for string starting with space and update testcase
utkarsha-deriv e8ae255
feat: disable whitespace beginning and disable btn with space in end …
utkarsha-deriv aceca5f
Merge branch 'master' into utkarsha/display-popup-upon-token-creation
utkarsha-deriv ef1adf8
fix: check for string starting with whitespace
utkarsha-deriv 2651ce5
Merge branch 'master' into utkarsha/display-popup-upon-token-creation
utkarsha-deriv 06d6b8e
chore: update with recent changes
utkarsha-deriv 39ac8e4
chore: improvements
utkarsha-deriv File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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
46 changes: 46 additions & 0 deletions
46
...nents/Dialogs/TokenCreationDialogSuccess/__tests__/token-creation-dialog-success.test.tsx
This file contains hidden or 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,46 @@ | ||
| import React from 'react'; | ||
| import TokenCreationDialogSuccess from '..'; | ||
| import { screen, render } from '@testing-library/react'; | ||
| import userEvent from '@testing-library/user-event'; | ||
|
|
||
| describe('Token Creation Dialog', () => { | ||
| it('Should display correct title on the modal', () => { | ||
| render(<TokenCreationDialogSuccess setToggleModal={jest.fn()} />); | ||
|
|
||
| const title = screen.getByText(/Token created successfully/i); | ||
| expect(title).toHaveTextContent('Token created successfully'); | ||
| }); | ||
|
|
||
| it('Should display correct content on the modal', () => { | ||
| render(<TokenCreationDialogSuccess setToggleModal={jest.fn()} />); | ||
|
|
||
| const textContent = screen.getByText(/Your API token is ready to be used./i); | ||
| expect(textContent).toHaveTextContent('Your API token is ready to be used.'); | ||
| }); | ||
|
|
||
| it('Should close the modal on OK button click', async () => { | ||
| const mockOnClose = jest.fn(); | ||
|
|
||
| render(<TokenCreationDialogSuccess setToggleModal={mockOnClose} />); | ||
|
|
||
| const okButton = screen.getByRole('button', { name: /OK/i }); | ||
| expect(okButton).toBeInTheDocument(); | ||
|
|
||
| await userEvent.click(okButton); | ||
|
|
||
| expect(mockOnClose).toHaveBeenCalledTimes(1); | ||
| }); | ||
|
|
||
| it('Should close the modal on cross button click', async () => { | ||
| const mockOnClose = jest.fn(); | ||
|
|
||
| render(<TokenCreationDialogSuccess setToggleModal={mockOnClose} />); | ||
| const modal = screen.getByText('Your API token is ready to be used.'); | ||
|
|
||
| const crossButton = screen.getByTestId('close-button'); | ||
| await userEvent.click(crossButton); | ||
|
|
||
| expect(modal).not.toBeInTheDocument(); | ||
| expect(mockOnClose).toHaveBeenCalled(); | ||
| }); | ||
| }); |
50 changes: 50 additions & 0 deletions
50
src/features/dashboard/components/Dialogs/TokenCreationDialogSuccess/index.tsx
This file contains hidden or 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,50 @@ | ||
| import React, { useCallback } from 'react'; | ||
| import { Button, Modal } from '@deriv/ui'; | ||
| import styles from './token-creation-dialog-sucess.module.scss'; | ||
|
|
||
| type ITokenCreationDialogSuccessProps = { | ||
| setToggleModal: React.Dispatch<React.SetStateAction<boolean>>; | ||
| }; | ||
|
|
||
| export const TokenCreationDialogSuccess = ({ | ||
| setToggleModal, | ||
| }: ITokenCreationDialogSuccessProps) => { | ||
| const onOpenChange = useCallback( | ||
| (open: boolean) => { | ||
| if (!open) { | ||
| setToggleModal(false); | ||
| } | ||
| }, | ||
| [setToggleModal], | ||
| ); | ||
| const handleToggle = () => { | ||
| setToggleModal(false); | ||
| }; | ||
|
|
||
| return ( | ||
| <Modal defaultOpen onOpenChange={onOpenChange}> | ||
| <Modal.Portal> | ||
| <div className='modal-overlay'> | ||
| <Modal.Overlay /> | ||
| <Modal.PageContent | ||
| title={'Token created successfully'} | ||
| has_close_button | ||
| className={styles.wrapper} | ||
| > | ||
| <div className={styles.modal}> | ||
| <p>Your API token is ready to be used.</p> | ||
| </div> | ||
|
|
||
| <div className={styles.buttonWrapper}> | ||
| <Button color='primary' onClick={handleToggle} className={styles.btn}> | ||
| OK | ||
| </Button> | ||
| </div> | ||
| </Modal.PageContent> | ||
| </div> | ||
| </Modal.Portal> | ||
| </Modal> | ||
| ); | ||
| }; | ||
|
|
||
| export default TokenCreationDialogSuccess; | ||
29 changes: 29 additions & 0 deletions
29
...rd/components/Dialogs/TokenCreationDialogSuccess/token-creation-dialog-sucess.module.scss
This file contains hidden or 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 @@ | ||
| @use 'src/styles/utility' as *; | ||
|
|
||
| .wrapper { | ||
| width: rem(44); | ||
| } | ||
|
|
||
| .modal { | ||
| display: flex; | ||
| flex-direction: column; | ||
| gap: 8px; | ||
| padding: rem(0.8) rem(2.4) 0; | ||
| font-size: rem(1.4); | ||
| line-height: rem(2); | ||
| @media (max-width: 992px) { | ||
| padding: 0 0 0 rem(1.6); | ||
| } | ||
| } | ||
|
|
||
| .buttonWrapper { | ||
| display: flex; | ||
| justify-content: flex-end; | ||
| padding: rem(2.4); | ||
| gap: rem(0.8); | ||
|
|
||
| .btn { | ||
| padding: rem(1) rem(1.6); | ||
| border-radius: rem(1.5); | ||
| } | ||
| } |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.