Skip to content

Commit 72f8c81

Browse files
test(sonar): add sample test for colors
1 parent 3310c5e commit 72f8c81

File tree

3 files changed

+33
-3
lines changed

3 files changed

+33
-3
lines changed

src/components/colors.test.tsx

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
import { render, screen, within } from '@testing-library/react-native';
2+
import React from 'react';
3+
4+
import { colors } from '@/ui';
5+
6+
import { Colors } from './colors';
7+
8+
describe('Colors component', () => {
9+
it('should render the Title component', () => {
10+
render(<Colors />);
11+
expect(screen.getByText('Colors')).toBeTruthy();
12+
});
13+
14+
it('should render Color components for each color group', () => {
15+
render(<Colors />);
16+
const colorNames = Object.keys(colors) as (keyof typeof colors)[];
17+
18+
colorNames.forEach((name: keyof typeof colors) => {
19+
if (typeof colors[name] !== 'string') {
20+
const colorTextLabel = screen.getByText(name.toUpperCase());
21+
expect(colorTextLabel).toBeTruthy();
22+
const list = screen.getByTestId(`color-list-${name}`);
23+
24+
Object.entries(colors[name]).forEach(([color]) => {
25+
within(list).getByText(color);
26+
});
27+
}
28+
});
29+
});
30+
});

src/components/colors.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ const Color = ({ name }: { name: ColorName }) => {
2222
return null;
2323
}
2424
return (
25-
<View className="pt-2">
25+
<View className="pt-2" testID={`color-list-${name}`}>
2626
<Text className="font-medium">{name.toUpperCase()}</Text>
2727
<View className="flex-row flex-wrap content-between justify-around ">
2828
{Object.entries(colors[name]).map(([key, value]) => {

src/core/use-theme-config.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import { useColorScheme } from 'nativewind';
77

88
import colors from '@/ui/colors';
99

10-
const DarkTheme: Theme = {
10+
export const DarkTheme: Theme = {
1111
..._DarkTheme,
1212
colors: {
1313
..._DarkTheme.colors,
@@ -19,7 +19,7 @@ const DarkTheme: Theme = {
1919
},
2020
};
2121

22-
const LightTheme: Theme = {
22+
export const LightTheme: Theme = {
2323
...DefaultTheme,
2424
colors: {
2525
...DefaultTheme.colors,

0 commit comments

Comments
 (0)