-
Notifications
You must be signed in to change notification settings - Fork 83
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(ffe-system-message-react): rewrite to ts
* custom animmation lenght removed * onClose -> onCloseRest BREAKING CHANGE: changed props
- Loading branch information
Showing
16 changed files
with
240 additions
and
301 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -17,19 +17,19 @@ | |
"url": "ssh://[email protected]:SpareBank1/designsystem.git" | ||
}, | ||
"scripts": { | ||
"build": "ffe-buildtool babel", | ||
"build": "ffe-buildtool tsc", | ||
"watch": "ffe-buildtool babel-watch", | ||
"lint": "eslint src", | ||
"lint:fix": "eslint src --fix", | ||
"lint": "eslint src --ext ts,tsx", | ||
"lint:fix": "eslint src --fix --ext ts,tsx", | ||
"test": "ffe-buildtool jest", | ||
"test:watch": "ffe-buildtool jest --watch" | ||
}, | ||
"dependencies": { | ||
"@sb1/ffe-collapse-react": "^4.0.2", | ||
"@sb1/ffe-grid-react": "^13.2.15", | ||
"@sb1/ffe-icons-react": "^10.0.1", | ||
"@sb1/ffe-system-message": "^8.0.17", | ||
"classnames": "^2.3.1", | ||
"prop-types": "^15.7.2" | ||
"classnames": "^2.3.1" | ||
}, | ||
"devDependencies": { | ||
"@sb1/ffe-buildtool": "^0.6.1", | ||
|
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
110 changes: 0 additions & 110 deletions
110
packages/ffe-system-message-react/src/SystemMessage.spec.js
This file was deleted.
Oops, something went wrong.
120 changes: 120 additions & 0 deletions
120
packages/ffe-system-message-react/src/SystemMessage.spec.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,120 @@ | ||
import React from 'react'; | ||
import { | ||
SystemErrorMessage, | ||
SystemErrorMessageProps, | ||
} from './SystemErrorMessage'; | ||
import { SystemInfoMessage, SystemInfoMessageProps } from './SystemInfoMessage'; | ||
import { SystemNewsMessage, SystemNewsMessageProps } from './SystemNewsMessage'; | ||
import { | ||
SystemSuccessMessage, | ||
SystemSuccessMessageProps, | ||
} from './SystemSuccessMessage'; | ||
import { render, screen } from '@testing-library/react'; | ||
|
||
const defaultProps = { | ||
children: <span>Message</span>, | ||
}; | ||
|
||
const TEST_ID_ERROR = 'TEST_ID_ERROR'; | ||
const TEST_ID_INFO = 'TEST_ID_INFO'; | ||
const TEST_ID_NEWS = 'TEST_ID_NEWS'; | ||
const TEST_ID_SUCCESS = 'TEST_ID_SUCCESS'; | ||
|
||
const renderSystemErrorMessage = (props?: SystemErrorMessageProps) => | ||
render( | ||
<SystemErrorMessage | ||
{...defaultProps} | ||
{...props} | ||
data-testid={TEST_ID_ERROR} | ||
/>, | ||
); | ||
const renderSystemInfoMessage = (props?: SystemInfoMessageProps) => | ||
render( | ||
<SystemInfoMessage | ||
{...defaultProps} | ||
{...props} | ||
data-testid={TEST_ID_INFO} | ||
/>, | ||
); | ||
const renderSystemNewsMessage = (props?: SystemNewsMessageProps) => | ||
render( | ||
<SystemNewsMessage | ||
{...defaultProps} | ||
{...props} | ||
data-testid={TEST_ID_NEWS} | ||
/>, | ||
); | ||
const renderSystemSuccessMessage = (props?: SystemSuccessMessageProps) => | ||
render( | ||
<SystemSuccessMessage | ||
{...defaultProps} | ||
{...props} | ||
data-testid={TEST_ID_SUCCESS} | ||
/>, | ||
); | ||
|
||
describe('<SystemMessage />', () => { | ||
it('applies the correct modifier classes to each type', () => { | ||
renderSystemErrorMessage(); | ||
const error = screen.getByTestId(TEST_ID_ERROR); | ||
expect(error.classList.contains('ffe-system-message-wrapper')).toBe( | ||
true, | ||
); | ||
expect( | ||
error.classList.contains('ffe-system-message-wrapper--error'), | ||
).toBe(true); | ||
|
||
renderSystemInfoMessage(); | ||
const info = screen.getByTestId(TEST_ID_INFO); | ||
expect(info.classList.contains('ffe-system-message-wrapper')).toBe( | ||
true, | ||
); | ||
expect( | ||
info.classList.contains('ffe-system-message-wrapper--info'), | ||
).toBe(true); | ||
|
||
renderSystemNewsMessage(); | ||
const news = screen.getByTestId(TEST_ID_NEWS); | ||
expect(news.classList.contains('ffe-system-message-wrapper')).toBe( | ||
true, | ||
); | ||
expect( | ||
news.classList.contains('ffe-system-message-wrapper--news'), | ||
).toBe(true); | ||
|
||
renderSystemSuccessMessage(); | ||
const success = screen.getByTestId(TEST_ID_SUCCESS); | ||
expect(success.classList.contains('ffe-system-message-wrapper')).toBe( | ||
true, | ||
); | ||
expect( | ||
success.classList.contains('ffe-system-message-wrapper--success'), | ||
).toBe(true); | ||
}); | ||
it('renders with correct aria-label', () => { | ||
renderSystemInfoMessage(); | ||
const info = screen.getByTestId(TEST_ID_INFO); | ||
renderSystemSuccessMessage(); | ||
const success = screen.getByTestId(TEST_ID_SUCCESS); | ||
expect(info.getAttribute('aria-label')).toBe('Infomelding'); | ||
expect(success.getAttribute('aria-label')).toBe('Suksessmelding'); | ||
}); | ||
it('renders with role group on container', () => { | ||
renderSystemInfoMessage(); | ||
const info = screen.getByTestId(TEST_ID_INFO); | ||
expect(info.getAttribute('role')).toBe('group'); | ||
}); | ||
|
||
it('renders a Norwegian aria label on the close button by default', () => { | ||
renderSystemInfoMessage(); | ||
expect( | ||
screen.queryByRole('button', { name: 'Lukk' }), | ||
).toBeInTheDocument(); | ||
}); | ||
it('renders an English aria-label if locale is "en"', () => { | ||
renderSystemInfoMessage({ locale: 'en' }); | ||
expect( | ||
screen.queryByRole('button', { name: 'Close' }), | ||
).toBeInTheDocument(); | ||
}); | ||
}); |
Oops, something went wrong.