forked from tari-project/tari
-
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.
* Add Icons and statuses to MiningBox, initialize WalletPasswordWizard * Password Wizard
- Loading branch information
1 parent
d7f3d91
commit 9c9d264
Showing
23 changed files
with
444 additions
and
26 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
48 changes: 48 additions & 0 deletions
48
applications/launchpad/gui-react/src/components/Callout/Callout.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,48 @@ | ||
import { render, screen } from '@testing-library/react' | ||
import { ThemeProvider } from 'styled-components' | ||
|
||
import Callout from '.' | ||
import themes from '../../styles/themes' | ||
|
||
describe('Callout', () => { | ||
it('should render without crashing when children is a string', () => { | ||
const testText = 'The callout test text' | ||
render( | ||
<ThemeProvider theme={themes.light}> | ||
<Callout>{testText}</Callout> | ||
</ThemeProvider>, | ||
) | ||
|
||
const el = screen.getByText(testText) | ||
expect(el).toBeInTheDocument() | ||
}) | ||
|
||
it('should render without crashing when children is a React Node', () => { | ||
const testId = 'the-callout-test-id' | ||
const testText = 'The callout test text' | ||
const testCmp = <span data-testid={testId}>{testText}</span> | ||
render( | ||
<ThemeProvider theme={themes.light}> | ||
<Callout>{testCmp}</Callout> | ||
</ThemeProvider>, | ||
) | ||
|
||
const elText = screen.getByText(testText) | ||
expect(elText).toBeInTheDocument() | ||
|
||
const elCmp = screen.getByTestId(testId) | ||
expect(elCmp).toBeInTheDocument() | ||
}) | ||
|
||
it('should render without crashing when inverted prop is used', () => { | ||
const testText = 'The callout test text' | ||
render( | ||
<ThemeProvider theme={themes.light}> | ||
<Callout inverted={true}>{testText}</Callout> | ||
</ThemeProvider>, | ||
) | ||
|
||
const el = screen.getByText(testText) | ||
expect(el).toBeInTheDocument() | ||
}) | ||
}) |
38 changes: 38 additions & 0 deletions
38
applications/launchpad/gui-react/src/components/Callout/index.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,38 @@ | ||
import Text from '../Text' | ||
import { CalloutIcon, StyledCallout } from './styles' | ||
|
||
import { CalloutProps } from './types' | ||
|
||
/** | ||
* Callout component that renders styled box with proper icon. | ||
* NOTE: It supports only the `warning` type for now. | ||
* | ||
* @param {CalloutType} [type='warning'] - the callout type/style. | ||
* @param {ReactNode} [icon] - override the icon. | ||
* @param {string | ReactNode} children - the callout content (text or ReactNode). | ||
*/ | ||
const Callout = ({ | ||
type = 'warning', | ||
icon = '⚠️', | ||
inverted, | ||
children, | ||
}: CalloutProps) => { | ||
let content = children | ||
|
||
if (typeof children === 'string') { | ||
content = ( | ||
<Text style={{ display: 'inline' }} type='microMedium'> | ||
{children} | ||
</Text> | ||
) | ||
} | ||
|
||
return ( | ||
<StyledCallout $type={type} $inverted={inverted}> | ||
<CalloutIcon>{icon}</CalloutIcon> | ||
{content} | ||
</StyledCallout> | ||
) | ||
} | ||
|
||
export default Callout |
23 changes: 23 additions & 0 deletions
23
applications/launchpad/gui-react/src/components/Callout/styles.ts
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,23 @@ | ||
import styled from 'styled-components' | ||
import { CalloutType } from './types' | ||
|
||
export const StyledCallout = styled.div<{ | ||
$type: CalloutType | ||
$inverted?: boolean | ||
}>` | ||
padding: ${({ theme }) => | ||
`${theme.spacingVertical(0.62)} ${theme.spacingHorizontal(0.5)}`}; | ||
background: ${({ theme, $inverted }) => { | ||
return $inverted ? theme.inverted.backgroundSecondary : theme.warning | ||
}}}; | ||
color: ${({ theme, $inverted }) => { | ||
return $inverted ? theme.inverted.warningText : theme.warningText | ||
}}; | ||
border-radius: ${({ theme }) => theme.borderRadius(0.5)}; | ||
` | ||
|
||
export const CalloutIcon = styled.span` | ||
display: inline-block; | ||
font-size: 12px; | ||
margin-right: ${({ theme }) => theme.spacingHorizontal(0.15)}; | ||
` |
10 changes: 10 additions & 0 deletions
10
applications/launchpad/gui-react/src/components/Callout/types.ts
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 { ReactNode } from 'react' | ||
|
||
export type CalloutType = 'warning' | ||
|
||
export interface CalloutProps { | ||
type?: CalloutType | ||
icon?: string | ReactNode | ||
inverted?: boolean | ||
children: string | ReactNode | ||
} |
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
28 changes: 24 additions & 4 deletions
28
applications/launchpad/gui-react/src/containers/MiningContainer/MiningBoxTari/index.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
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
66 changes: 66 additions & 0 deletions
66
...-react/src/containers/WalletPasswordWizard/WalletPasswordForm/WalletPasswordForm.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,66 @@ | ||
import { act, fireEvent, render, screen } from '@testing-library/react' | ||
import { ThemeProvider } from 'styled-components' | ||
|
||
import WalletPasswordForm from '.' | ||
|
||
import themes from '../../../styles/themes' | ||
|
||
describe('WalletPasswordForm', () => { | ||
it('should render without crashing when custom submit button text is given', () => { | ||
const testSubmitBtnText = 'The test text of submit button' | ||
const submitMock = jest.fn() | ||
|
||
render( | ||
<ThemeProvider theme={themes.light}> | ||
<WalletPasswordForm | ||
onSubmit={submitMock} | ||
submitBtnText={testSubmitBtnText} | ||
/> | ||
</ThemeProvider>, | ||
) | ||
const el = screen.getByText(testSubmitBtnText) | ||
expect(el).toBeInTheDocument() | ||
}) | ||
|
||
it('should submit form only if password is set', async () => { | ||
const testPassword = 'pass' | ||
const submitMock = jest.fn() | ||
|
||
await act(async () => { | ||
render( | ||
<ThemeProvider theme={themes.light}> | ||
<WalletPasswordForm onSubmit={submitMock} /> | ||
</ThemeProvider>, | ||
) | ||
}) | ||
|
||
const elInput = screen.getByTestId('password-input') | ||
expect(elInput).toBeInTheDocument() | ||
|
||
const elSubmitBtn = screen.getByTestId('wallet-password-wizard-submit-btn') | ||
expect(elSubmitBtn).toBeInTheDocument() | ||
|
||
// Firstly, the form cannot be submitted if password input is empty: | ||
await act(async () => { | ||
fireEvent.click(elSubmitBtn) | ||
}) | ||
|
||
expect(submitMock).toHaveBeenCalledTimes(0) | ||
|
||
// Now, set the password... | ||
await act(async () => { | ||
fireEvent.input(elInput, { target: { value: testPassword } }) | ||
}) | ||
|
||
// ...check the presence of the password in the input... | ||
expect((elInput as HTMLInputElement).value).toBe(testPassword) | ||
|
||
// ...and submit form again: | ||
await act(async () => { | ||
fireEvent.click(elSubmitBtn) | ||
}) | ||
|
||
expect(submitMock).toHaveBeenCalledWith({ password: testPassword }) | ||
expect(submitMock).toHaveBeenCalledTimes(1) | ||
}) | ||
}) |
Oops, something went wrong.