box-ui-elements 23.4.0-beta.16 → 23.4.0-beta.18
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/explorer.js +1 -1
- package/dist/preview.js +1 -1
- package/dist/sidebar.js +1 -1
- package/es/elements/common/nav-button/BackButton.js +5 -8
- package/es/elements/common/nav-button/BackButton.js.flow +8 -18
- package/es/elements/common/nav-button/BackButton.js.map +1 -1
- package/{src/elements/common/types/SidebarNavigation.flow.js → es/elements/common/types/SidebarNavigation.js.flow} +9 -23
- package/es/elements/content-sidebar/versions/StaticVersionSidebar.js +6 -3
- package/es/elements/content-sidebar/versions/StaticVersionSidebar.js.flow +47 -42
- package/es/elements/content-sidebar/versions/StaticVersionSidebar.js.map +1 -1
- package/es/elements/content-sidebar/versions/VersionsGroup.js.flow +3 -0
- package/es/elements/content-sidebar/versions/VersionsGroup.js.map +1 -1
- package/es/elements/content-sidebar/versions/VersionsList.js +16 -8
- package/es/elements/content-sidebar/versions/VersionsList.js.flow +35 -17
- package/es/elements/content-sidebar/versions/VersionsList.js.map +1 -1
- package/es/elements/content-sidebar/versions/VersionsMenu.js.flow +3 -0
- package/es/elements/content-sidebar/versions/VersionsMenu.js.map +1 -1
- package/es/elements/content-sidebar/versions/VersionsSidebar.js +6 -3
- package/es/elements/content-sidebar/versions/VersionsSidebar.js.flow +48 -39
- package/es/elements/content-sidebar/versions/VersionsSidebar.js.map +1 -1
- package/es/src/test-utils/testing-library.d.ts +2 -1
- package/es/test-utils/testing-library.js +4 -1
- package/es/test-utils/testing-library.js.map +1 -1
- package/package.json +3 -3
- package/src/elements/common/nav-button/BackButton.js +8 -18
- package/src/elements/common/nav-button/__tests__/BackButton.test.js +36 -27
- package/{es/elements/common/types/SidebarNavigation.flow.js.flow → src/elements/common/types/SidebarNavigation.js.flow} +9 -23
- package/src/elements/content-sidebar/versions/StaticVersionSidebar.js +47 -42
- package/src/elements/content-sidebar/versions/VersionsGroup.js +3 -0
- package/src/elements/content-sidebar/versions/VersionsList.js +35 -17
- package/src/elements/content-sidebar/versions/VersionsMenu.js +3 -0
- package/src/elements/content-sidebar/versions/VersionsSidebar.js +48 -39
- package/src/elements/content-sidebar/versions/__tests__/StaticVersionSidebar.test.js +171 -0
- package/src/elements/content-sidebar/versions/__tests__/VersionsList.test.js +138 -13
- package/src/elements/content-sidebar/versions/__tests__/VersionsMenu.test.js +75 -23
- package/src/elements/content-sidebar/versions/__tests__/VersionsSidebar.test.js +147 -20
- package/src/test-utils/testing-library.tsx +4 -1
- package/es/elements/common/types/SidebarNavigation.flow.js +0 -14
- package/es/elements/common/types/SidebarNavigation.flow.js.map +0 -1
- package/src/elements/common/nav-button/__tests__/__snapshots__/BackButton.test.js.snap +0 -64
- package/src/elements/content-sidebar/versions/__tests__/__snapshots__/VersionsList.test.js.snap +0 -45
- package/src/elements/content-sidebar/versions/__tests__/__snapshots__/VersionsSidebar.test.js.snap +0 -92
|
@@ -6,6 +6,7 @@
|
|
|
6
6
|
|
|
7
7
|
import * as React from 'react';
|
|
8
8
|
import { FormattedMessage } from 'react-intl';
|
|
9
|
+
import { Route } from 'react-router-dom';
|
|
9
10
|
import type { MessageDescriptor } from 'react-intl';
|
|
10
11
|
import InlineError from '../../../components/inline-error';
|
|
11
12
|
import messages from './messages';
|
|
@@ -36,47 +37,55 @@ const VersionsSidebar = ({ error, isLoading, parentName, versions, ...rest }: Pr
|
|
|
36
37
|
const showError = !!error;
|
|
37
38
|
|
|
38
39
|
return (
|
|
39
|
-
<
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
<
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
40
|
+
<Route>
|
|
41
|
+
{({ history }) => (
|
|
42
|
+
<SidebarContent
|
|
43
|
+
className="bcs-Versions"
|
|
44
|
+
data-resin-component="preview"
|
|
45
|
+
data-resin-feature="versions"
|
|
46
|
+
title={
|
|
47
|
+
<>
|
|
48
|
+
<BackButton data-resin-target="back" onClick={() => history.push(`/${parentName}`)} />
|
|
49
|
+
<FormattedMessage {...messages.versionsTitle} />
|
|
50
|
+
</>
|
|
51
|
+
}
|
|
52
|
+
>
|
|
53
|
+
<LoadingIndicatorWrapper
|
|
54
|
+
className="bcs-Versions-content"
|
|
55
|
+
crawlerPosition="top"
|
|
56
|
+
isLoading={isLoading}
|
|
57
|
+
>
|
|
58
|
+
{showError && (
|
|
59
|
+
<InlineError title={<FormattedMessage {...messages.versionServerError} />}>
|
|
60
|
+
<FormattedMessage {...error} />
|
|
61
|
+
</InlineError>
|
|
62
|
+
)}
|
|
56
63
|
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
64
|
+
{showEmpty && (
|
|
65
|
+
<div className="bcs-Versions-empty">
|
|
66
|
+
<FormattedMessage {...messages.versionsEmpty} />
|
|
67
|
+
</div>
|
|
68
|
+
)}
|
|
62
69
|
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
70
|
+
{showVersions && (
|
|
71
|
+
<div className="bcs-Versions-menu" data-testid="bcs-Versions-menu">
|
|
72
|
+
<VersionsMenu versions={versions} {...rest} />
|
|
73
|
+
</div>
|
|
74
|
+
)}
|
|
75
|
+
{showLimit && (
|
|
76
|
+
<div className="bcs-Versions-maxEntries" data-testid="max-versions">
|
|
77
|
+
<FormattedMessage
|
|
78
|
+
{...messages.versionMaxEntries}
|
|
79
|
+
values={{
|
|
80
|
+
maxVersions: MAX_VERSIONS,
|
|
81
|
+
}}
|
|
82
|
+
/>
|
|
83
|
+
</div>
|
|
84
|
+
)}
|
|
85
|
+
</LoadingIndicatorWrapper>
|
|
86
|
+
</SidebarContent>
|
|
87
|
+
)}
|
|
88
|
+
</Route>
|
|
80
89
|
);
|
|
81
90
|
};
|
|
82
91
|
|
|
@@ -0,0 +1,171 @@
|
|
|
1
|
+
import * as React from 'react';
|
|
2
|
+
import { MemoryRouter, Route } from 'react-router-dom';
|
|
3
|
+
import { render, screen, userEvent } from '../../../../test-utils/testing-library';
|
|
4
|
+
import StaticVersionSidebar from '../StaticVersionSidebar';
|
|
5
|
+
|
|
6
|
+
jest.mock('../../../common/nav-button', () => ({
|
|
7
|
+
BackButton: ({ onClick, 'data-resin-target': dataResinTarget }) => (
|
|
8
|
+
<button type="button" onClick={onClick} data-resin-target={dataResinTarget} data-testid="back-button">
|
|
9
|
+
Back
|
|
10
|
+
</button>
|
|
11
|
+
),
|
|
12
|
+
}));
|
|
13
|
+
|
|
14
|
+
jest.mock('../VersionsMenu', () => ({ versions, fileId, versionCount, versionLimit }) => (
|
|
15
|
+
<div data-testid="versions-menu">
|
|
16
|
+
Versions: {versions.length}, FileId: {fileId}, Count: {versionCount}, Limit: {versionLimit}
|
|
17
|
+
</div>
|
|
18
|
+
));
|
|
19
|
+
|
|
20
|
+
jest.mock('../../../../components/loading-indicator', () => ({
|
|
21
|
+
LoadingIndicatorWrapper: ({ children, isLoading, className, crawlerPosition }) => (
|
|
22
|
+
<div
|
|
23
|
+
className={className}
|
|
24
|
+
data-testid="loading-wrapper"
|
|
25
|
+
data-loading={isLoading}
|
|
26
|
+
data-crawler-position={crawlerPosition}
|
|
27
|
+
>
|
|
28
|
+
{children}
|
|
29
|
+
</div>
|
|
30
|
+
),
|
|
31
|
+
}));
|
|
32
|
+
|
|
33
|
+
jest.mock(
|
|
34
|
+
'../../../../components/primary-button',
|
|
35
|
+
() =>
|
|
36
|
+
({ children, onClick, className, 'data-resin-target': dataResinTarget, type }) => (
|
|
37
|
+
<button
|
|
38
|
+
className={className}
|
|
39
|
+
onClick={onClick}
|
|
40
|
+
data-resin-target={dataResinTarget}
|
|
41
|
+
type={type}
|
|
42
|
+
data-testid="upgrade-button"
|
|
43
|
+
>
|
|
44
|
+
{children}
|
|
45
|
+
</button>
|
|
46
|
+
),
|
|
47
|
+
);
|
|
48
|
+
|
|
49
|
+
jest.mock('../../../../illustration/BoxDrive140', () => ({ className }) => (
|
|
50
|
+
<div className={className} data-testid="box-drive-icon" />
|
|
51
|
+
));
|
|
52
|
+
|
|
53
|
+
describe('elements/content-sidebar/versions/StaticVersionSidebar', () => {
|
|
54
|
+
const defaultProps = {
|
|
55
|
+
isLoading: false,
|
|
56
|
+
onUpgradeClick: jest.fn(),
|
|
57
|
+
parentName: 'activity',
|
|
58
|
+
};
|
|
59
|
+
const renderComponent = (props = {}) => {
|
|
60
|
+
return render(
|
|
61
|
+
<MemoryRouter initialEntries={['/versions']}>
|
|
62
|
+
<StaticVersionSidebar {...defaultProps} {...props} />
|
|
63
|
+
</MemoryRouter>,
|
|
64
|
+
);
|
|
65
|
+
};
|
|
66
|
+
|
|
67
|
+
beforeEach(() => {
|
|
68
|
+
jest.clearAllMocks();
|
|
69
|
+
});
|
|
70
|
+
|
|
71
|
+
test('should render with all main sections', () => {
|
|
72
|
+
renderComponent();
|
|
73
|
+
|
|
74
|
+
expect(screen.getByRole('tabpanel')).toBeInTheDocument();
|
|
75
|
+
expect(screen.getByRole('tabpanel')).toHaveClass('bcs-StaticVersionSidebar');
|
|
76
|
+
expect(screen.getByRole('tabpanel')).toHaveAttribute('data-resin-component', 'preview');
|
|
77
|
+
expect(screen.getByRole('tabpanel')).toHaveAttribute('data-resin-feature', 'versions');
|
|
78
|
+
|
|
79
|
+
expect(screen.getByRole('heading', { level: 3 })).toBeInTheDocument();
|
|
80
|
+
expect(screen.getByTestId('back-button')).toBeInTheDocument();
|
|
81
|
+
expect(screen.getByText('Version History')).toBeInTheDocument();
|
|
82
|
+
|
|
83
|
+
expect(screen.getByTestId('loading-wrapper')).toBeInTheDocument();
|
|
84
|
+
expect(screen.getByTestId('versions-menu')).toBeInTheDocument();
|
|
85
|
+
|
|
86
|
+
const boxDriveIcon = screen.getByTestId('box-drive-icon');
|
|
87
|
+
expect(boxDriveIcon).toBeInTheDocument();
|
|
88
|
+
expect(boxDriveIcon).toHaveClass('bcs-StaticVersionSidebar-upsell-icon');
|
|
89
|
+
expect(screen.getByTestId('upgrade-button')).toBeInTheDocument();
|
|
90
|
+
expect(screen.getByText('Upgrade Now')).toBeInTheDocument();
|
|
91
|
+
expect(
|
|
92
|
+
screen.getByText(
|
|
93
|
+
'Sorry, version history is not available with your current account plan. To access versioning, select from one of our paid plans.',
|
|
94
|
+
),
|
|
95
|
+
).toBeInTheDocument();
|
|
96
|
+
});
|
|
97
|
+
|
|
98
|
+
test('should pass correct props to BackButton', () => {
|
|
99
|
+
renderComponent({ parentName: 'details' });
|
|
100
|
+
|
|
101
|
+
const backButton = screen.getByTestId('back-button');
|
|
102
|
+
expect(backButton).toHaveAttribute('data-resin-target', 'back');
|
|
103
|
+
});
|
|
104
|
+
|
|
105
|
+
test('should navigate when BackButton is clicked', async () => {
|
|
106
|
+
let currentLocation;
|
|
107
|
+
|
|
108
|
+
const TestWrapper = ({ children }) => (
|
|
109
|
+
<MemoryRouter initialEntries={['/versions']}>
|
|
110
|
+
<Route
|
|
111
|
+
path="*"
|
|
112
|
+
render={({ location }) => {
|
|
113
|
+
currentLocation = location;
|
|
114
|
+
return children;
|
|
115
|
+
}}
|
|
116
|
+
/>
|
|
117
|
+
</MemoryRouter>
|
|
118
|
+
);
|
|
119
|
+
|
|
120
|
+
render(
|
|
121
|
+
<TestWrapper>
|
|
122
|
+
<StaticVersionSidebar {...defaultProps} parentName="details" />
|
|
123
|
+
</TestWrapper>,
|
|
124
|
+
);
|
|
125
|
+
|
|
126
|
+
expect(currentLocation.pathname).toBe('/versions');
|
|
127
|
+
|
|
128
|
+
const backButton = screen.getByTestId('back-button');
|
|
129
|
+
const user = userEvent();
|
|
130
|
+
await user.click(backButton);
|
|
131
|
+
|
|
132
|
+
expect(currentLocation.pathname).toBe('/details');
|
|
133
|
+
});
|
|
134
|
+
|
|
135
|
+
test('should pass loading state to LoadingIndicatorWrapper', () => {
|
|
136
|
+
renderComponent({ isLoading: true });
|
|
137
|
+
|
|
138
|
+
const loadingWrapper = screen.getByTestId('loading-wrapper');
|
|
139
|
+
expect(loadingWrapper).toHaveAttribute('data-loading', 'true');
|
|
140
|
+
expect(loadingWrapper).toHaveAttribute('data-crawler-position', 'top');
|
|
141
|
+
expect(loadingWrapper).toHaveClass('bcs-StaticVersionSidebar-content');
|
|
142
|
+
});
|
|
143
|
+
|
|
144
|
+
test('should render VersionsMenu with correct props', () => {
|
|
145
|
+
renderComponent();
|
|
146
|
+
|
|
147
|
+
const versionsMenu = screen.getByTestId('versions-menu');
|
|
148
|
+
expect(versionsMenu).toHaveTextContent('Versions: 3, FileId: 1, Count: 3, Limit: 3');
|
|
149
|
+
});
|
|
150
|
+
|
|
151
|
+
test('should call onUpgradeClick when upgrade button is clicked', async () => {
|
|
152
|
+
const mockOnUpgradeClick = jest.fn();
|
|
153
|
+
const user = userEvent();
|
|
154
|
+
renderComponent({ onUpgradeClick: mockOnUpgradeClick });
|
|
155
|
+
|
|
156
|
+
const upgradeButton = screen.getByTestId('upgrade-button');
|
|
157
|
+
await user.click(upgradeButton);
|
|
158
|
+
|
|
159
|
+
expect(mockOnUpgradeClick).toHaveBeenCalledTimes(1);
|
|
160
|
+
});
|
|
161
|
+
|
|
162
|
+
test('should render upgrade button with correct attributes', () => {
|
|
163
|
+
renderComponent();
|
|
164
|
+
|
|
165
|
+
const upgradeButton = screen.getByTestId('upgrade-button');
|
|
166
|
+
expect(upgradeButton).toHaveClass('bcs-StaticVersionSidebar-upsell-button');
|
|
167
|
+
expect(upgradeButton).toHaveAttribute('data-resin-target', 'versioning_error_upgrade_cta');
|
|
168
|
+
expect(upgradeButton).toHaveAttribute('type', 'button');
|
|
169
|
+
expect(upgradeButton).toHaveTextContent('Upgrade');
|
|
170
|
+
});
|
|
171
|
+
});
|
|
@@ -1,23 +1,148 @@
|
|
|
1
1
|
import * as React from 'react';
|
|
2
|
-
import {
|
|
2
|
+
import { MemoryRouter, Route } from 'react-router-dom';
|
|
3
|
+
import { render, screen } from '../../../../test-utils/testing-library';
|
|
3
4
|
import VersionsList from '../VersionsList';
|
|
4
5
|
|
|
6
|
+
jest.mock('../VersionsItem', () => {
|
|
7
|
+
const MockVersionsItem = jest.fn(({ isCurrent, isSelected, version, fileId, versionCount, versionLimit }) => (
|
|
8
|
+
<div data-testid={`versions-item-${version.id}`}>
|
|
9
|
+
<span>Version {version.id}</span>
|
|
10
|
+
{isCurrent && <span>Current</span>}
|
|
11
|
+
{isSelected && <span>Selected</span>}
|
|
12
|
+
{fileId && <span>FileID: {fileId}</span>}
|
|
13
|
+
{versionCount && <span>VersionCount: {versionCount}</span>}
|
|
14
|
+
{versionLimit && <span>VersionLimit: {versionLimit}</span>}
|
|
15
|
+
</div>
|
|
16
|
+
));
|
|
17
|
+
return MockVersionsItem;
|
|
18
|
+
});
|
|
19
|
+
|
|
5
20
|
describe('elements/content-sidebar/versions/VersionsList', () => {
|
|
6
|
-
|
|
21
|
+
beforeEach(() => {
|
|
22
|
+
jest.clearAllMocks();
|
|
23
|
+
});
|
|
24
|
+
|
|
25
|
+
const renderComponent = (props = {}, routePath = '/activity/versions/12345') => {
|
|
26
|
+
if (props.routerDisabled) {
|
|
27
|
+
return render(<VersionsList {...props} />);
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
return render(
|
|
31
|
+
<MemoryRouter initialEntries={[routePath]}>
|
|
32
|
+
<Route path="/:sidebar(activity|details)/versions/:versionId?">
|
|
33
|
+
<VersionsList {...props} />
|
|
34
|
+
</Route>
|
|
35
|
+
</MemoryRouter>,
|
|
36
|
+
);
|
|
37
|
+
};
|
|
7
38
|
|
|
8
39
|
describe('render', () => {
|
|
9
|
-
test
|
|
10
|
-
versions
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
40
|
+
test('should render empty list when no versions provided', () => {
|
|
41
|
+
renderComponent({ versions: [] });
|
|
42
|
+
const list = screen.getByRole('list');
|
|
43
|
+
const listItems = screen.queryAllByRole('listitem');
|
|
44
|
+
|
|
45
|
+
expect(list).toBeInTheDocument();
|
|
46
|
+
expect(listItems).toHaveLength(0);
|
|
47
|
+
});
|
|
48
|
+
|
|
49
|
+
test('should render single version item', () => {
|
|
50
|
+
const versions = [{ id: '12345' }];
|
|
51
|
+
renderComponent({ versions });
|
|
52
|
+
const list = screen.getByRole('list');
|
|
53
|
+
const listItems = screen.getAllByRole('listitem');
|
|
54
|
+
|
|
55
|
+
expect(list).toBeInTheDocument();
|
|
56
|
+
expect(listItems).toHaveLength(1);
|
|
57
|
+
expect(screen.getByText('Version 12345')).toBeInTheDocument();
|
|
58
|
+
});
|
|
59
|
+
|
|
60
|
+
test('should render multiple version items', () => {
|
|
61
|
+
const versions = [{ id: '12345' }, { id: '45678' }];
|
|
62
|
+
renderComponent({ versions });
|
|
63
|
+
const list = screen.getByRole('list');
|
|
64
|
+
const listItems = screen.getAllByRole('listitem');
|
|
65
|
+
|
|
66
|
+
expect(list).toBeInTheDocument();
|
|
67
|
+
expect(listItems).toHaveLength(2);
|
|
68
|
+
expect(screen.getByText('Version 12345')).toBeInTheDocument();
|
|
69
|
+
expect(screen.getByText('Version 45678')).toBeInTheDocument();
|
|
70
|
+
});
|
|
71
|
+
|
|
72
|
+
test('should pass correct isCurrent prop based on currentId', () => {
|
|
73
|
+
const versions = [{ id: '12345' }, { id: '67890' }];
|
|
74
|
+
const currentId = '12345';
|
|
75
|
+
renderComponent({ versions, currentId, routerDisabled: true });
|
|
76
|
+
|
|
77
|
+
// Version 12345 should be marked as current
|
|
78
|
+
const version12345Container = screen.getByTestId('versions-item-12345');
|
|
79
|
+
expect(version12345Container).toBeInTheDocument();
|
|
80
|
+
expect(screen.getByText('Current')).toBeInTheDocument();
|
|
81
|
+
|
|
82
|
+
// Only one "Current" text should exist
|
|
83
|
+
expect(screen.getAllByText('Current')).toHaveLength(1);
|
|
84
|
+
});
|
|
85
|
+
|
|
86
|
+
test('should use router selection when routerDisabled is false', () => {
|
|
87
|
+
const versions = [{ id: '12345' }, { id: '67890' }];
|
|
88
|
+
renderComponent({ versions, routerDisabled: false }, '/activity/versions/12345');
|
|
89
|
+
|
|
90
|
+
// Version 12345 should be marked as selected based on route
|
|
91
|
+
const version12345Container = screen.getByTestId('versions-item-12345');
|
|
92
|
+
expect(version12345Container).toBeInTheDocument();
|
|
93
|
+
expect(version12345Container).toHaveTextContent('Selected');
|
|
94
|
+
expect(screen.getAllByText('Selected')).toHaveLength(1);
|
|
95
|
+
});
|
|
96
|
+
|
|
97
|
+
test('should use internalSidebarNavigation selection when routerDisabled is true', () => {
|
|
98
|
+
const versions = [{ id: '12345' }, { id: '67890' }];
|
|
99
|
+
const internalSidebarNavigation = { versionId: '67890', open: true };
|
|
100
|
+
|
|
101
|
+
renderComponent({
|
|
102
|
+
versions,
|
|
103
|
+
routerDisabled: true,
|
|
104
|
+
internalSidebarNavigation,
|
|
105
|
+
});
|
|
106
|
+
|
|
107
|
+
// Version 67890 should be marked as selected based on internal navigation
|
|
108
|
+
const version67890Container = screen.getByTestId('versions-item-67890');
|
|
109
|
+
expect(version67890Container).toBeInTheDocument();
|
|
110
|
+
expect(version67890Container).toHaveTextContent('Selected');
|
|
111
|
+
expect(screen.getAllByText('Selected')).toHaveLength(1);
|
|
112
|
+
});
|
|
113
|
+
|
|
114
|
+
test('should handle no selection when internalSidebarNavigation is not provided', () => {
|
|
115
|
+
const versions = [{ id: '12345' }, { id: '67890' }];
|
|
116
|
+
|
|
117
|
+
renderComponent({ versions, routerDisabled: true });
|
|
118
|
+
|
|
119
|
+
// No version should be selected
|
|
120
|
+
expect(screen.queryByText('Selected')).not.toBeInTheDocument();
|
|
121
|
+
});
|
|
122
|
+
|
|
123
|
+
test('should render items with correct version IDs', () => {
|
|
124
|
+
const versions = [{ id: 'version-abc' }, { id: 'version-xyz' }];
|
|
125
|
+
|
|
126
|
+
renderComponent({ versions, routerDisabled: true });
|
|
127
|
+
|
|
128
|
+
expect(screen.getByText('Version version-abc')).toBeInTheDocument();
|
|
129
|
+
expect(screen.getByText('Version version-xyz')).toBeInTheDocument();
|
|
130
|
+
});
|
|
131
|
+
|
|
132
|
+
test('should pass down other props to VersionsItem', () => {
|
|
133
|
+
const versions = [{ id: '12345' }];
|
|
134
|
+
const props = {
|
|
135
|
+
versions,
|
|
136
|
+
fileId: 'f_123',
|
|
137
|
+
versionCount: 10,
|
|
138
|
+
versionLimit: 100,
|
|
139
|
+
routerDisabled: true,
|
|
18
140
|
};
|
|
19
|
-
|
|
20
|
-
|
|
141
|
+
renderComponent(props);
|
|
142
|
+
|
|
143
|
+
expect(screen.getByText('FileID: f_123')).toBeInTheDocument();
|
|
144
|
+
expect(screen.getByText('VersionCount: 10')).toBeInTheDocument();
|
|
145
|
+
expect(screen.getByText('VersionLimit: 100')).toBeInTheDocument();
|
|
21
146
|
});
|
|
22
147
|
});
|
|
23
148
|
});
|
|
@@ -1,10 +1,35 @@
|
|
|
1
1
|
import * as React from 'react';
|
|
2
|
-
import {
|
|
3
|
-
import messages from '../messages';
|
|
4
|
-
import VersionsGroup from '../VersionsGroup';
|
|
2
|
+
import { render, screen } from '../../../../test-utils/testing-library';
|
|
5
3
|
import VersionsMenu from '../VersionsMenu';
|
|
6
4
|
|
|
7
|
-
jest.
|
|
5
|
+
jest.mock('../VersionsGroup', () => {
|
|
6
|
+
const MockVersionsGroup = jest.fn(
|
|
7
|
+
({
|
|
8
|
+
heading,
|
|
9
|
+
versions,
|
|
10
|
+
fileId,
|
|
11
|
+
versionCount,
|
|
12
|
+
versionLimit,
|
|
13
|
+
currentId,
|
|
14
|
+
routerDisabled,
|
|
15
|
+
internalSidebarNavigation,
|
|
16
|
+
}) => (
|
|
17
|
+
<div>
|
|
18
|
+
<h1>{heading}</h1>
|
|
19
|
+
<span>{versions.length} versions</span>
|
|
20
|
+
{fileId && <span data-testid="fileId">{fileId}</span>}
|
|
21
|
+
{versionCount !== undefined && <span data-testid="versionCount">{versionCount}</span>}
|
|
22
|
+
{versionLimit !== undefined && <span data-testid="versionLimit">{versionLimit}</span>}
|
|
23
|
+
{currentId && <span data-testid="currentId">{currentId}</span>}
|
|
24
|
+
{routerDisabled !== undefined && <span data-testid="routerDisabled">{String(routerDisabled)}</span>}
|
|
25
|
+
{internalSidebarNavigation && (
|
|
26
|
+
<span data-testid="internalSidebarNavigation">{JSON.stringify(internalSidebarNavigation)}</span>
|
|
27
|
+
)}
|
|
28
|
+
</div>
|
|
29
|
+
),
|
|
30
|
+
);
|
|
31
|
+
return MockVersionsGroup;
|
|
32
|
+
});
|
|
8
33
|
|
|
9
34
|
describe('elements/content-sidebar/versions/VersionsMenu', () => {
|
|
10
35
|
const defaultDate = '2019-06-20T20:00:00.000Z';
|
|
@@ -17,15 +42,11 @@ describe('elements/content-sidebar/versions/VersionsMenu', () => {
|
|
|
17
42
|
modified_by: { name: 'Test User', id: '098765' },
|
|
18
43
|
};
|
|
19
44
|
const getVersion = (overrides = {}) => ({ ...defaultVersion, ...overrides });
|
|
20
|
-
const
|
|
21
|
-
shallow(<VersionsMenu {...props} />, {
|
|
22
|
-
wrappingComponent: wrapperProps => <IntlProvider locale="en" messages={messages} {...wrapperProps} />,
|
|
23
|
-
})
|
|
24
|
-
.shallow() // <Memo .../>
|
|
25
|
-
.dive(); // <ul .../>
|
|
45
|
+
const renderComponent = (props = {}) => render(<VersionsMenu {...props} />);
|
|
26
46
|
const GlobalDate = Date;
|
|
27
47
|
|
|
28
48
|
beforeEach(() => {
|
|
49
|
+
jest.clearAllMocks();
|
|
29
50
|
global.Date = jest.fn(date => new GlobalDate(date || defaultDate));
|
|
30
51
|
global.Date.now = () => defaultDateMs;
|
|
31
52
|
});
|
|
@@ -48,20 +69,51 @@ describe('elements/content-sidebar/versions/VersionsMenu', () => {
|
|
|
48
69
|
getVersion({ created_at: '2019-02-01T20:00:00.000Z', id: '2' }),
|
|
49
70
|
getVersion({ created_at: '2018-05-01T20:00:00.000Z', id: '1' }),
|
|
50
71
|
];
|
|
51
|
-
|
|
52
|
-
const
|
|
72
|
+
renderComponent({ versions });
|
|
73
|
+
const headings = [
|
|
74
|
+
'Today',
|
|
75
|
+
'Yesterday',
|
|
76
|
+
'Tuesday',
|
|
77
|
+
'Monday',
|
|
78
|
+
'Last Week',
|
|
79
|
+
'This Month',
|
|
80
|
+
'May',
|
|
81
|
+
'February',
|
|
82
|
+
'2018',
|
|
83
|
+
];
|
|
84
|
+
const versionCounts = [2, 1, 1, 1, 1, 1, 1, 1, 1];
|
|
85
|
+
|
|
86
|
+
expect(screen.getAllByRole('heading', { level: 1 })).toHaveLength(9);
|
|
87
|
+
|
|
88
|
+
headings.forEach((heading, index) => {
|
|
89
|
+
const headingElement = screen.getByText(heading);
|
|
90
|
+
const groupContainer = headingElement.parentElement;
|
|
91
|
+
|
|
92
|
+
expect(groupContainer).toHaveTextContent(`${versionCounts[index]} versions`);
|
|
93
|
+
});
|
|
94
|
+
});
|
|
95
|
+
|
|
96
|
+
test('should pass down other props to VersionsGroup', () => {
|
|
97
|
+
const versions = [getVersion({ id: '10' })];
|
|
98
|
+
const props = {
|
|
99
|
+
versions,
|
|
100
|
+
fileId: 'f_123',
|
|
101
|
+
versionCount: 10,
|
|
102
|
+
versionLimit: 100,
|
|
103
|
+
currentId: '10',
|
|
104
|
+
routerDisabled: false,
|
|
105
|
+
internalSidebarNavigation: { open: false, sidebar: 'activity' },
|
|
106
|
+
};
|
|
107
|
+
renderComponent(props);
|
|
53
108
|
|
|
54
|
-
expect(
|
|
55
|
-
expect(
|
|
56
|
-
expect(
|
|
57
|
-
expect(
|
|
58
|
-
expect(
|
|
59
|
-
expect(
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
expect(groups.at(6).prop('heading')).toBe('May');
|
|
63
|
-
expect(groups.at(7).prop('heading')).toBe('February');
|
|
64
|
-
expect(groups.at(8).prop('heading')).toBe('2018');
|
|
109
|
+
expect(screen.getByTestId('fileId')).toHaveTextContent('f_123');
|
|
110
|
+
expect(screen.getByTestId('versionCount')).toHaveTextContent('10');
|
|
111
|
+
expect(screen.getByTestId('versionLimit')).toHaveTextContent('100');
|
|
112
|
+
expect(screen.getByTestId('currentId')).toHaveTextContent('10');
|
|
113
|
+
expect(screen.getByTestId('routerDisabled')).toHaveTextContent('false');
|
|
114
|
+
expect(screen.getByTestId('internalSidebarNavigation')).toHaveTextContent(
|
|
115
|
+
JSON.stringify(props.internalSidebarNavigation),
|
|
116
|
+
);
|
|
65
117
|
});
|
|
66
118
|
});
|
|
67
119
|
});
|