Skip to content

Commit 38b2680

Browse files
committed
chore: update tests
1 parent 695c51b commit 38b2680

4 files changed

Lines changed: 100 additions & 160 deletions

File tree

libs/react-plock/package.json

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,6 @@
3232
"react": "^18.2.0"
3333
},
3434
"devDependencies": {
35-
"@testing-library/dom": "^10.4.0",
36-
"@testing-library/react": "^16.1.0",
3735
"@types/react": "^19.0.1",
3836
"@types/react-dom": "^19.0.2"
3937
}

libs/react-plock/src/index.spec.tsx

Lines changed: 49 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
1-
import { describe, it, expect } from 'vitest';
2-
import { createChunks, createDataColumns } from '.';
3-
import { render } from '@testing-library/react';
4-
import { Masonry } from '.';
1+
import { describe, expect, it } from 'vitest';
2+
import { createBalancedColumns, createChunks, createDataColumns } from '.';
53

64
describe('Plock', () => {
75
it('should create chunks', () => {
@@ -79,60 +77,61 @@ describe('Plock', () => {
7977
});
8078
});
8179

82-
describe('Integration Tests', () => {
83-
it('should render with different HTML elements using "as" prop', () => {
84-
const items = [1, 2, 3];
85-
const config = { columns: 3, gap: 10 };
86-
87-
// Test with 'section' element
88-
const { container: sectionContainer } = render(
89-
<Masonry
90-
items={items}
91-
render={(item) => <div key={item}>{item}</div>}
92-
config={config}
93-
as="section"
94-
/>
95-
);
80+
describe('Balanced Layout', () => {
81+
it('should distribute items to columns based on height', () => {
82+
const items = [1, 2, 3, 4];
83+
const heightMap = new Map([
84+
[1, 100], // tall
85+
[2, 50], // short
86+
[3, 120], // tallest
87+
[4, 30], // shortest
88+
]);
9689

97-
// Test with 'article' element
98-
const { container: articleContainer } = render(
99-
<Masonry
100-
items={items}
101-
render={(item) => <div key={item}>{item}</div>}
102-
config={config}
103-
as="article"
104-
/>
90+
const result = createBalancedColumns(
91+
items,
92+
2,
93+
(item) => heightMap.get(item) || 0
10594
);
10695

107-
expect(sectionContainer.querySelector('section')).toBeTruthy();
108-
expect(articleContainer.querySelector('article')).toBeTruthy();
96+
expect(result).toEqual([
97+
[1, 4], // Column 1: 100 + 30 = 130
98+
[2, 3], // Column 2: 50 + 120 = 170
99+
]);
109100
});
110101

111-
it('should render with custom React component using "as" prop', () => {
112-
const CustomComponent = ({
113-
children,
114-
className,
115-
}: {
116-
children: React.ReactNode;
117-
className?: string;
118-
}) => <div className={`custom-wrapper ${className || ''}`}>{children}</div>;
102+
it('should handle empty items array', () => {
103+
const result = createBalancedColumns([], 3, () => 0);
104+
expect(result).toEqual([[], [], []]);
105+
});
119106

107+
it('should handle single column', () => {
120108
const items = [1, 2, 3];
121-
const config = { columns: 3, gap: 10 };
122-
123-
const { container } = render(
124-
<Masonry
125-
items={items}
126-
render={(item) => <div key={item}>{item}</div>}
127-
config={config}
128-
as={CustomComponent}
129-
className="test-class"
130-
/>
131-
);
109+
const result = createBalancedColumns(items, 1, () => 100);
110+
expect(result).toEqual([[1, 2, 3]]);
111+
});
112+
113+
it('should maintain item order within columns', () => {
114+
const items = [1, 2, 3, 4, 5, 6];
115+
const heightMap = new Map([
116+
[1, 50],
117+
[2, 50],
118+
[3, 50],
119+
[4, 50],
120+
[5, 50],
121+
[6, 50],
122+
]);
132123

133-
const customElement = container.querySelector('.custom-wrapper');
124+
const result = createBalancedColumns(
125+
items,
126+
3,
127+
(item) => heightMap.get(item) || 0
128+
);
134129

135-
expect(customElement).toBeTruthy();
136-
expect(customElement?.classList.contains('test-class')).toBeTruthy();
130+
// With equal heights, items should be distributed evenly while maintaining order
131+
expect(result).toEqual([
132+
[1, 4],
133+
[2, 5],
134+
[3, 6],
135+
]);
137136
});
138137
});

package.json

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,10 @@
33
"private": true,
44
"devDependencies": {
55
"@types/node": "^18.14.4",
6-
"@types/react": "^18.2.0",
76
"@vitejs/plugin-react": "^4.3.4",
87
"typescript": "^5.3.3",
98
"vite": "^6.0.3",
109
"vite-plugin-dts": "^4.3.0",
11-
"vitest": "^2.1.8",
12-
"jsdom": "^25.0.1"
10+
"vitest": "^2.1.8"
1311
}
1412
}

0 commit comments

Comments
 (0)