diff --git a/test/methods/dataframe/display/display.test.js b/test/methods/dataframe/display/display.test.js index 2d51e64..9646421 100644 --- a/test/methods/dataframe/display/display.test.js +++ b/test/methods/dataframe/display/display.test.js @@ -2,11 +2,6 @@ import { describe, it, expect, vi, beforeEach } from 'vitest'; import { DataFrame } from '../../../../src/core/dataframe/DataFrame.js'; import { display } from '../../../../src/methods/dataframe/display/display.js'; -import { - testWithBothStorageTypes, - createDataFrameWithStorage, -} from '../../../utils/storageTestUtils.js'; - // Mock the module vi.mock('../../../../src/display/web/html.js', () => ({ display: vi.fn(), @@ -21,50 +16,47 @@ describe('DataFrame display method', () => { mockWebDisplay.mockReset(); }); - // Run tests with both storage types - testWithBothStorageTypes((storageType) => { - describe(`with ${storageType} storage`, () => { - // Create test data frame with people data for better readability in tests - const testData = [ - { name: 'Alice', age: 25, city: 'New York' }, - { name: 'Bob', age: 30, city: 'Boston' }, - { name: 'Charlie', age: 35, city: 'Chicago' }, - ]; - - // Create DataFrame with the specified storage type - const df = createDataFrameWithStorage(DataFrame, testData, storageType); + describe('with standard storage', () => { + // Create test data frame with people data for better readability in tests + const testData = [ + { name: 'Alice', age: 25, city: 'New York' }, + { name: 'Bob', age: 30, city: 'Boston' }, + { name: 'Charlie', age: 35, city: 'Chicago' }, + ]; - it('should call the web display function with the frame', () => { - // Call display function directly - const displayFn = display(); - displayFn(df); + // Create DataFrame using fromRows + const df = DataFrame.fromRows(testData); - // Check that the web display function was called with the frame - expect(mockWebDisplay).toHaveBeenCalledWith(df, expect.any(Object)); - }); + it('should call the web display function with the frame', () => { + // Call display function directly + const displayFn = display(); + displayFn(df); - it('should return the frame for method chaining', () => { - // Call display function and check the return value - const displayFn = display(); - const result = displayFn(df); + // Check that the web display function was called with the frame + expect(mockWebDisplay).toHaveBeenCalledWith(df, expect.any(Object)); + }); - // Check that the function returns the frame - expect(result).toBe(df); - }); + it('should return the frame for method chaining', () => { + // Call display function and check the return value + const displayFn = display(); + const result = displayFn(df); - it('should pass options to the web display function', () => { - // Call display function with options - const displayFn = display(); - const options = { - maxRows: 5, - maxCols: 2, - className: 'custom-table', - }; - displayFn(df, options); + // Check that the function returns the frame + expect(result).toBe(df); + }); - // Check that the web display function was called with the options - expect(mockWebDisplay).toHaveBeenCalledWith(df, options); - }); + it('should pass options to the web display function', () => { + // Call display function with options + const displayFn = display(); + const options = { + maxRows: 5, + maxCols: 2, + className: 'custom-table', + }; + displayFn(df, options); + + // Check that the web display function was called with the options + expect(mockWebDisplay).toHaveBeenCalledWith(df, options); }); }); }); diff --git a/test/methods/dataframe/display/print.test.js b/test/methods/dataframe/display/print.test.js index 7b31ba2..d1ff81a 100644 --- a/test/methods/dataframe/display/print.test.js +++ b/test/methods/dataframe/display/print.test.js @@ -2,11 +2,6 @@ import { describe, it, expect, vi } from 'vitest'; import { DataFrame } from '../../../../src/core/dataframe/DataFrame.js'; import { print } from '../../../../src/methods/dataframe/display/print.js'; -import { - testWithBothStorageTypes, - createDataFrameWithStorage, -} from '../../../utils/storageTestUtils.js'; - // Test data to be used in all tests const sampleData = [ { value: 10, category: 'A', mixed: '20' }, @@ -17,134 +12,119 @@ const sampleData = [ ]; describe('DataFrame print method', () => { - // Run tests with both storage types - testWithBothStorageTypes((storageType) => { - describe(`with ${storageType} storage`, () => { - // Create test data frame with people data for better readability in tests - const testData = [ - { name: 'Alice', age: 25, city: 'New York' }, - { name: 'Bob', age: 30, city: 'Boston' }, - { name: 'Charlie', age: 35, city: 'Chicago' }, - { name: 'David', age: 40, city: 'Denver' }, - { name: 'Eve', age: 45, city: 'El Paso' }, - ]; - - // Create DataFrame with the specified storage type - const df = createDataFrameWithStorage(DataFrame, testData, storageType); - - it('should format data as a table string', () => { - // Mock console.log to check output - const consoleSpy = vi - .spyOn(console, 'log') - .mockImplementation(() => {}); - - // Call print function directly - const printFn = print(); - printFn(df); - - // Check that console.log was called - expect(consoleSpy).toHaveBeenCalled(); - - // Get the argument passed to console.log - const output = consoleSpy.mock.calls[0][0]; - - // Check that the output contains column headers - expect(output).toContain('name'); - expect(output).toContain('age'); - expect(output).toContain('city'); - - // Check that the output contains data - expect(output).toContain('Alice'); - expect(output).toContain('25'); - expect(output).toContain('New York'); - - // Restore console.log - consoleSpy.mockRestore(); - }); - - it('should return the frame for method chaining', () => { - // Mock console.log to prevent output - const consoleSpy = vi - .spyOn(console, 'log') - .mockImplementation(() => {}); - - // Call print function and check the return value - const printFn = print(); - const result = printFn(df); - - // Check that the function returns the frame - expect(result).toBe(df); - - // Restore console.log - consoleSpy.mockRestore(); - }); - - it('should respect rows limit', () => { - // Create a frame with many rows - const largeData = Array.from({ length: 20 }, (_, i) => ({ - id: i, - value: i * 10, - })); - - const largeDf = createDataFrameWithStorage( - DataFrame, - largeData, - storageType, - ); - - // Mock console.log - const consoleSpy = vi - .spyOn(console, 'log') - .mockImplementation(() => {}); - - // Call print function with row limit - const printFn = print(); - printFn(largeDf, 5); - - // Get the output - const output = consoleSpy.mock.calls[0][0]; - - // Check that the output contains message about additional rows - expect(output).toContain('more rows'); - - // Restore console.log - consoleSpy.mockRestore(); - }); - - it('should respect cols limit', () => { - // Create a frame with many columns - const wideData = { - col1: [1, 2, 3], - col2: [4, 5, 6], - col3: [7, 8, 9], - col4: [10, 11, 12], - col5: [13, 14, 15], - }; - - const wideDf = createDataFrameWithStorage( - DataFrame, - wideData, - storageType, - ); - - // Mock console.log - const consoleSpy = vi - .spyOn(console, 'log') - .mockImplementation(() => {}); - - // Call print function with column limit - const printFn = print(); - printFn(wideDf, Infinity, 2); - - // Get the output - const output = consoleSpy.mock.calls[0][0]; - - // Check that the output contains message about additional columns - expect(output).toContain('more columns'); - - // Restore console.log - consoleSpy.mockRestore(); - }); + describe('with standard storage', () => { + // Create test data frame with people data for better readability in tests + const testData = [ + { name: 'Alice', age: 25, city: 'New York' }, + { name: 'Bob', age: 30, city: 'Boston' }, + { name: 'Charlie', age: 35, city: 'Chicago' }, + { name: 'David', age: 40, city: 'Denver' }, + { name: 'Eve', age: 45, city: 'El Paso' }, + ]; + + // Create DataFrame using fromRows + const df = DataFrame.fromRows(testData); + + it('should format data as a table string', () => { + // Mock console.log to check output + const consoleSpy = vi.spyOn(console, 'log').mockImplementation(() => {}); + + // Call print function directly + const printFn = print(); + printFn(df); + + // Check that console.log was called + expect(consoleSpy).toHaveBeenCalled(); + + // Get the argument passed to console.log + const output = consoleSpy.mock.calls[0][0]; + + // Check that the output contains column headers + expect(output).toContain('name'); + expect(output).toContain('age'); + expect(output).toContain('city'); + + // Check that the output contains data + expect(output).toContain('Alice'); + expect(output).toContain('25'); + expect(output).toContain('New York'); + + // Restore console.log + consoleSpy.mockRestore(); + }); + + it('should return the frame for method chaining', () => { + // Mock console.log to prevent output + const consoleSpy = vi.spyOn(console, 'log').mockImplementation(() => {}); + + // Call print function and check the return value + const printFn = print(); + const result = printFn(df); + + // Check that the function returns the frame + expect(result).toBe(df); + + // Restore console.log + consoleSpy.mockRestore(); + }); + + it('should respect rows limit', () => { + // Create a frame with many rows + const largeData = Array.from({ length: 20 }, (_, i) => ({ + id: i, + value: i * 10, + })); + + const largeDf = DataFrame.fromRows(largeData); + + // Mock console.log + const consoleSpy = vi.spyOn(console, 'log').mockImplementation(() => {}); + + // Call print function with row limit + const printFn = print(); + printFn(largeDf, 5); + + // Get the output + const output = consoleSpy.mock.calls[0][0]; + + // Check that the output contains message about additional rows + expect(output).toContain('more rows'); + + // Restore console.log + consoleSpy.mockRestore(); + }); + + it('should respect cols limit', () => { + // Create a frame with many columns + const wideData = { + col1: [1, 2, 3], + col2: [4, 5, 6], + col3: [7, 8, 9], + col4: [10, 11, 12], + col5: [13, 14, 15], + }; + + const wideDf = DataFrame.fromRows([ + { col1: 1, col2: 4, col3: 7, col4: 10, col5: 13 }, + { col1: 2, col2: 5, col3: 8, col4: 11, col5: 14 }, + { col1: 3, col2: 6, col3: 9, col4: 12, col5: 15 }, + ]); + + // Mock console.log + const consoleSpy = vi.spyOn(console, 'log').mockImplementation(() => {}); + + // Call print function with column limit + const printFn = print(); + printFn(wideDf, Infinity, 2); + + // Get the output + const output = consoleSpy.mock.calls[0][0]; + + // Check that the output contains message about additional columns + expect(output).toContain('more columns'); + + // Restore console.log + consoleSpy.mockRestore(); }); }); }); diff --git a/test/methods/dataframe/display/renderTo.test.js b/test/methods/dataframe/display/renderTo.test.js index a467089..cee0aef 100644 --- a/test/methods/dataframe/display/renderTo.test.js +++ b/test/methods/dataframe/display/renderTo.test.js @@ -2,11 +2,6 @@ import { describe, it, expect, vi, beforeEach } from 'vitest'; import { DataFrame } from '../../../../src/core/dataframe/DataFrame.js'; import { renderTo } from '../../../../src/methods/dataframe/display/renderTo.js'; -import { - testWithBothStorageTypes, - createDataFrameWithStorage, -} from '../../../utils/storageTestUtils.js'; - // Mock the module vi.mock('../../../../src/display/web/html.js', () => ({ renderTo: vi.fn(), @@ -21,57 +16,54 @@ describe('DataFrame renderTo method', () => { mockWebRenderTo.mockReset(); }); - // Run tests with both storage types - testWithBothStorageTypes((storageType) => { - describe(`with ${storageType} storage`, () => { - // Create test data frame with people data for better readability in tests - const testData = [ - { name: 'Alice', age: 25, city: 'New York' }, - { name: 'Bob', age: 30, city: 'Boston' }, - { name: 'Charlie', age: 35, city: 'Chicago' }, - ]; + describe('with standard storage', () => { + // Create test data frame with people data for better readability in tests + const testData = [ + { name: 'Alice', age: 25, city: 'New York' }, + { name: 'Bob', age: 30, city: 'Boston' }, + { name: 'Charlie', age: 35, city: 'Chicago' }, + ]; - // Create DataFrame with the specified storage type - const df = createDataFrameWithStorage(DataFrame, testData, storageType); + // Create DataFrame using fromRows + const df = DataFrame.fromRows(testData); - // Mock DOM element - const mockElement = { id: 'test-element' }; + // Mock DOM element + const mockElement = { id: 'test-element' }; - it('should call the web renderTo function with the frame and element', () => { - // Call renderTo function directly - const renderToFn = renderTo(); - renderToFn(df, mockElement); + it('should call the web renderTo function with the frame and element', () => { + // Call renderTo function directly + const renderToFn = renderTo(); + renderToFn(df, mockElement); - // Check that the web renderTo function was called with the frame and element - expect(mockWebRenderTo).toHaveBeenCalledWith( - df, - mockElement, - expect.any(Object), - ); - }); + // Check that the web renderTo function was called with the frame and element + expect(mockWebRenderTo).toHaveBeenCalledWith( + df, + mockElement, + expect.any(Object), + ); + }); - it('should return the frame for method chaining', () => { - // Call renderTo function and check the return value - const renderToFn = renderTo(); - const result = renderToFn(df, mockElement); + it('should return the frame for method chaining', () => { + // Call renderTo function and check the return value + const renderToFn = renderTo(); + const result = renderToFn(df, mockElement); - // Check that the function returns the frame - expect(result).toBe(df); - }); + // Check that the function returns the frame + expect(result).toBe(df); + }); - it('should pass options to the web renderTo function', () => { - // Call renderTo function with options - const renderToFn = renderTo(); - const options = { - maxRows: 5, - maxCols: 2, - className: 'custom-table', - }; - renderToFn(df, mockElement, options); + it('should pass options to the web renderTo function', () => { + // Call renderTo function with options + const renderToFn = renderTo(); + const options = { + maxRows: 5, + maxCols: 2, + className: 'custom-table', + }; + renderToFn(df, mockElement, options); - // Check that the web renderTo function was called with the options - expect(mockWebRenderTo).toHaveBeenCalledWith(df, mockElement, options); - }); + // Check that the web renderTo function was called with the options + expect(mockWebRenderTo).toHaveBeenCalledWith(df, mockElement, options); }); }); }); diff --git a/test/methods/dataframe/display/toHTML.test.js b/test/methods/dataframe/display/toHTML.test.js index 9ecce53..04157eb 100644 --- a/test/methods/dataframe/display/toHTML.test.js +++ b/test/methods/dataframe/display/toHTML.test.js @@ -2,68 +2,60 @@ import { describe, it, expect, vi } from 'vitest'; import { DataFrame } from '../../../../src/core/dataframe/DataFrame.js'; import { toHTML } from '../../../../src/methods/dataframe/display/toHTML.js'; -import { - testWithBothStorageTypes, - createDataFrameWithStorage, -} from '../../../utils/storageTestUtils.js'; - describe('DataFrame toHTML method', () => { - // Run tests with both storage types - testWithBothStorageTypes((storageType) => { - describe(`with ${storageType} storage`, () => { - // Create test data frame with people data for better readability in tests - const testData = [ - { name: 'Alice', age: 25, city: 'New York' }, - { name: 'Bob', age: 30, city: 'Boston' }, - { name: 'Charlie', age: 35, city: 'Chicago' }, - ]; - - // Create DataFrame with the specified storage type - const df = createDataFrameWithStorage(DataFrame, testData, storageType); - - it('should convert DataFrame to HTML string', () => { - // Call toHTML function directly - const toHTMLFn = toHTML(); - const html = toHTMLFn(df); - - // Check that the result is a string - expect(typeof html).toBe('string'); - - // Check that the HTML contains expected elements - expect(html).toContain('