Skip to content

Commit f4762c2

Browse files
committed
test: update test files
1 parent 7147821 commit f4762c2

File tree

8 files changed

+654
-611
lines changed

8 files changed

+654
-611
lines changed

tests/App.test.tsx

Lines changed: 46 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -6,49 +6,68 @@ import App from '../src/App';
66
describe('App Component', () => {
77
it('renders without crashing', () => {
88
render(<App />);
9-
expect(screen.getByRole('button', { name: /dark mode/i })).toBeInTheDocument();
9+
expect(screen.getByTestId('app-container')).toBeInTheDocument();
1010
});
1111

1212
it('renders the MultiLevelTable component', () => {
1313
render(<App />);
1414
// Check for table headers
15+
expect(screen.getByText('Resource Type')).toBeInTheDocument();
1516
expect(screen.getByText('Name')).toBeInTheDocument();
16-
expect(screen.getByText('Value')).toBeInTheDocument();
1717
expect(screen.getByText('Status')).toBeInTheDocument();
18+
expect(screen.getByText('Orchestration')).toBeInTheDocument();
1819
});
1920

20-
it('toggles theme when theme button is clicked', () => {
21+
it('renders table title and subtitle', () => {
2122
render(<App />);
22-
const themeButton = screen.getByRole('button', { name: /dark mode/i });
23-
const appDiv = screen.getByTestId('app-container');
24-
25-
// Initial state should be light theme
26-
expect(appDiv).toHaveStyle({ backgroundColor: '#ffffff' });
27-
28-
// Click to toggle to dark theme
29-
fireEvent.click(themeButton);
30-
expect(appDiv).toHaveStyle({ backgroundColor: '#212529' });
31-
32-
// Click again to toggle back to light theme
33-
fireEvent.click(themeButton);
34-
expect(appDiv).toHaveStyle({ backgroundColor: '#ffffff' });
23+
expect(screen.getByText('Multi-Level Table Demo')).toBeInTheDocument();
24+
expect(screen.getByText('A comprehensive table showing resource management')).toBeInTheDocument();
25+
});
26+
27+
it('renders search input', () => {
28+
render(<App />);
29+
const searchInput = screen.getByPlaceholderText('Search');
30+
expect(searchInput).toBeInTheDocument();
3531
});
3632

37-
it('renders parent items correctly', () => {
33+
it('renders export and filter buttons', () => {
3834
render(<App />);
39-
// Check for some parent items
40-
expect(screen.getByText('Parent 1')).toBeInTheDocument();
41-
expect(screen.getByText('Parent 2')).toBeInTheDocument();
35+
expect(screen.getByText('Export')).toBeInTheDocument();
36+
expect(screen.getByText('Filter')).toBeInTheDocument();
4237
});
4338

44-
it('renders status cells with correct colors', () => {
39+
it('renders sample data items', () => {
4540
render(<App />);
46-
const activeStatus = screen.getAllByText('Active')[0];
47-
const inactiveStatus = screen.getAllByText('Inactive')[0];
48-
const pendingStatus = screen.getAllByText('Pending')[0];
41+
// Check for some sample data items
42+
expect(screen.getByText('web-service')).toBeInTheDocument();
43+
expect(screen.getByText('mobile-app-backend')).toBeInTheDocument();
44+
expect(screen.getByText('analytics-platform')).toBeInTheDocument();
45+
});
4946

50-
expect(activeStatus).toHaveStyle({ color: '#2ecc71' });
51-
expect(inactiveStatus).toHaveStyle({ color: '#e74c3c' });
52-
expect(pendingStatus).toHaveStyle({ color: '#f1c40f' });
47+
it('renders status cells', () => {
48+
render(<App />);
49+
// Check that status badges are rendered (use getAllByText since there are multiple)
50+
const activeElements = screen.getAllByText('Active');
51+
const inactiveElements = screen.getAllByText('Inactive');
52+
const pendingElements = screen.getAllByText('Pending');
53+
54+
expect(activeElements.length).toBeGreaterThan(0);
55+
expect(inactiveElements.length).toBeGreaterThan(0);
56+
expect(pendingElements.length).toBeGreaterThan(0);
57+
});
58+
59+
it('renders resource types', () => {
60+
render(<App />);
61+
// Use getAllByText since there are multiple Application elements
62+
const applicationElements = screen.getAllByText('Application');
63+
expect(applicationElements.length).toBeGreaterThan(0);
64+
expect(screen.getByText('Redis')).toBeInTheDocument();
65+
});
66+
67+
it('renders orchestration values', () => {
68+
render(<App />);
69+
// Use getAllByText since there are multiple ECS elements
70+
const ecsElements = screen.getAllByText('ECS');
71+
expect(ecsElements.length).toBeGreaterThan(0);
5372
});
5473
});

tests/components/ExpandIcon.test.tsx

Lines changed: 66 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,52 +1,95 @@
11
import React from 'react';
2-
import { describe, it, expect } from 'vitest';
2+
3+
import { describe, it, expect, vi } from 'vitest';
34
import { render, screen } from '@testing-library/react';
5+
46
import '@testing-library/jest-dom';
57

6-
import { ExpandIcon } from '../../src/components/icons';
8+
import { ExpandIcon } from '../../src/components/icons/ExpandIcon';
79
import type { ThemeProps } from '../../src/types/theme';
810

9-
describe('ExpandIcon', () => {
10-
const mockTheme: ThemeProps = {
11-
expandIcon: {
12-
color: '#000000',
13-
},
14-
};
11+
const mockTheme: ThemeProps = {
12+
colors: {
13+
primaryColor: '#5D5FEF',
14+
textColor: '#262626',
15+
borderColor: '#E5E5E5',
16+
},
17+
expandIcon: {
18+
color: '#000000',
19+
},
20+
};
1521

16-
it('renders expanded icon when isExpanded is true', () => {
22+
describe('ExpandIcon', () => {
23+
it('applies correct transform for expanded state', () => {
1724
render(<ExpandIcon isExpanded theme={mockTheme} mode="expand" />);
18-
const icon = screen.getByRole('img', { hidden: true });
19-
expect(icon).toBeInTheDocument();
20-
expect(icon.closest('.expand-icon')).toHaveClass('expand-icon');
25+
26+
const expandIcon = document.querySelector('.expand-icon');
27+
expect(expandIcon).toHaveStyle({ transform: 'rotate(90deg)' });
2128
});
2229

23-
it('renders collapsed icon when isExpanded is false', () => {
30+
it('applies correct transform for collapsed state', () => {
2431
render(<ExpandIcon isExpanded={false} theme={mockTheme} mode="expand" />);
32+
33+
const expandIcon = document.querySelector('.expand-icon');
34+
expect(expandIcon).toHaveStyle({ transform: 'rotate(0deg)' });
35+
});
36+
37+
it('renders SVG element', () => {
38+
render(<ExpandIcon isExpanded theme={mockTheme} mode="expand" />);
39+
40+
const svg = document.querySelector('svg');
41+
expect(svg).toBeInTheDocument();
42+
expect(svg).toHaveAttribute('viewBox', '0 0 24 24');
43+
});
2544

26-
const icon = screen.getByRole('img', { hidden: true });
27-
expect(icon).toBeInTheDocument();
28-
expect(icon.closest('.expand-icon')).toHaveClass('expand-icon');
45+
it('renders expand icon with SVG', () => {
46+
render(<ExpandIcon isExpanded theme={mockTheme} mode="expand" />);
47+
48+
const svg = document.querySelector('svg');
49+
expect(svg).toBeInTheDocument();
50+
expect(svg).toHaveAttribute('width', '24');
51+
expect(svg).toHaveAttribute('height', '24');
52+
});
53+
54+
it('renders collapsed icon with SVG', () => {
55+
render(<ExpandIcon isExpanded={false} theme={mockTheme} mode="expand" />);
56+
57+
const svg = document.querySelector('svg');
58+
expect(svg).toBeInTheDocument();
59+
expect(svg).toHaveAttribute('width', '24');
60+
expect(svg).toHaveAttribute('height', '24');
2961
});
3062

3163
it('applies custom theme color when provided', () => {
3264
const customTheme: ThemeProps = {
65+
...mockTheme,
3366
expandIcon: {
3467
color: '#FF0000',
3568
},
3669
};
3770

3871
render(<ExpandIcon isExpanded theme={customTheme} mode="expand" />);
39-
40-
const icon = screen.getByRole('img', { hidden: true });
41-
expect(icon).toBeInTheDocument();
72+
73+
const svg = document.querySelector('svg');
74+
expect(svg).toBeInTheDocument();
75+
expect(svg).toHaveAttribute('width', '24');
76+
expect(svg).toHaveAttribute('height', '24');
4277
});
4378

4479
it('renders without theme color when not provided', () => {
45-
const themeWithoutColor: ThemeProps = {};
80+
const themeWithoutColor: ThemeProps = {
81+
colors: {
82+
primaryColor: '#5D5FEF',
83+
textColor: '#262626',
84+
borderColor: '#E5E5E5',
85+
},
86+
};
4687

4788
render(<ExpandIcon isExpanded theme={themeWithoutColor} mode="expand" />);
48-
49-
const icon = screen.getByRole('img', { hidden: true });
50-
expect(icon).toBeInTheDocument();
89+
90+
const svg = document.querySelector('svg');
91+
expect(svg).toBeInTheDocument();
92+
expect(svg).toHaveAttribute('width', '24');
93+
expect(svg).toHaveAttribute('height', '24');
5194
});
5295
});

0 commit comments

Comments
 (0)