-
Notifications
You must be signed in to change notification settings - Fork 82
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 #2018 from SpareBank1/system-messages-as-ts
feat(ffe-system-message-react): rewrite to ts
- 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
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.