-
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 pull request #25 from user-interviews/feature/UIDS-24-flash-com…
…ponent UIDS-24 Flash message components
- Loading branch information
Showing
22 changed files
with
2,231 additions
and
3,171 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
$ux-navbar-shadow-color: rgba( 0, 0, 0, 0.26 ); | ||
|
||
$ux-box-shadow: 0 2px 5px $ux-navbar-shadow-color; | ||
$ux-box-shadow-light: 0 1px 1px $ux-navbar-shadow-color; | ||
|
||
$ux-box-shadow-card: 0 2px 4px rgba(0,0,0,0.1); | ||
|
||
$ux-box-shadow-top: 0 -2px 5px $ux-navbar-shadow-color; | ||
$ux-box-shadow-top-light: 0 -1px 1px $ux-navbar-shadow-color; |
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,2 @@ | ||
$ui-navbar-height: 3rem; | ||
$ui-navbar-height-mobile: $ui-navbar-height; |
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 |
---|---|---|
@@ -1,4 +1,6 @@ | ||
@import './box_shadow'; | ||
@import './lists'; | ||
@import './navbar'; | ||
@import './palette'; | ||
@import './typography'; | ||
@import './z_stack'; |
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,20 @@ | ||
import React from 'react'; | ||
import { create } from 'react-test-renderer'; | ||
|
||
import Flash from '../../src/Flash/Flash'; | ||
|
||
describe('Flash', () => { | ||
test('no header classes', () => { | ||
const { props } = create(<Flash header messages={[]} />).toJSON(); | ||
|
||
expect(props.className).toContain('Flash'); | ||
expect(props.className).not.toContain('Flash--no-header'); | ||
}); | ||
|
||
test('header classes', () => { | ||
const { props } = create(<Flash header={false} messages={[]} />).toJSON(); | ||
|
||
expect(props.className).toContain('Flash'); | ||
expect(props.className).toContain('Flash--no-header'); | ||
}); | ||
}); |
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 @@ | ||
// Jest Snapshot v1, https://goo.gl/fbAQLP | ||
|
||
exports[`test withFlash it can create a new flash message 1`] = ` | ||
Array [ | ||
<div | ||
className="alert alert-success" | ||
> | ||
<button | ||
className="close" | ||
onClick={[Function]} | ||
type="button" | ||
> | ||
× | ||
</button> | ||
This is just a test... | ||
</div>, | ||
<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,88 @@ | ||
import { renderHook, act } from '@testing-library/react-hooks'; | ||
import { MessageTypes, useFlash } from '../../src/Flash'; | ||
|
||
const GENERATED_UUID = '1234'; | ||
|
||
jest.mock('uuid', () => ( | ||
{ | ||
v4: () => '1234', | ||
} | ||
)); | ||
|
||
describe('useFlash', () => { | ||
test('can set a new message', () => { | ||
const newMessage = 'I want to say something!'; | ||
const { result } = renderHook(() => useFlash()); | ||
|
||
act(() => { | ||
result.current.setMessage(MessageTypes.SUCCESS, newMessage); | ||
}); | ||
|
||
expect(result.current.messages).toEqual([{ | ||
id: GENERATED_UUID, | ||
type: MessageTypes.SUCCESS, | ||
message: newMessage, | ||
}]); | ||
}); | ||
|
||
test('can dismiss an existing message', () => { | ||
const newMessage = 'I want to say something else!'; | ||
const { result } = renderHook(() => useFlash()); | ||
|
||
act(() => { | ||
result.current.setMessage(MessageTypes.SUCCESS, newMessage); | ||
}); | ||
|
||
expect(result.current.messages).toEqual([{ | ||
id: GENERATED_UUID, | ||
type: MessageTypes.SUCCESS, | ||
message: newMessage, | ||
}]); | ||
|
||
act(() => { | ||
result.current.dismissMessage(GENERATED_UUID); | ||
}); | ||
|
||
expect(result.current.messages).toEqual([]); | ||
}); | ||
|
||
test('can set two messages', () => { | ||
const newMessages = ['I want to say', 'so many things']; | ||
const { result } = renderHook(() => useFlash()); | ||
|
||
newMessages.forEach( | ||
(message) => { | ||
act(() => { | ||
result.current.setMessage(MessageTypes.ERROR, message); | ||
}); | ||
}, | ||
); | ||
|
||
expect(result.current.messages).toEqual( | ||
newMessages.map((message) => ({ | ||
id: GENERATED_UUID, | ||
type: MessageTypes.ERROR, | ||
message, | ||
})), | ||
); | ||
}); | ||
|
||
test('can clear all messages', () => { | ||
const messages = ['A new', 'message'].map( | ||
(msg, i) => ({ | ||
id: i, | ||
type: MessageTypes.SUCCESS, | ||
message: msg, | ||
}), | ||
); | ||
|
||
const { result } = renderHook(() => useFlash(messages)); | ||
expect(result.current.messages.length).toEqual(2); | ||
|
||
act(() => { | ||
result.current.clearMessages(); | ||
}); | ||
|
||
expect(result.current.messages.length).toEqual(0); | ||
}); | ||
}); |
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,30 @@ | ||
import React from 'react'; | ||
import { act } from '@testing-library/react-hooks'; | ||
import { create } from 'react-test-renderer'; | ||
|
||
import withFlash from '../../src/Flash/withFlash'; | ||
import { MessageTypes } from '../../src/Flash'; | ||
|
||
jest.mock('react-transition-group', () => ( | ||
{ | ||
CSSTransition: ({ children }) => children, | ||
TransitionGroup: ({ children }) => children, | ||
} | ||
)); | ||
|
||
const WrappedComponent = () => <div />; | ||
|
||
describe('test withFlash', () => { | ||
test('it can create a new flash message', async () => { | ||
const newMessage = 'This is just a test...'; | ||
const ComponentWithFlash = withFlash(WrappedComponent); | ||
const flash = create(<ComponentWithFlash />); | ||
const component = flash.root.findByType(WrappedComponent); | ||
|
||
act(() => { | ||
component.props.setFlashMessage(MessageTypes.SUCCESS, newMessage); | ||
}); | ||
|
||
expect(flash).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
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,17 @@ | ||
import React from 'react'; | ||
import PropTypes from 'prop-types'; | ||
import { CSSTransition } from 'react-transition-group'; | ||
|
||
import './FadeTransition.scss'; | ||
|
||
const FadeTransition = ({ children, ...props }) => ( | ||
<CSSTransition {...props} classNames="FadeTransition" timeout={{ enter: 300, exit: 200 }}> | ||
{children} | ||
</CSSTransition> | ||
); | ||
|
||
FadeTransition.propTypes = { | ||
children: PropTypes.element.isRequired, | ||
}; | ||
|
||
export default FadeTransition; |
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,17 @@ | ||
.FadeTransition-enter { | ||
opacity: 0.01; | ||
|
||
&.FadeTransition-enter-active { | ||
opacity: 1; | ||
transition: opacity 300ms ease-in; | ||
} | ||
} | ||
|
||
.FadeTransition-exit { | ||
opacity: 1; | ||
|
||
&.FadeTransition-exit-active { | ||
opacity: 0.01; | ||
transition: opacity 200ms ease-in; | ||
} | ||
} |
Oops, something went wrong.