Skip to content

Commit 40d122c

Browse files
authored
Adding unit tests for PowerSummaryTable.js (#257)
1 parent b2b7ceb commit 40d122c

File tree

1 file changed

+23
-0
lines changed

1 file changed

+23
-0
lines changed

src/tests/Tables_tests/PowerSummaryTable.test.js

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,4 +70,27 @@ describe('PowerSummaryTable Component', () => {
7070
expect(within(noMessageRow).queryByText('Warning message')).toBeNull();
7171
expect(within(noMessageRow).queryByText('Error message')).toBeNull();
7272
});
73+
74+
test('total and percent values match sum of data', () => {
75+
render(<PowerSummaryTable title="Power Summary" data={mockData} total={60} percent={80} />);
76+
77+
const displayedTotal = screen.getByText((content) => content.includes('60.00') && content.includes('W'));
78+
expect(displayedTotal).toBeInTheDocument();
79+
80+
const progressBar = screen.getByRole('progressbar');
81+
expect(progressBar).toHaveAttribute('value', '80');
82+
expect(progressBar).toHaveAttribute('max', '100');
83+
});
84+
85+
test('renders correctly with no data entries', () => {
86+
render(<PowerSummaryTable title="Power Summary" data={[]} total={0} percent={0} />);
87+
88+
expect(screen.getByText('Power Summary')).toBeInTheDocument();
89+
90+
expect(screen.getByText('0.00 W')).toBeInTheDocument();
91+
expect(screen.getByText('0 %')).toBeInTheDocument();
92+
93+
const progressBar = screen.getByRole('progressbar');
94+
expect(progressBar).toHaveAttribute('value', '0');
95+
});
7396
});

0 commit comments

Comments
 (0)