11import React from 'react' ;
2+
23import { fireEvent , render , screen , within } from '@testing-library/react' ;
34import { describe , expect , it , vi } from 'vitest' ;
5+
46import { MultiLevelTable } from '../../src/components/MultiLevelTable' ;
57import type { Column , DataItem } from '../../src/types/types' ;
68// Mock data for testing
@@ -71,6 +73,7 @@ const mockColumns: Column[] = [
7173 ) ,
7274 } ,
7375] ;
76+
7477describe ( 'MultiLevelTable' , ( ) => {
7578 it ( 'renders table with basic data' , ( ) => {
7679 render ( < MultiLevelTable data = { mockData } columns = { mockColumns } /> ) ;
@@ -96,6 +99,7 @@ describe('MultiLevelTable', () => {
9699
97100 // Click expand button for first parent
98101 const expandButton = screen . getAllByRole ( 'button' ) [ 0 ] ;
102+
99103 fireEvent . click ( expandButton ) ;
100104
101105 // Children should now be visible
@@ -113,6 +117,7 @@ describe('MultiLevelTable', () => {
113117
114118 // Click name header to sort
115119 const nameHeader = screen . getByText ( 'Name' ) ;
120+
116121 fireEvent . click ( nameHeader ) ;
117122
118123 // Get all rows and check order
@@ -129,6 +134,7 @@ describe('MultiLevelTable', () => {
129134
130135 // Check if order is reversed
131136 const updatedRows = screen . getAllByRole ( 'row' ) . slice ( 1 ) ;
137+
132138 expect ( within ( updatedRows [ 0 ] ) . getByText ( 'Parent 2' ) ) . toBeInTheDocument ( ) ;
133139 expect ( within ( updatedRows [ 1 ] ) . getByText ( 'Parent 1' ) ) . toBeInTheDocument ( ) ;
134140 } ) ;
@@ -145,6 +151,7 @@ describe('MultiLevelTable', () => {
145151 // Check if pagination controls are present
146152 const nextButton = screen . getByRole ( 'button' , { name : '>' } ) ;
147153 const prevButton = screen . getByRole ( 'button' , { name : '<' } ) ;
154+
148155 expect ( nextButton ) . toBeInTheDocument ( ) ;
149156 expect ( prevButton ) . toBeInTheDocument ( ) ;
150157
@@ -190,6 +197,7 @@ describe('MultiLevelTable', () => {
190197
191198 const table = screen . getByRole ( 'table' ) ;
192199 const tableWrapper = table . closest ( '.table-wrapper' ) ;
200+
193201 expect ( tableWrapper ?. parentElement ) . toHaveStyle ( { backgroundColor : '#f0f0f0' } ) ;
194202 expect ( table ) . toHaveStyle ( { borderColor : '#ff0000' } ) ;
195203 } ) ;
@@ -207,14 +215,15 @@ describe('MultiLevelTable', () => {
207215
208216 // Check if custom render is applied
209217 const customElements = screen . getAllByTestId ( 'custom-name' ) ;
218+
210219 expect ( customElements ) . toHaveLength ( 2 ) ; // Two parent rows
211220 expect ( customElements [ 0 ] ) . toHaveTextContent ( 'Parent 1' ) ;
212221 } ) ;
213222 it ( 'handles filtering' , ( ) => {
214223 render ( < MultiLevelTable data = { mockData } columns = { mockColumns } /> ) ;
215224
216225 // Find filter input
217- const filterInput = screen . getByPlaceholderText ( 'Filter Name ...' ) ;
226+ const filterInput = screen . getByPlaceholderText ( 'Filter name ...' ) ;
218227
219228 // Type in filter
220229 fireEvent . change ( filterInput , { target : { value : 'Parent 1' } } ) ;
@@ -241,10 +250,12 @@ describe('MultiLevelTable', () => {
241250 render ( < MultiLevelTable data = { mockData } columns = { mockColumns } /> ) ;
242251
243252 const statusCells = screen . getAllByTestId ( 'status-cell' ) ;
253+
244254 expect ( statusCells ) . toHaveLength ( 2 ) ; // Two parent rows
245255
246256 // Check if status cells have correct styles
247257 const activeCell = statusCells . find ( cell => cell . textContent === 'Active' ) ;
258+
248259 expect ( activeCell ) . toHaveStyle ( {
249260 backgroundColor : '#e6ffe6' ,
250261 color : '#006600' ,
0 commit comments