-
Notifications
You must be signed in to change notification settings - Fork 23
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
27 changed files
with
569 additions
and
158 deletions.
There are no files selected for viewing
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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,55 @@ | ||
import { render, screen } from '@testing-library/react'; | ||
import AppAlert from './AppAlert'; | ||
import { capitalize, randomText } from '../../utils'; | ||
import { AlertProps } from '@mui/material'; | ||
|
||
const ComponentToTest = AppAlert; | ||
|
||
/** | ||
* Tests for <AppAlert/> component | ||
*/ | ||
describe('<AppAlert/> component', () => { | ||
it('renders itself', () => { | ||
const testId = randomText(8); | ||
render(<ComponentToTest data-testid={testId} />); | ||
const alert = screen.getByTestId(testId); | ||
expect(alert).toBeDefined(); | ||
expect(alert).toHaveAttribute('role', 'alert'); | ||
expect(alert).toHaveClass('MuiAlert-root'); | ||
}); | ||
|
||
it('supports .severity property', () => { | ||
const SEVERITIES = ['error', 'info', 'success', 'warning']; | ||
for (const severity of SEVERITIES) { | ||
const testId = randomText(8); | ||
const severity = 'success'; | ||
render( | ||
<ComponentToTest | ||
data-testid={testId} | ||
severity={severity} | ||
variant="filled" // Needed to verify exact MUI classes | ||
/> | ||
); | ||
const alert = screen.getByTestId(testId); | ||
expect(alert).toBeDefined(); | ||
expect(alert).toHaveClass(`MuiAlert-filled${capitalize(severity)}`); | ||
} | ||
}); | ||
|
||
it('supports .variant property', () => { | ||
const VARIANTS = ['filled', 'outlined', 'standard']; | ||
for (const variant of VARIANTS) { | ||
const testId = randomText(8); | ||
render( | ||
<ComponentToTest | ||
data-testid={testId} | ||
variant={variant as AlertProps['variant']} | ||
severity="warning" // Needed to verify exact MUI classes | ||
/> | ||
); | ||
const alert = screen.getByTestId(testId); | ||
expect(alert).toBeDefined(); | ||
expect(alert).toHaveClass(`MuiAlert-${variant}Warning`); | ||
} | ||
}); | ||
}); |
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,63 @@ | ||
import { render, screen } from '@testing-library/react'; | ||
import AppIcon, { ICONS } from './AppIcon'; | ||
import { APP_ICON_SIZE } from '../config'; | ||
import { randomColor, randomText } from '../../utils'; | ||
|
||
const ComponentToTest = AppIcon; | ||
|
||
/** | ||
* Tests for <AppIcon/> component | ||
*/ | ||
describe('<AppIcon/> component', () => { | ||
it('renders itself', () => { | ||
const testId = randomText(8); | ||
render(<ComponentToTest data-testid={testId} />); | ||
const svg = screen.getByTestId(testId); | ||
expect(svg).toBeDefined(); | ||
expect(svg).toHaveAttribute('data-icon', 'default'); | ||
expect(svg).toHaveAttribute('size', String(APP_ICON_SIZE)); // default size | ||
expect(svg).toHaveAttribute('height', String(APP_ICON_SIZE)); // default size when .size is not set | ||
expect(svg).toHaveAttribute('width', String(APP_ICON_SIZE)); // default size when .size is not se | ||
}); | ||
|
||
it('supports .color property', () => { | ||
const testId = randomText(8); | ||
const color = randomColor(); // Note: 'rgb(255, 128, 0)' format is used by react-icons npm, so tests may fail | ||
render(<ComponentToTest data-testid={testId} color={color} />); | ||
const svg = screen.getByTestId(testId); | ||
expect(svg).toHaveAttribute('data-icon', 'default'); | ||
// expect(svg).toHaveAttribute('color', color); // TODO: Looks like MUI Icons exclude .color property from <svg> rendering | ||
expect(svg).toHaveStyle(`color: ${color}`); | ||
expect(svg).toHaveAttribute('fill', 'currentColor'); // .fill must be 'currentColor' when .color property is set | ||
}); | ||
|
||
it('supports .icon property', () => { | ||
// Verify that all icons are supported | ||
for (const icon of Object.keys(ICONS)) { | ||
const testId = randomText(8); | ||
render(<ComponentToTest data-testid={testId} icon={icon} />); | ||
const svg = screen.getByTestId(testId); | ||
expect(svg).toBeDefined(); | ||
expect(svg).toHaveAttribute('data-icon', icon.toLowerCase()); | ||
} | ||
}); | ||
|
||
it('supports .size property', () => { | ||
const testId = randomText(8); | ||
const size = Math.floor(Math.random() * 128) + 1; | ||
render(<ComponentToTest data-testid={testId} size={size} />); | ||
const svg = screen.getByTestId(testId); | ||
expect(svg).toHaveAttribute('size', String(size)); | ||
expect(svg).toHaveAttribute('height', String(size)); | ||
expect(svg).toHaveAttribute('width', String(size)); | ||
}); | ||
|
||
it('supports .title property', () => { | ||
const testId = randomText(8); | ||
const title = randomText(16); | ||
render(<ComponentToTest data-testid={testId} title={title} />); | ||
const svg = screen.getByTestId(testId); | ||
expect(svg).toBeDefined(); | ||
expect(svg).toHaveAttribute('title', title); | ||
}); | ||
}); |
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
Oops, something went wrong.