@imposium-hub/components 2.15.0-3 → 2.16.0
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.
- package/dist/cjs/components/app-wrapper/AppWrapper.d.ts +0 -1
- package/dist/cjs/components/app-wrapper/AppWrapper.js +1 -1
- package/dist/cjs/components/app-wrapper/AppWrapper.js.map +1 -1
- package/dist/cjs/components/assets/AssetsTypeIcon.js +2 -0
- package/dist/cjs/components/assets/AssetsTypeIcon.js.map +1 -1
- package/dist/cjs/components/change-report/ChangeReportTree.js +65 -10
- package/dist/cjs/components/change-report/ChangeReportTree.js.map +1 -1
- package/dist/cjs/components/number-field/NumberField.d.ts +2 -2
- package/dist/cjs/components/number-field/NumberField.js +7 -4
- package/dist/cjs/components/number-field/NumberField.js.map +1 -1
- package/dist/cjs/components/publish-wizard/PublishWizard.js +40 -39
- package/dist/cjs/components/publish-wizard/PublishWizard.js.map +1 -1
- package/dist/cjs/constants/copy.d.ts +1 -0
- package/dist/cjs/constants/copy.js +3 -2
- package/dist/cjs/constants/copy.js.map +1 -1
- package/dist/cjs/constants/icons.d.ts +5 -0
- package/dist/cjs/constants/icons.js +12 -2
- package/dist/cjs/constants/icons.js.map +1 -1
- package/dist/cjs/constants/snippets.d.ts +2 -0
- package/dist/cjs/redux/actions/publish.d.ts +1 -1
- package/dist/cjs/redux/actions/publish.js +2 -2
- package/dist/cjs/redux/actions/publish.js.map +1 -1
- package/dist/esm/components/app-wrapper/AppWrapper.d.ts +0 -1
- package/dist/esm/components/app-wrapper/AppWrapper.js +1 -1
- package/dist/esm/components/app-wrapper/AppWrapper.js.map +1 -1
- package/dist/esm/components/assets/AssetsTypeIcon.js +2 -0
- package/dist/esm/components/assets/AssetsTypeIcon.js.map +1 -1
- package/dist/esm/components/change-report/ChangeReportTree.js +64 -10
- package/dist/esm/components/change-report/ChangeReportTree.js.map +1 -1
- package/dist/esm/components/number-field/NumberField.d.ts +2 -2
- package/dist/esm/components/number-field/NumberField.js +5 -4
- package/dist/esm/components/number-field/NumberField.js.map +1 -1
- package/dist/esm/components/publish-wizard/PublishWizard.js +40 -39
- package/dist/esm/components/publish-wizard/PublishWizard.js.map +1 -1
- package/dist/esm/constants/copy.d.ts +1 -0
- package/dist/esm/constants/copy.js +3 -2
- package/dist/esm/constants/copy.js.map +1 -1
- package/dist/esm/constants/icons.d.ts +5 -0
- package/dist/esm/constants/icons.js +10 -0
- package/dist/esm/constants/icons.js.map +1 -1
- package/dist/esm/constants/snippets.d.ts +2 -0
- package/dist/esm/redux/actions/publish.d.ts +1 -1
- package/dist/esm/redux/actions/publish.js +2 -2
- package/dist/esm/redux/actions/publish.js.map +1 -1
- package/dist/styles.css +54 -10
- package/dist/styles.less +65 -13
- package/less/components/change-report.less +50 -9
- package/less/components/publish-wizard.less +15 -4
- package/package.json +5 -1
- package/src/components/advanced-number-field/AdvancedNumberField.test.tsx +724 -0
- package/src/components/anchor-field/AnchorField.test.tsx +130 -0
- package/src/components/app-wrapper/AppWrapper.tsx +1 -6
- package/src/components/asset-details/AssetDetails.test.tsx +494 -0
- package/src/components/assets/AssetField.test.tsx +449 -0
- package/src/components/assets/AssetsTableAssetIdCell.test.tsx +142 -0
- package/src/components/assets/AssetsTableAssetIdFilter.test.tsx +95 -0
- package/src/components/assets/AssetsTableComplexTagCell.test.tsx +161 -0
- package/src/components/assets/AssetsTableDateCell.test.tsx +106 -0
- package/src/components/assets/AssetsTableDropzone.test.tsx +132 -0
- package/src/components/assets/AssetsTableDurationCell.test.tsx +119 -0
- package/src/components/assets/AssetsTableGlobalCell.test.tsx +46 -0
- package/src/components/assets/AssetsTableNameCell.test.tsx +166 -0
- package/src/components/assets/AssetsTableNameFilter.test.tsx +95 -0
- package/src/components/assets/AssetsTablePreviewCell.test.tsx +191 -0
- package/src/components/assets/AssetsTableRateCell.test.tsx +87 -0
- package/src/components/assets/AssetsTableSelectCell.test.tsx +156 -0
- package/src/components/assets/AssetsTableSelectFilter.test.tsx +119 -0
- package/src/components/assets/AssetsTableStatusCell.test.tsx +60 -0
- package/src/components/assets/AssetsTypeIcon.tsx +2 -0
- package/src/components/change-report/ChangeReportTree.tsx +104 -16
- package/src/components/number-field/NumberField.test.tsx +383 -0
- package/src/components/number-field/NumberField.tsx +15 -9
- package/src/components/publish-wizard/PublishWizard.tsx +59 -54
- package/src/components/text-field/TextField.test.tsx +988 -0
- package/src/constants/copy.ts +3 -2
- package/src/constants/icons.tsx +10 -0
- package/src/constants/snippets.ts +2 -0
- package/src/redux/actions/publish.ts +7 -2
- package/src/test/setup.ts +91 -0
- package/src/test/utils.tsx +44 -0
- package/tsconfig.eslint.json +8 -0
- package/tsconfig.json +1 -1
- package/vitest.config.ts +31 -0
- package/src/components/service-icon/ServiceIcon.test.tsx +0 -0
|
@@ -0,0 +1,161 @@
|
|
|
1
|
+
import { describe, it, expect, vi } from 'vitest';
|
|
2
|
+
import React from 'react';
|
|
3
|
+
import { render } from '@testing-library/react';
|
|
4
|
+
import { Provider } from 'react-redux';
|
|
5
|
+
import { legacy_createStore as createStore } from 'redux';
|
|
6
|
+
|
|
7
|
+
let capturedDoSubmit: (value: string) => void;
|
|
8
|
+
let capturedRemoveHandlers: Record<string, () => void> = {};
|
|
9
|
+
|
|
10
|
+
vi.mock('../tag/Tag', () => ({
|
|
11
|
+
default: ({ copy, removeHandler }: any) => {
|
|
12
|
+
capturedRemoveHandlers[copy] = removeHandler;
|
|
13
|
+
return (
|
|
14
|
+
<div
|
|
15
|
+
data-testid={`tag-${copy}`}
|
|
16
|
+
className='mock-tag'>
|
|
17
|
+
<span>{copy}</span>
|
|
18
|
+
<button
|
|
19
|
+
data-testid={`remove-${copy}`}
|
|
20
|
+
onClick={removeHandler}>
|
|
21
|
+
x
|
|
22
|
+
</button>
|
|
23
|
+
</div>
|
|
24
|
+
);
|
|
25
|
+
}
|
|
26
|
+
}));
|
|
27
|
+
|
|
28
|
+
vi.mock('../text-field/TextField', () => ({
|
|
29
|
+
default: ({ submittable, submittableType, placeholder, value, doSubmit, suggestions }: any) => {
|
|
30
|
+
capturedDoSubmit = doSubmit;
|
|
31
|
+
return (
|
|
32
|
+
<div
|
|
33
|
+
data-testid='mock-text-field'
|
|
34
|
+
data-submittable={submittable}
|
|
35
|
+
data-submittable-type={submittableType}
|
|
36
|
+
data-placeholder={placeholder}
|
|
37
|
+
data-value={value}
|
|
38
|
+
data-suggestions={JSON.stringify(suggestions || [])}>
|
|
39
|
+
<button
|
|
40
|
+
data-testid='submit-trigger'
|
|
41
|
+
onClick={() => doSubmit('new-tag')}>
|
|
42
|
+
Add
|
|
43
|
+
</button>
|
|
44
|
+
</div>
|
|
45
|
+
);
|
|
46
|
+
}
|
|
47
|
+
}));
|
|
48
|
+
|
|
49
|
+
vi.mock('../../redux/actions/asset-list', () => ({
|
|
50
|
+
addAssetTag: vi.fn((_api, _id, _tags) => ({ type: 'MOCK_ADD_TAG' })),
|
|
51
|
+
deleteAssetTag: vi.fn((_api, _id, _tag) => ({ type: 'MOCK_DELETE_TAG' })),
|
|
52
|
+
default: {}
|
|
53
|
+
}));
|
|
54
|
+
|
|
55
|
+
import AssetsTableComplexTagCellMemoized from './AssetsTableComplexTagCell';
|
|
56
|
+
import { addAssetTag, deleteAssetTag } from '../../redux/actions/asset-list';
|
|
57
|
+
|
|
58
|
+
const MOCK_ASSET_ID = 'asset-999';
|
|
59
|
+
const MOCK_API = { addAssetTag: vi.fn(), deleteAssetTag: vi.fn() };
|
|
60
|
+
const MOCK_SUGGESTIONS = ['alpha', 'beta', 'gamma'];
|
|
61
|
+
|
|
62
|
+
const createMockStore = (assetTags: string[] = MOCK_SUGGESTIONS) => {
|
|
63
|
+
const initialState = { assetTags };
|
|
64
|
+
return createStore((state = initialState) => state);
|
|
65
|
+
};
|
|
66
|
+
|
|
67
|
+
const buildCellProp = (tags: string[] = ['tag-a', 'tag-b']) => ({
|
|
68
|
+
row: {
|
|
69
|
+
original: { id: MOCK_ASSET_ID, tags }
|
|
70
|
+
}
|
|
71
|
+
});
|
|
72
|
+
|
|
73
|
+
const renderComponent = (tagOverrides?: string[], storeOverrides?: string[]) => {
|
|
74
|
+
capturedRemoveHandlers = {};
|
|
75
|
+
const store = createMockStore(storeOverrides);
|
|
76
|
+
const cell = buildCellProp(tagOverrides);
|
|
77
|
+
|
|
78
|
+
const result = render(
|
|
79
|
+
<Provider store={store}>
|
|
80
|
+
<AssetsTableComplexTagCellMemoized
|
|
81
|
+
cell={cell}
|
|
82
|
+
api={MOCK_API}
|
|
83
|
+
/>
|
|
84
|
+
</Provider>
|
|
85
|
+
);
|
|
86
|
+
|
|
87
|
+
return { ...result, store };
|
|
88
|
+
};
|
|
89
|
+
|
|
90
|
+
describe('AssetsTableComplexTagCell', () => {
|
|
91
|
+
it('renders existing tags as Tag components', () => {
|
|
92
|
+
const tags = ['tag-a', 'tag-b', 'tag-c'];
|
|
93
|
+
const { getByTestId } = renderComponent(tags);
|
|
94
|
+
|
|
95
|
+
tags.forEach((tag) => {
|
|
96
|
+
expect(getByTestId(`tag-${tag}`)).toBeTruthy();
|
|
97
|
+
});
|
|
98
|
+
});
|
|
99
|
+
|
|
100
|
+
it('deduplicates tags before rendering', () => {
|
|
101
|
+
const { container } = renderComponent(['dup', 'dup', 'unique']);
|
|
102
|
+
const renderedTags = container.querySelectorAll('.mock-tag');
|
|
103
|
+
|
|
104
|
+
expect(renderedTags).toHaveLength(2);
|
|
105
|
+
});
|
|
106
|
+
|
|
107
|
+
it('renders the TextField with correct props', () => {
|
|
108
|
+
const { getByTestId } = renderComponent();
|
|
109
|
+
const textField = getByTestId('mock-text-field');
|
|
110
|
+
|
|
111
|
+
expect(textField.getAttribute('data-submittable')).toBe('true');
|
|
112
|
+
expect(textField.getAttribute('data-submittable-type')).toBe('add');
|
|
113
|
+
expect(textField.getAttribute('data-placeholder')).toBe('+');
|
|
114
|
+
expect(textField.getAttribute('data-value')).toBe('');
|
|
115
|
+
});
|
|
116
|
+
|
|
117
|
+
it('passes assetTags from store as suggestions', () => {
|
|
118
|
+
const suggestions = ['x', 'y', 'z'];
|
|
119
|
+
const { getByTestId } = renderComponent([], suggestions);
|
|
120
|
+
const textField = getByTestId('mock-text-field');
|
|
121
|
+
|
|
122
|
+
const suggestionsAttr = textField.getAttribute('data-suggestions');
|
|
123
|
+
if (suggestionsAttr) {
|
|
124
|
+
expect(suggestionsAttr).toBeTruthy();
|
|
125
|
+
expect(JSON.parse(suggestionsAttr)).toEqual(suggestions);
|
|
126
|
+
}
|
|
127
|
+
});
|
|
128
|
+
|
|
129
|
+
it('dispatches addAssetTag when submitting a new tag', () => {
|
|
130
|
+
renderComponent(['existing']);
|
|
131
|
+
|
|
132
|
+
capturedDoSubmit('brand-new');
|
|
133
|
+
|
|
134
|
+
expect(addAssetTag).toHaveBeenCalledWith(MOCK_API, MOCK_ASSET_ID, 'brand-new');
|
|
135
|
+
});
|
|
136
|
+
|
|
137
|
+
it('does not dispatch addAssetTag when submitting a duplicate tag', () => {
|
|
138
|
+
vi.mocked(addAssetTag).mockClear();
|
|
139
|
+
renderComponent(['already-here']);
|
|
140
|
+
|
|
141
|
+
capturedDoSubmit('already-here');
|
|
142
|
+
|
|
143
|
+
expect(addAssetTag).not.toHaveBeenCalled();
|
|
144
|
+
});
|
|
145
|
+
|
|
146
|
+
it('dispatches deleteAssetTag when removing a tag', () => {
|
|
147
|
+
renderComponent(['removable']);
|
|
148
|
+
|
|
149
|
+
capturedRemoveHandlers['removable']();
|
|
150
|
+
|
|
151
|
+
expect(deleteAssetTag).toHaveBeenCalledWith(MOCK_API, MOCK_ASSET_ID, 'removable');
|
|
152
|
+
});
|
|
153
|
+
|
|
154
|
+
it('renders with no tags', () => {
|
|
155
|
+
const { container, getByTestId } = renderComponent([]);
|
|
156
|
+
const renderedTags = container.querySelectorAll('.mock-tag');
|
|
157
|
+
|
|
158
|
+
expect(renderedTags).toHaveLength(0);
|
|
159
|
+
expect(getByTestId('mock-text-field')).toBeTruthy();
|
|
160
|
+
});
|
|
161
|
+
});
|
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
import { describe, it, expect, vi } from 'vitest';
|
|
2
|
+
import React from 'react';
|
|
3
|
+
import { render } from '@testing-library/react';
|
|
4
|
+
|
|
5
|
+
const MOCK_FORMATTED_DATE = '4/9/2026 3:00 PM';
|
|
6
|
+
|
|
7
|
+
vi.mock('../../Util', async (importOriginal) => {
|
|
8
|
+
const actual = (await importOriginal()) as any;
|
|
9
|
+
return {
|
|
10
|
+
...actual,
|
|
11
|
+
formatDateDefault: vi.fn(() => MOCK_FORMATTED_DATE)
|
|
12
|
+
};
|
|
13
|
+
});
|
|
14
|
+
|
|
15
|
+
import AssetsTableDateCellMemoized from './AssetsTableDateCell';
|
|
16
|
+
import { formatDateDefault } from '../../Util';
|
|
17
|
+
|
|
18
|
+
const MOCK_UNIX_TIMESTAMP = 1776013200;
|
|
19
|
+
|
|
20
|
+
const buildCellProp = (values: Record<string, any>) => ({
|
|
21
|
+
row: { values }
|
|
22
|
+
});
|
|
23
|
+
|
|
24
|
+
describe('AssetsTableDateCell', () => {
|
|
25
|
+
it('renders date_created when date_created prop is true and value exists', () => {
|
|
26
|
+
const cell = buildCellProp({ date_created: MOCK_UNIX_TIMESTAMP });
|
|
27
|
+
const { container } = render(
|
|
28
|
+
<AssetsTableDateCellMemoized
|
|
29
|
+
cell={cell}
|
|
30
|
+
date_created={true}
|
|
31
|
+
/>
|
|
32
|
+
);
|
|
33
|
+
|
|
34
|
+
expect(formatDateDefault).toHaveBeenCalledWith(MOCK_UNIX_TIMESTAMP);
|
|
35
|
+
expect(container.textContent).toBe(MOCK_FORMATTED_DATE);
|
|
36
|
+
});
|
|
37
|
+
|
|
38
|
+
it('renders date_modified when date_created is false', () => {
|
|
39
|
+
const cell = buildCellProp({ date_modified: MOCK_UNIX_TIMESTAMP });
|
|
40
|
+
const { container } = render(
|
|
41
|
+
<AssetsTableDateCellMemoized
|
|
42
|
+
cell={cell}
|
|
43
|
+
date_created={false}
|
|
44
|
+
/>
|
|
45
|
+
);
|
|
46
|
+
|
|
47
|
+
expect(formatDateDefault).toHaveBeenCalledWith(MOCK_UNIX_TIMESTAMP);
|
|
48
|
+
expect(container.textContent).toBe(MOCK_FORMATTED_DATE);
|
|
49
|
+
});
|
|
50
|
+
|
|
51
|
+
it('falls through to date_updated when date_modified is absent', () => {
|
|
52
|
+
const cell = buildCellProp({ date_updated: MOCK_UNIX_TIMESTAMP });
|
|
53
|
+
const { container } = render(
|
|
54
|
+
<AssetsTableDateCellMemoized
|
|
55
|
+
cell={cell}
|
|
56
|
+
date_created={false}
|
|
57
|
+
/>
|
|
58
|
+
);
|
|
59
|
+
|
|
60
|
+
expect(formatDateDefault).toHaveBeenCalledWith(MOCK_UNIX_TIMESTAMP);
|
|
61
|
+
expect(container.textContent).toBe(MOCK_FORMATTED_DATE);
|
|
62
|
+
});
|
|
63
|
+
|
|
64
|
+
it('prefers date_modified over date_updated when both exist', () => {
|
|
65
|
+
const modifiedTimestamp = 1776099600;
|
|
66
|
+
const cell = buildCellProp({
|
|
67
|
+
date_modified: modifiedTimestamp,
|
|
68
|
+
date_updated: MOCK_UNIX_TIMESTAMP
|
|
69
|
+
});
|
|
70
|
+
const { container } = render(
|
|
71
|
+
<AssetsTableDateCellMemoized
|
|
72
|
+
cell={cell}
|
|
73
|
+
date_created={false}
|
|
74
|
+
/>
|
|
75
|
+
);
|
|
76
|
+
|
|
77
|
+
expect(formatDateDefault).toHaveBeenCalledWith(modifiedTimestamp);
|
|
78
|
+
expect(container.textContent).toBe(MOCK_FORMATTED_DATE);
|
|
79
|
+
});
|
|
80
|
+
|
|
81
|
+
it('skips date_created value when date_created prop is false', () => {
|
|
82
|
+
vi.mocked(formatDateDefault).mockClear();
|
|
83
|
+
const cell = buildCellProp({ date_created: MOCK_UNIX_TIMESTAMP });
|
|
84
|
+
const { container } = render(
|
|
85
|
+
<AssetsTableDateCellMemoized
|
|
86
|
+
cell={cell}
|
|
87
|
+
date_created={false}
|
|
88
|
+
/>
|
|
89
|
+
);
|
|
90
|
+
|
|
91
|
+
expect(formatDateDefault).not.toHaveBeenCalled();
|
|
92
|
+
expect(container.innerHTML).toBe('');
|
|
93
|
+
});
|
|
94
|
+
|
|
95
|
+
it('returns null when no date values are present', () => {
|
|
96
|
+
const cell = buildCellProp({});
|
|
97
|
+
const { container } = render(
|
|
98
|
+
<AssetsTableDateCellMemoized
|
|
99
|
+
cell={cell}
|
|
100
|
+
date_created={false}
|
|
101
|
+
/>
|
|
102
|
+
);
|
|
103
|
+
|
|
104
|
+
expect(container.innerHTML).toBe('');
|
|
105
|
+
});
|
|
106
|
+
});
|
|
@@ -0,0 +1,132 @@
|
|
|
1
|
+
import { describe, it, expect, vi } from 'vitest';
|
|
2
|
+
import React from 'react';
|
|
3
|
+
import { render } from '@testing-library/react';
|
|
4
|
+
|
|
5
|
+
let capturedDropConfig: any = {};
|
|
6
|
+
|
|
7
|
+
vi.mock('react-dnd', () => ({
|
|
8
|
+
useDrop: (configFn: () => any) => {
|
|
9
|
+
capturedDropConfig = typeof configFn === 'function' ? configFn() : configFn;
|
|
10
|
+
const refCallback = vi.fn();
|
|
11
|
+
return [{}, refCallback];
|
|
12
|
+
}
|
|
13
|
+
}));
|
|
14
|
+
|
|
15
|
+
vi.mock('react-dnd-html5-backend', () => ({
|
|
16
|
+
NativeTypes: { FILE: '__NATIVE_FILE__' }
|
|
17
|
+
}));
|
|
18
|
+
|
|
19
|
+
import AssetsTableDropzone from './AssetsTableDropzone';
|
|
20
|
+
|
|
21
|
+
describe('AssetsTableDropzone', () => {
|
|
22
|
+
it('renders children inside a div', () => {
|
|
23
|
+
const { getByText } = render(
|
|
24
|
+
<AssetsTableDropzone onDrop={vi.fn()}>
|
|
25
|
+
<span>Drop here</span>
|
|
26
|
+
</AssetsTableDropzone>
|
|
27
|
+
);
|
|
28
|
+
|
|
29
|
+
expect(getByText('Drop here')).toBeTruthy();
|
|
30
|
+
});
|
|
31
|
+
|
|
32
|
+
it('applies the provided className', () => {
|
|
33
|
+
const { container } = render(
|
|
34
|
+
<AssetsTableDropzone
|
|
35
|
+
onDrop={vi.fn()}
|
|
36
|
+
className='custom-zone'>
|
|
37
|
+
<span>content</span>
|
|
38
|
+
</AssetsTableDropzone>
|
|
39
|
+
);
|
|
40
|
+
|
|
41
|
+
expect(container?.firstElementChild?.className).toBe('custom-zone');
|
|
42
|
+
});
|
|
43
|
+
|
|
44
|
+
it('defaults to empty className when none is provided', () => {
|
|
45
|
+
const { container } = render(
|
|
46
|
+
<AssetsTableDropzone onDrop={vi.fn()}>
|
|
47
|
+
<span>content</span>
|
|
48
|
+
</AssetsTableDropzone>
|
|
49
|
+
);
|
|
50
|
+
|
|
51
|
+
expect(container?.firstElementChild?.className).toBe('');
|
|
52
|
+
});
|
|
53
|
+
|
|
54
|
+
it('accepts NativeTypes.FILE in the drop config', () => {
|
|
55
|
+
render(
|
|
56
|
+
<AssetsTableDropzone onDrop={vi.fn()}>
|
|
57
|
+
<span>content</span>
|
|
58
|
+
</AssetsTableDropzone>
|
|
59
|
+
);
|
|
60
|
+
|
|
61
|
+
expect(capturedDropConfig.accept).toContain('__NATIVE_FILE__');
|
|
62
|
+
});
|
|
63
|
+
|
|
64
|
+
it('calls onDrop with props and monitor when an item is dropped', () => {
|
|
65
|
+
const onDrop = vi.fn();
|
|
66
|
+
render(
|
|
67
|
+
<AssetsTableDropzone onDrop={onDrop}>
|
|
68
|
+
<span>content</span>
|
|
69
|
+
</AssetsTableDropzone>
|
|
70
|
+
);
|
|
71
|
+
|
|
72
|
+
const mockMonitor = { isOver: vi.fn(), canDrop: vi.fn() };
|
|
73
|
+
capturedDropConfig.drop({}, mockMonitor);
|
|
74
|
+
|
|
75
|
+
expect(onDrop).toHaveBeenCalledWith(expect.objectContaining({ onDrop }), mockMonitor);
|
|
76
|
+
});
|
|
77
|
+
|
|
78
|
+
it('does not throw when onDrop is falsy', () => {
|
|
79
|
+
render(
|
|
80
|
+
<AssetsTableDropzone onDrop={undefined as any}>
|
|
81
|
+
<span>content</span>
|
|
82
|
+
</AssetsTableDropzone>
|
|
83
|
+
);
|
|
84
|
+
|
|
85
|
+
const mockMonitor = { isOver: vi.fn(), canDrop: vi.fn() };
|
|
86
|
+
expect(() => capturedDropConfig.drop({}, mockMonitor)).not.toThrow();
|
|
87
|
+
});
|
|
88
|
+
|
|
89
|
+
it('uses onExternalCollect when provided', () => {
|
|
90
|
+
const onExternalCollect = vi.fn(() => ({ custom: true }));
|
|
91
|
+
render(
|
|
92
|
+
<AssetsTableDropzone
|
|
93
|
+
onDrop={vi.fn()}
|
|
94
|
+
onExternalCollect={onExternalCollect}>
|
|
95
|
+
<span>content</span>
|
|
96
|
+
</AssetsTableDropzone>
|
|
97
|
+
);
|
|
98
|
+
|
|
99
|
+
const mockMonitor = { isOver: vi.fn(), canDrop: vi.fn() };
|
|
100
|
+
const result = capturedDropConfig.collect(mockMonitor);
|
|
101
|
+
|
|
102
|
+
expect(onExternalCollect).toHaveBeenCalledWith(mockMonitor);
|
|
103
|
+
expect(result).toEqual({ custom: true });
|
|
104
|
+
});
|
|
105
|
+
|
|
106
|
+
it('uses default collect when onExternalCollect is not provided', () => {
|
|
107
|
+
render(
|
|
108
|
+
<AssetsTableDropzone onDrop={vi.fn()}>
|
|
109
|
+
<span>content</span>
|
|
110
|
+
</AssetsTableDropzone>
|
|
111
|
+
);
|
|
112
|
+
|
|
113
|
+
const mockIsOver = vi.fn();
|
|
114
|
+
const mockCanDrop = vi.fn();
|
|
115
|
+
const mockMonitor = { isOver: mockIsOver, canDrop: mockCanDrop };
|
|
116
|
+
const result = capturedDropConfig.collect(mockMonitor);
|
|
117
|
+
|
|
118
|
+
expect(result).toEqual({ isOver: mockIsOver, canDrop: mockCanDrop });
|
|
119
|
+
});
|
|
120
|
+
|
|
121
|
+
it('does not attach dropRef when disable is true', () => {
|
|
122
|
+
const { container } = render(
|
|
123
|
+
<AssetsTableDropzone
|
|
124
|
+
onDrop={vi.fn()}
|
|
125
|
+
disable={true}>
|
|
126
|
+
<span>content</span>
|
|
127
|
+
</AssetsTableDropzone>
|
|
128
|
+
);
|
|
129
|
+
|
|
130
|
+
expect(container.firstElementChild).toBeTruthy();
|
|
131
|
+
});
|
|
132
|
+
});
|
|
@@ -0,0 +1,119 @@
|
|
|
1
|
+
import { describe, it, expect, vi } from 'vitest';
|
|
2
|
+
import React from 'react';
|
|
3
|
+
import { render } from '@testing-library/react';
|
|
4
|
+
|
|
5
|
+
const MOCK_DURATION = '00:01:30:00';
|
|
6
|
+
const MOCK_AUDIO_DURATION = '00:02:15';
|
|
7
|
+
|
|
8
|
+
vi.mock('../../Util', async (importOriginal) => {
|
|
9
|
+
const actual = (await importOriginal()) as any;
|
|
10
|
+
return {
|
|
11
|
+
...actual,
|
|
12
|
+
getDuration: vi.fn(() => MOCK_DURATION),
|
|
13
|
+
formatAudioDuration: vi.fn(() => MOCK_AUDIO_DURATION)
|
|
14
|
+
};
|
|
15
|
+
});
|
|
16
|
+
|
|
17
|
+
import AssetsTableDurationCell, { secondsToTime } from './AssetsTableDurationCell';
|
|
18
|
+
import { getDuration, formatAudioDuration } from '../../Util';
|
|
19
|
+
import { ASSET_TYPES } from '../../constants/assets';
|
|
20
|
+
|
|
21
|
+
const buildCellProp = (overrides: Record<string, any> = {}) => ({
|
|
22
|
+
row: {
|
|
23
|
+
original: {
|
|
24
|
+
type: 'video',
|
|
25
|
+
data: '{}',
|
|
26
|
+
rate: 30,
|
|
27
|
+
frame_count: 2700,
|
|
28
|
+
duration: 0,
|
|
29
|
+
...overrides
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
});
|
|
33
|
+
|
|
34
|
+
describe('AssetsTableDurationCell', () => {
|
|
35
|
+
it('renders duration using getDuration when rate and frame_count exist', () => {
|
|
36
|
+
const cell = buildCellProp({ type: 'video', rate: 30, frame_count: 2700 });
|
|
37
|
+
const { container } = render(<AssetsTableDurationCell cell={cell} />);
|
|
38
|
+
|
|
39
|
+
expect(getDuration).toHaveBeenCalledWith(2700, 30);
|
|
40
|
+
expect(container.querySelector('.asset-duration-cell')).toBeTruthy();
|
|
41
|
+
expect(container.textContent).toBe(MOCK_DURATION);
|
|
42
|
+
});
|
|
43
|
+
|
|
44
|
+
it('renders empty duration when rate is missing', () => {
|
|
45
|
+
vi.mocked(getDuration).mockClear();
|
|
46
|
+
const cell = buildCellProp({ type: 'video', rate: null, frame_count: 100 });
|
|
47
|
+
const { container } = render(<AssetsTableDurationCell cell={cell} />);
|
|
48
|
+
|
|
49
|
+
expect(getDuration).not.toHaveBeenCalled();
|
|
50
|
+
expect(container.querySelector('.asset-duration-cell')).toBeTruthy();
|
|
51
|
+
});
|
|
52
|
+
|
|
53
|
+
it('renders frame count for image_sequence type', () => {
|
|
54
|
+
const cell = buildCellProp({
|
|
55
|
+
type: ASSET_TYPES.IMAGE_SEQUENCE,
|
|
56
|
+
duration: 120,
|
|
57
|
+
rate: null,
|
|
58
|
+
frame_count: null
|
|
59
|
+
});
|
|
60
|
+
const { container } = render(<AssetsTableDurationCell cell={cell} />);
|
|
61
|
+
|
|
62
|
+
expect(container.textContent).toBe('120 frames');
|
|
63
|
+
});
|
|
64
|
+
|
|
65
|
+
it('parses data JSON and renders duration for video_composition type', () => {
|
|
66
|
+
const compositionData = JSON.stringify({ frames: 900, rate: 24 });
|
|
67
|
+
const cell = buildCellProp({
|
|
68
|
+
type: ASSET_TYPES.VIDEO_COMPOSITION,
|
|
69
|
+
data: compositionData,
|
|
70
|
+
rate: null,
|
|
71
|
+
frame_count: null
|
|
72
|
+
});
|
|
73
|
+
const { container } = render(<AssetsTableDurationCell cell={cell} />);
|
|
74
|
+
|
|
75
|
+
expect(getDuration).toHaveBeenCalledWith(900, 24);
|
|
76
|
+
expect(container.textContent).toBe(MOCK_DURATION);
|
|
77
|
+
});
|
|
78
|
+
|
|
79
|
+
it('renders formatted audio duration for audio type', () => {
|
|
80
|
+
const cell = buildCellProp({
|
|
81
|
+
type: ASSET_TYPES.AUDIO,
|
|
82
|
+
duration: 135,
|
|
83
|
+
rate: null,
|
|
84
|
+
frame_count: null
|
|
85
|
+
});
|
|
86
|
+
const { container } = render(<AssetsTableDurationCell cell={cell} />);
|
|
87
|
+
|
|
88
|
+
expect(formatAudioDuration).toHaveBeenCalledWith(135);
|
|
89
|
+
expect(container.textContent).toBe(MOCK_AUDIO_DURATION);
|
|
90
|
+
});
|
|
91
|
+
|
|
92
|
+
it('renders empty div when duration is null', () => {
|
|
93
|
+
vi.mocked(getDuration).mockReturnValueOnce(null as any);
|
|
94
|
+
const cell = buildCellProp({ type: 'unknown', rate: 30, frame_count: 100 });
|
|
95
|
+
const { container } = render(<AssetsTableDurationCell cell={cell} />);
|
|
96
|
+
const durationCell = container.querySelector('.asset-duration-cell');
|
|
97
|
+
|
|
98
|
+
expect(durationCell).toBeTruthy();
|
|
99
|
+
expect(durationCell?.textContent).toBe('');
|
|
100
|
+
});
|
|
101
|
+
});
|
|
102
|
+
|
|
103
|
+
describe('secondsToTime', () => {
|
|
104
|
+
it('formats seconds into minutes:seconds', () => {
|
|
105
|
+
expect(secondsToTime(90)).toBe('1:30');
|
|
106
|
+
});
|
|
107
|
+
|
|
108
|
+
it('pads single-digit seconds with a leading zero', () => {
|
|
109
|
+
expect(secondsToTime(65)).toBe('1:05');
|
|
110
|
+
});
|
|
111
|
+
|
|
112
|
+
it('handles zero seconds', () => {
|
|
113
|
+
expect(secondsToTime(0)).toBe('0:00');
|
|
114
|
+
});
|
|
115
|
+
|
|
116
|
+
it('handles large values', () => {
|
|
117
|
+
expect(secondsToTime(3661)).toBe('61:01');
|
|
118
|
+
});
|
|
119
|
+
});
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import { describe, it, expect, vi } from 'vitest';
|
|
2
|
+
import React from 'react';
|
|
3
|
+
import { render } from '@testing-library/react';
|
|
4
|
+
|
|
5
|
+
vi.mock('../../constants/icons', () => ({
|
|
6
|
+
ICON_GLOBE: <span data-testid='icon-globe'>globe</span>
|
|
7
|
+
}));
|
|
8
|
+
|
|
9
|
+
import AssetsTableGlobalCellMemoized from './AssetsTableGlobalCell';
|
|
10
|
+
|
|
11
|
+
const buildCellProp = (storyId: any) => ({
|
|
12
|
+
row: { original: { story_id: storyId } }
|
|
13
|
+
});
|
|
14
|
+
|
|
15
|
+
describe('AssetsTableGlobalCell', () => {
|
|
16
|
+
it('hides the globe icon when story_id is a truthy string', () => {
|
|
17
|
+
const { container, queryByTestId } = render(
|
|
18
|
+
<AssetsTableGlobalCellMemoized cell={buildCellProp('story-123')} />
|
|
19
|
+
);
|
|
20
|
+
|
|
21
|
+
expect(container.querySelector('.asset-global-cell')).toBeTruthy();
|
|
22
|
+
expect(queryByTestId('icon-globe')).toBeNull();
|
|
23
|
+
});
|
|
24
|
+
|
|
25
|
+
it('hides the globe icon when story_id is undefined', () => {
|
|
26
|
+
const { queryByTestId } = render(
|
|
27
|
+
<AssetsTableGlobalCellMemoized cell={buildCellProp(undefined)} />
|
|
28
|
+
);
|
|
29
|
+
|
|
30
|
+
expect(queryByTestId('icon-globe')).toBeNull();
|
|
31
|
+
});
|
|
32
|
+
|
|
33
|
+
it('shows the globe icon when story_id is null', () => {
|
|
34
|
+
const { getByTestId } = render(
|
|
35
|
+
<AssetsTableGlobalCellMemoized cell={buildCellProp(null)} />
|
|
36
|
+
);
|
|
37
|
+
|
|
38
|
+
expect(getByTestId('icon-globe')).toBeTruthy();
|
|
39
|
+
});
|
|
40
|
+
|
|
41
|
+
it('shows the globe icon when story_id is an empty string', () => {
|
|
42
|
+
const { getByTestId } = render(<AssetsTableGlobalCellMemoized cell={buildCellProp('')} />);
|
|
43
|
+
|
|
44
|
+
expect(getByTestId('icon-globe')).toBeTruthy();
|
|
45
|
+
});
|
|
46
|
+
});
|