-
Notifications
You must be signed in to change notification settings - Fork 22
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[CLD-589] As a ‘Developer’, I want to see a message appear when I acc…
…ess the Apps and API pages (#233) * [CLD-589] As a ‘Developer’, I want to see a message appear when I access the Apps and API pages * Fix as comment
- Loading branch information
1 parent
d7451b5
commit b5a0f54
Showing
8 changed files
with
100 additions
and
0 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
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
23 changes: 23 additions & 0 deletions
23
src/components/ui/__tests__/__snapshots__/sandbox-pop-up.tsx.snap
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 @@ | ||
// Jest Snapshot v1, https://goo.gl/fbAQLP | ||
|
||
exports[`SandboxPopUp should match snapshot with default 1`] = ` | ||
<div> | ||
<ToastMessage | ||
message="Data in the dev portal APIs is sandbox and is regularly refreshed. You should not use these feeds for production apps, they are for development purposes only." | ||
onCloseToast={[Function]} | ||
variant="info" | ||
visible={false} | ||
/> | ||
</div> | ||
`; | ||
|
||
exports[`SandboxPopUp should match snapshot with passed props 1`] = ` | ||
<div> | ||
<ToastMessage | ||
message="mess" | ||
onCloseToast={[Function]} | ||
variant="info" | ||
visible={false} | ||
/> | ||
</div> | ||
`; |
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,32 @@ | ||
import * as React from 'react' | ||
import { shallow } from 'enzyme' | ||
import { popUp, SandboxPopUp, HALF_SECOND } from '../sandbox-pop-up' | ||
|
||
const setOpen = jest.fn() | ||
jest.useFakeTimers() | ||
describe('popUp', () => { | ||
afterEach(() => { | ||
jest.clearAllMocks() | ||
jest.clearAllTimers() | ||
}) | ||
it('should call setTimeout if loading = false', () => { | ||
const fn = popUp(setOpen, false) | ||
fn() | ||
expect(setTimeout).toHaveBeenCalledTimes(1) | ||
expect(setTimeout).toHaveBeenCalledWith(expect.any(Function), HALF_SECOND) | ||
}) | ||
it('should not call setTimeout if loading = true', () => { | ||
const fn = popUp(setOpen, true) | ||
fn() | ||
expect(setTimeout).not.toHaveBeenCalled() | ||
}) | ||
}) | ||
|
||
describe('SandboxPopUp', () => { | ||
it('should match snapshot with default', () => { | ||
expect(shallow(<SandboxPopUp />)).toMatchSnapshot() | ||
}) | ||
it('should match snapshot with passed props', () => { | ||
expect(shallow(<SandboxPopUp loading={true} message="mess" />)).toMatchSnapshot() | ||
}) | ||
}) |
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 * as React from 'react' | ||
import { ToastMessage } from '@reapit/elements' | ||
import styles from '@/styles/blocks/sandbox-pop-up.scss?mod' | ||
|
||
export const HALF_SECOND = 500 | ||
|
||
export const popUp = (setOpen, loading) => () => { | ||
if (!loading) setTimeout(setOpen, HALF_SECOND) | ||
} | ||
|
||
export const SandboxPopUp = ({ | ||
loading = false, | ||
message = 'Data in the dev portal APIs is sandbox and is regularly refreshed. You should not use these feeds for production apps, they are for development purposes only.' | ||
}) => { | ||
const [isOpen, setIsOpen] = React.useState<boolean>(false) | ||
const setOpen = React.useCallback(setIsOpen.bind(null, true), [setIsOpen]) | ||
const setClose = React.useCallback(setIsOpen.bind(null, false), [setIsOpen]) | ||
|
||
React.useEffect(popUp(setOpen, loading), [loading]) | ||
|
||
return ( | ||
<div className={styles['wrap-pop-up']}> | ||
<ToastMessage visible={isOpen} message={message} variant="info" onCloseToast={setClose} /> | ||
</div> | ||
) | ||
} |
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,6 @@ | ||
.wrap-pop-up { | ||
transform: translateX(-2rem); | ||
width: 100vw; | ||
position: fixed; | ||
bottom: 0; | ||
} |