@imposium-hub/components 2.16.0-0 → 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.
@@ -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
+ });
@@ -0,0 +1,166 @@
1
+ import { describe, it, expect, vi, beforeEach, afterEach } from 'vitest';
2
+ import React from 'react';
3
+ import { render, act } from '@testing-library/react';
4
+ import { Provider } from 'react-redux';
5
+ import { legacy_createStore as createStore } from 'redux';
6
+ import { assets as copy } from '../../constants/copy';
7
+
8
+ let capturedTextFieldProps: any = {};
9
+
10
+ vi.mock('../text-field/TextField', () => ({
11
+ default: (props: any) => {
12
+ capturedTextFieldProps = props;
13
+ return (
14
+ <div
15
+ data-testid='mock-text-field'
16
+ data-value={props.value}
17
+ data-disabled={props.disabled}>
18
+ <input
19
+ value={props.value || ''}
20
+ onChange={(e) => props.onChange((e.target as HTMLInputElement).value)}
21
+ readOnly={props.disabled}
22
+ />
23
+ </div>
24
+ );
25
+ }
26
+ }));
27
+
28
+ vi.mock('../determinate-loader/DeterminateLoader', () => ({
29
+ DeterminateLoader: ({ progress, text }: any) => (
30
+ <div
31
+ data-testid='determinate-loader'
32
+ data-progress={progress}>
33
+ {text}
34
+ </div>
35
+ )
36
+ }));
37
+
38
+ vi.mock('../../redux/actions/asset-list', () => ({
39
+ updateAssetName: vi.fn((_api, _id, _name) => ({ type: 'MOCK_UPDATE_NAME' })),
40
+ default: {}
41
+ }));
42
+
43
+ import AssetsTableNameCellConnected from './AssetsTableNameCell';
44
+ import { updateAssetName } from '../../redux/actions/asset-list';
45
+
46
+ const MOCK_ASSET_ID = 'asset-abc';
47
+ const MOCK_ASSET_NAME = 'my-video.mp4';
48
+ const MOCK_API = { updateAsset: vi.fn() };
49
+
50
+ const createMockStore = () => createStore((state = {}) => state);
51
+
52
+ const buildCellProp = (overrides: Record<string, any> = {}) => ({
53
+ row: {
54
+ original: {
55
+ name: MOCK_ASSET_NAME,
56
+ id: MOCK_ASSET_ID,
57
+ percent: undefined,
58
+ error: undefined,
59
+ ...overrides
60
+ }
61
+ }
62
+ });
63
+
64
+ const renderComponent = (cellOverrides: Record<string, any> = {}, disabled = false) => {
65
+ const store = createMockStore();
66
+ const cell = buildCellProp(cellOverrides);
67
+
68
+ const result = render(
69
+ <Provider store={store}>
70
+ <AssetsTableNameCellConnected
71
+ cell={cell}
72
+ api={MOCK_API}
73
+ disabled={disabled}
74
+ />
75
+ </Provider>
76
+ );
77
+
78
+ return result;
79
+ };
80
+
81
+ describe('AssetsTableNameCell', () => {
82
+ beforeEach(() => {
83
+ vi.useFakeTimers();
84
+ vi.mocked(updateAssetName).mockClear();
85
+ capturedTextFieldProps = {};
86
+ });
87
+
88
+ afterEach(() => {
89
+ vi.useRealTimers();
90
+ });
91
+
92
+ it('renders a TextField with the asset name when not uploading', () => {
93
+ const { getByTestId } = renderComponent();
94
+ const textField = getByTestId('mock-text-field');
95
+
96
+ expect(textField.getAttribute('data-value')).toBe(MOCK_ASSET_NAME);
97
+ expect(textField.getAttribute('data-disabled')).toBe('false');
98
+ });
99
+
100
+ it('renders a TextField as disabled when disabled prop is true', () => {
101
+ const { getByTestId } = renderComponent({}, true);
102
+ const textField = getByTestId('mock-text-field');
103
+
104
+ expect(textField.getAttribute('data-disabled')).toBe('true');
105
+ });
106
+
107
+ it('renders DeterminateLoader when upload progress is under 100', () => {
108
+ const { getByTestId } = renderComponent({ percent: 45 });
109
+ const loader = getByTestId('determinate-loader');
110
+
111
+ expect(loader.getAttribute('data-progress')).toBe('45');
112
+ expect(loader.textContent).toBe(MOCK_ASSET_NAME);
113
+ });
114
+
115
+ it('renders prepare phase text when upload progress is 100 and no error', () => {
116
+ const { container } = renderComponent({ percent: 100 });
117
+
118
+ expect(container.textContent).toBe(copy.uploads.preparePhase);
119
+ });
120
+
121
+ it('renders error message when upload progress is 100 and error exists', () => {
122
+ const errorMessage = 'Upload failed';
123
+ const { container } = renderComponent({ percent: 100, error: errorMessage });
124
+
125
+ expect(container.textContent).toBe(errorMessage);
126
+ });
127
+
128
+ it('dispatches updateAssetName after debounce on text change', () => {
129
+ renderComponent();
130
+
131
+ act(() => {
132
+ capturedTextFieldProps.onChange('new-name');
133
+ });
134
+
135
+ expect(updateAssetName).not.toHaveBeenCalled();
136
+
137
+ act(() => {
138
+ vi.advanceTimersByTime(1000);
139
+ });
140
+
141
+ expect(updateAssetName).toHaveBeenCalledWith(MOCK_API, MOCK_ASSET_ID, 'new-name');
142
+ });
143
+
144
+ it('resets debounce timer on rapid changes', () => {
145
+ renderComponent();
146
+
147
+ act(() => {
148
+ capturedTextFieldProps.onChange('first');
149
+ });
150
+
151
+ act(() => {
152
+ vi.advanceTimersByTime(500);
153
+ });
154
+
155
+ act(() => {
156
+ capturedTextFieldProps.onChange('second');
157
+ });
158
+
159
+ act(() => {
160
+ vi.advanceTimersByTime(1000);
161
+ });
162
+
163
+ expect(updateAssetName).toHaveBeenCalledTimes(1);
164
+ expect(updateAssetName).toHaveBeenCalledWith(MOCK_API, MOCK_ASSET_ID, 'second');
165
+ });
166
+ });
@@ -0,0 +1,95 @@
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
+ vi.mock('../text-field/TextField', () => ({
8
+ default: ({ className, submittable, submittableType, value, doSubmit, header }: any) => (
9
+ <div
10
+ data-testid='mock-text-field'
11
+ data-classname={className}
12
+ data-submittable={submittable}
13
+ data-submittable-type={submittableType}
14
+ data-value={value || ''}
15
+ data-header={header}>
16
+ <button
17
+ data-testid='submit-trigger'
18
+ onClick={() => doSubmit('new-filter-value')}>
19
+ Submit
20
+ </button>
21
+ </div>
22
+ )
23
+ }));
24
+
25
+ vi.mock('../../redux/actions/asset-filters', () => ({
26
+ updateFilters: vi.fn((filters) => ({ type: 'assetFilters/UPDATE', newFilters: filters })),
27
+ default: { UPDATE: 'assetFilters/UPDATE', RESET: 'footageFilters/RESET' }
28
+ }));
29
+
30
+ import AssetsTableNameFilterMemoized from './AssetsTableNameFilter';
31
+
32
+ const MOCK_NAME_FILTER = 'existing-name-filter';
33
+
34
+ const createMockStore = (nameFilter = '') => {
35
+ const initialState = { assetFilters: { name: nameFilter } };
36
+ return createStore((state: any = initialState, action: any) => {
37
+ if (action.type === 'assetFilters/UPDATE') {
38
+ return {
39
+ ...state,
40
+ assetFilters: { ...state.assetFilters, ...action.newFilters }
41
+ };
42
+ }
43
+ return state;
44
+ });
45
+ };
46
+
47
+ const renderComponent = (nameFilter = '') => {
48
+ const store = createMockStore(nameFilter);
49
+
50
+ const result = render(
51
+ <Provider store={store}>
52
+ <AssetsTableNameFilterMemoized />
53
+ </Provider>
54
+ );
55
+
56
+ return { ...result, store };
57
+ };
58
+
59
+ describe('AssetsTableNameFilter', () => {
60
+ it('renders the TextField with correct props', () => {
61
+ const { getByTestId } = renderComponent(MOCK_NAME_FILTER);
62
+ const textField = getByTestId('mock-text-field');
63
+
64
+ expect(textField.getAttribute('data-classname')).toBe('asset-name');
65
+ expect(textField.getAttribute('data-submittable')).toBe('true');
66
+ expect(textField.getAttribute('data-submittable-type')).toBe('search');
67
+ expect(textField.getAttribute('data-value')).toBe(MOCK_NAME_FILTER);
68
+ expect(textField.getAttribute('data-header')).toBe('true');
69
+ });
70
+
71
+ it('dispatches updateFilters with the submitted name value', () => {
72
+ const { getByTestId, store } = renderComponent();
73
+ const submitButton = getByTestId('submit-trigger');
74
+
75
+ submitButton.click();
76
+
77
+ const storeState = store.getState();
78
+ expect(storeState.assetFilters.name).toBe('new-filter-value');
79
+ });
80
+
81
+ it('renders with an empty filter value when no name is set', () => {
82
+ const { getByTestId } = renderComponent();
83
+ const textField = getByTestId('mock-text-field');
84
+
85
+ expect(textField.getAttribute('data-value')).toBe('');
86
+ });
87
+
88
+ it('passes the current filter value from the redux store', () => {
89
+ const filterValue = 'search-term-xyz';
90
+ const { getByTestId } = renderComponent(filterValue);
91
+ const textField = getByTestId('mock-text-field');
92
+
93
+ expect(textField.getAttribute('data-value')).toBe(filterValue);
94
+ });
95
+ });