frame.select 1.0.4 → 1.0.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=ItemFilter.test.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ItemFilter.test.d.ts","sourceRoot":"","sources":["../../src/components/ItemFilter.test.tsx"],"names":[],"mappings":""}
@@ -0,0 +1,41 @@
1
+ import { render, fireEvent } from '@testing-library/react';
2
+ import { describe, it, expect, vi } from 'vitest';
3
+ import ItemFilter from './ItemFilter';
4
+ import React from 'react';
5
+ describe('ItemFilter', () => {
6
+ it('should clear the filter when clearFilter is called', () => {
7
+ const setFilterMock = vi.fn();
8
+ const itemFilter = {
9
+ filter: 'test',
10
+ setFilter: setFilterMock,
11
+ placeholder: 'Filter Items',
12
+ property: 'name',
13
+ filterMatches: vi.fn(),
14
+ };
15
+ const { getByPlaceholderText, getByRole } = render(React.createElement(ItemFilter, { itemFilter: itemFilter }));
16
+ const input = getByPlaceholderText('Filter Items');
17
+ const button = getByRole('button');
18
+ // Ensure the input has the initial filter value
19
+ expect(input.value).toBe('test');
20
+ // Click the clear button
21
+ fireEvent.click(button);
22
+ // Ensure the setFilter function was called with an empty string
23
+ expect(setFilterMock).toHaveBeenCalledWith('');
24
+ });
25
+ it('should update the filter when handleInputChange is called', () => {
26
+ const setFilterMock = vi.fn();
27
+ const itemFilter = {
28
+ filter: '',
29
+ setFilter: setFilterMock,
30
+ placeholder: 'Filter Items',
31
+ property: 'name',
32
+ filterMatches: vi.fn(),
33
+ };
34
+ const { getByPlaceholderText } = render(React.createElement(ItemFilter, { itemFilter: itemFilter }));
35
+ const input = getByPlaceholderText('Filter Items');
36
+ // Simulate typing in the input field
37
+ fireEvent.change(input, { target: { value: 'new filter' } });
38
+ // Ensure the setFilter function was called with the new value
39
+ expect(setFilterMock).toHaveBeenCalledWith('new filter');
40
+ });
41
+ });
@@ -1 +1 @@
1
- {"version":3,"file":"ItemList.d.ts","sourceRoot":"","sources":["../../src/components/ItemList.tsx"],"names":[],"mappings":"AASA,OAAO,EAIL,IAAI,EAGL,MAAM,uBAAuB,CAAC;AAE/B,OAAO,EAAE,WAAW,EAAE,OAAO,EAAS,MAAM,aAAa,CAAC;AAC1D,OAAO,EAAE,GAAG,EAAsB,MAAM,OAAO,CAAC;AAChD,OAAO,KAAK,MAAM,OAAO,CAAC;AAE1B,UAAU,aAAa,CAAC,CAAC;IACvB,QAAQ,EAAE,CAAC,EAAE,CAAC;IACd,UAAU,CAAC,EAAE,CAAC,IAAI,EAAE,MAAM,KAAK,KAAK,CAAC,SAAS,CAAC;IAC/C,UAAU,CAAC,EAAE,WAAW,CAAC,CAAC,CAAC,CAAC;IAC5B,SAAS,CAAC,EAAE,CAAC,IAAI,EAAE,IAAI,CAAC,CAAC,EAAE,OAAO,CAAC,KAAK,IAAI,CAAC;IAC7C,YAAY,CAAC,EAAE,OAAO,CAAC,CAAC,CAAC,EAAE,CAAC;IAC5B,KAAK,CAAC,EAAE,KAAK,CAAC,aAAa,CAAC;CAC7B;AAED,iBAAS,QAAQ,CAAC,CAAC,SAAS;IAAE,IAAI,EAAE,MAAM,CAAA;CAAE,EAAE,EAC5C,QAAQ,EACR,UAAU,EACV,UAAU,EACV,SAAS,EACT,YAAiB,EACjB,KAA8D,GAC/D,EAAE,aAAa,CAAC,CAAC,CAAC,GAAG,GAAG,CAAC,OAAO,CAwJhC;AAED,eAAe,QAAQ,CAAC"}
1
+ {"version":3,"file":"ItemList.d.ts","sourceRoot":"","sources":["../../src/components/ItemList.tsx"],"names":[],"mappings":"AASA,OAAO,EAIL,IAAI,EAGL,MAAM,uBAAuB,CAAC;AAE/B,OAAO,EAAE,WAAW,EAAE,OAAO,EAAS,MAAM,aAAa,CAAC;AAC1D,OAAO,EAAE,GAAG,EAAsB,MAAM,OAAO,CAAC;AAChD,OAAO,KAAK,MAAM,OAAO,CAAC;AAE1B,UAAU,aAAa,CAAC,CAAC;IACvB,QAAQ,EAAE,CAAC,EAAE,CAAC;IACd,UAAU,CAAC,EAAE,CAAC,IAAI,EAAE,MAAM,KAAK,KAAK,CAAC,SAAS,CAAC;IAC/C,UAAU,CAAC,EAAE,WAAW,CAAC,CAAC,CAAC,CAAC;IAC5B,SAAS,CAAC,EAAE,CAAC,IAAI,EAAE,IAAI,CAAC,CAAC,EAAE,OAAO,CAAC,KAAK,IAAI,CAAC;IAC7C,YAAY,CAAC,EAAE,OAAO,CAAC,CAAC,CAAC,EAAE,CAAC;IAC5B,KAAK,CAAC,EAAE,KAAK,CAAC,aAAa,CAAC;CAC7B;AAED,iBAAS,QAAQ,CAAC,CAAC,SAAS;IAAE,IAAI,EAAE,MAAM,CAAA;CAAE,EAAE,EAC5C,QAAQ,EACR,UAAU,EACV,UAAU,EACV,SAAS,EACT,YAAiB,EACjB,KAA8D,GAC/D,EAAE,aAAa,CAAC,CAAC,CAAC,GAAG,GAAG,CAAC,OAAO,CAsJhC;AAED,eAAe,QAAQ,CAAC"}
@@ -86,13 +86,12 @@ function ItemList({ itemList, renderItem, itemFilter, clickFunc, extraColumns =
86
86
  getCoreRowModel: getCoreRowModel(),
87
87
  getFilteredRowModel: getFilteredRowModel(),
88
88
  });
89
- return (React.createElement("div", null,
90
- React.createElement(TableContainer, { style: style },
91
- React.createElement(Table, { stickyHeader: true, "aria-label": "sticky table" },
92
- React.createElement(TableHead, null, table.getHeaderGroups().map((headerGroup) => (React.createElement(TableRow, { key: headerGroup.id, "data-testid": headerGroup.id }, headerGroup.headers.map((header) => (React.createElement(TableCell, { key: header.id }, displayHeader(header)))))))),
93
- React.createElement(TableBody, null, table.getRowModel().rows.map((row) => (React.createElement(TableRow, { key: row.id }, row.getVisibleCells().map((cell) => {
94
- // console.log(`cell: ${JSON.stringify(cell, null)}`)
95
- return displayBody(cell);
96
- })))))))));
89
+ return (React.createElement(TableContainer, { "data-testid": "frame.select-TableContainer", style: style },
90
+ React.createElement(Table, { stickyHeader: true, "aria-label": "sticky table" },
91
+ React.createElement(TableHead, null, table.getHeaderGroups().map((headerGroup) => (React.createElement(TableRow, { key: headerGroup.id, "data-testid": headerGroup.id }, headerGroup.headers.map((header) => (React.createElement(TableCell, { key: header.id }, displayHeader(header)))))))),
92
+ React.createElement(TableBody, null, table.getRowModel().rows.map((row) => (React.createElement(TableRow, { key: row.id }, row.getVisibleCells().map((cell) => {
93
+ // console.log(`cell: ${JSON.stringify(cell, null)}`)
94
+ return displayBody(cell);
95
+ }))))))));
97
96
  }
98
97
  export default ItemList;
@@ -0,0 +1,2 @@
1
+ import '@testing-library/jest-dom';
2
+ //# sourceMappingURL=ItemList.test.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ItemList.test.d.ts","sourceRoot":"","sources":["../../src/components/ItemList.test.tsx"],"names":[],"mappings":"AACA,OAAO,2BAA2B,CAAC"}
@@ -0,0 +1,74 @@
1
+ import { render, screen, fireEvent } from '@testing-library/react';
2
+ import '@testing-library/jest-dom';
3
+ import { describe, expect, it, vi } from 'vitest';
4
+ import { createColumnHelper } from '@tanstack/react-table';
5
+ import React from 'react';
6
+ import ItemList from './ItemList';
7
+ describe('ItemList', () => {
8
+ const itemList = [
9
+ { name: 'Item 1' },
10
+ { name: 'Item 2' },
11
+ { name: 'Item 3' },
12
+ ];
13
+ const filterMatches = (item, filter) => item.name.includes(filter);
14
+ // const filterEvent = vi.fn()
15
+ const renderItem = (item) => React.createElement("span", null, item);
16
+ const clickFunc = vi.fn();
17
+ const itemFilter = {
18
+ filter: 'Item',
19
+ setFilter: vi.fn(),
20
+ property: 'name',
21
+ filterMatches,
22
+ placeholder: 'Filter Items',
23
+ };
24
+ it('renders the item list', () => {
25
+ render(React.createElement(ItemList, { itemList: itemList }));
26
+ itemList.forEach((item) => {
27
+ expect(screen.getByText(item.name)).toBeInTheDocument();
28
+ });
29
+ });
30
+ it('filters the item list based on filterMatches', () => {
31
+ render(React.createElement(ItemList, { itemList: itemList, itemFilter: itemFilter }));
32
+ expect(screen.getByText('Item 1')).toBeInTheDocument();
33
+ expect(screen.getByText('Item 2')).toBeInTheDocument();
34
+ expect(screen.getByText('Item 3')).toBeInTheDocument();
35
+ });
36
+ // it('calls filterEvent when filter is applied', () => {
37
+ // render(<ItemList itemList={itemList} filterEvent={filterEvent} itemFilter={itemFilter} />)
38
+ // expect(filterEvent).toHaveBeenCalledWith(itemList)
39
+ // })
40
+ it('renders custom item using renderItem', () => {
41
+ render(React.createElement(ItemList, { itemList: itemList, renderItem: renderItem }));
42
+ itemList.forEach((item) => {
43
+ expect(screen.getByText(item.name)).toBeInTheDocument();
44
+ });
45
+ });
46
+ it('calls clickFunc with the correct cell when an item is clicked', () => {
47
+ render(React.createElement(ItemList, { itemList: itemList, clickFunc: clickFunc }));
48
+ const itemButton = screen.getByText('Item 1').closest('button');
49
+ fireEvent.click(itemButton);
50
+ expect(clickFunc).toHaveBeenCalled();
51
+ expect(clickFunc.mock.calls[0][0].getValue()).toBe('Item 1');
52
+ });
53
+ });
54
+ describe('ItemList - createColumnHelper', () => {
55
+ it('creates columns correctly', () => {
56
+ const columnHelper = createColumnHelper();
57
+ const columns = [
58
+ columnHelper.accessor('name', {
59
+ header: 'Name',
60
+ cell: (info) => React.createElement("span", null, info.getValue()),
61
+ }),
62
+ columnHelper.accessor('age', {
63
+ header: 'Age',
64
+ cell: (info) => React.createElement("span", null, info.getValue()),
65
+ }),
66
+ ];
67
+ expect(columns).toHaveLength(2);
68
+ expect(columns[0].accessorKey).toBe('name');
69
+ expect(columns[0].header).toBe('Name');
70
+ expect(typeof columns[0].cell).toBe('function');
71
+ expect(columns[1].header).toBe('Age');
72
+ expect(typeof columns[1].cell).toBe('function');
73
+ });
74
+ });
@@ -1 +1 @@
1
- {"root":["../src/app.tsx","../src/index.ts","../src/main.tsx","../src/vite-env.d.ts","../src/components/itemfilter.tsx","../src/components/itemlist.tsx","../src/components/itemtypes.ts"],"version":"5.8.3"}
1
+ {"root":["../src/app.tsx","../src/index.ts","../src/main.tsx","../src/vite-env.d.ts","../src/components/itemfilter.test.tsx","../src/components/itemfilter.tsx","../src/components/itemlist.test.tsx","../src/components/itemlist.tsx","../src/components/itemtypes.ts"],"version":"5.8.3"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "frame.select",
3
- "version": "1.0.4",
3
+ "version": "1.0.6",
4
4
  "description": "A React component for selecting items from a list with a search bar.",
5
5
  "license": "MIT",
6
6
  "type": "module",
@@ -15,6 +15,7 @@
15
15
  "build": "tsc -b",
16
16
  "build-and-vite": "tsc -b && vite build",
17
17
  "lint": "eslint .",
18
+ "test": "vitest --config vitest.config.ts",
18
19
  "preview": "vite preview"
19
20
  },
20
21
  "dependencies": {
@@ -28,6 +29,9 @@
28
29
  },
29
30
  "devDependencies": {
30
31
  "@eslint/js": "^9.21.0",
32
+ "@testing-library/dom": "^10.4.0",
33
+ "@testing-library/jest-dom": "^6.6.3",
34
+ "@testing-library/react": "^16.2.0",
31
35
  "@types/react": "^19.0.10",
32
36
  "@types/react-dom": "^19.1.2",
33
37
  "@vitejs/plugin-react": "^4.3.4",
@@ -35,8 +39,10 @@
35
39
  "eslint-plugin-react-hooks": "^5.1.0",
36
40
  "eslint-plugin-react-refresh": "^0.4.19",
37
41
  "globals": "^16.0.0",
42
+ "jsdom": "^26.0.0",
38
43
  "typescript": "~5.8.3",
39
44
  "typescript-eslint": "^8.24.1",
40
- "vite": "^6.2.0"
45
+ "vite": "^6.2.0",
46
+ "vitest": "^3.0.9"
41
47
  }
42
48
  }