box-ui-elements 23.4.0-beta.16 → 23.4.0-beta.17

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.
Files changed (25) hide show
  1. package/dist/explorer.js +1 -1
  2. package/dist/preview.js +1 -1
  3. package/dist/sidebar.js +1 -1
  4. package/es/elements/common/nav-button/BackButton.js +5 -8
  5. package/es/elements/common/nav-button/BackButton.js.flow +8 -18
  6. package/es/elements/common/nav-button/BackButton.js.map +1 -1
  7. package/es/elements/content-sidebar/versions/StaticVersionSidebar.js +6 -3
  8. package/es/elements/content-sidebar/versions/StaticVersionSidebar.js.flow +47 -42
  9. package/es/elements/content-sidebar/versions/StaticVersionSidebar.js.map +1 -1
  10. package/es/elements/content-sidebar/versions/VersionsSidebar.js +6 -3
  11. package/es/elements/content-sidebar/versions/VersionsSidebar.js.flow +48 -39
  12. package/es/elements/content-sidebar/versions/VersionsSidebar.js.map +1 -1
  13. package/es/src/test-utils/testing-library.d.ts +2 -1
  14. package/es/test-utils/testing-library.js +4 -1
  15. package/es/test-utils/testing-library.js.map +1 -1
  16. package/package.json +1 -1
  17. package/src/elements/common/nav-button/BackButton.js +8 -18
  18. package/src/elements/common/nav-button/__tests__/BackButton.test.js +36 -27
  19. package/src/elements/content-sidebar/versions/StaticVersionSidebar.js +47 -42
  20. package/src/elements/content-sidebar/versions/VersionsSidebar.js +48 -39
  21. package/src/elements/content-sidebar/versions/__tests__/StaticVersionSidebar.test.js +171 -0
  22. package/src/elements/content-sidebar/versions/__tests__/VersionsSidebar.test.js +147 -20
  23. package/src/test-utils/testing-library.tsx +4 -1
  24. package/src/elements/common/nav-button/__tests__/__snapshots__/BackButton.test.js.snap +0 -64
  25. package/src/elements/content-sidebar/versions/__tests__/__snapshots__/VersionsSidebar.test.js.snap +0 -92
@@ -1,43 +1,52 @@
1
1
  import * as React from 'react';
2
- import { MemoryRouter, Router } from 'react-router-dom';
3
- import { mount } from 'enzyme';
2
+ import { render, screen, userEvent } from '../../../../test-utils/testing-library';
4
3
  import { BackButton } from '..';
5
4
 
6
5
  describe('elements/common/nav-button/BackButton', () => {
7
- const getWrapper = (props = {}) =>
8
- mount(
9
- <MemoryRouter initialEntries={['/start', '/test']}>
10
- <BackButton {...props} />
11
- </MemoryRouter>,
12
- );
13
- const getHistory = wrapper => wrapper.find(Router).prop('history');
14
-
15
- test('should match its snapshot', () => {
16
- const wrapper = getWrapper();
17
- const button = wrapper.find(BackButton).first();
18
-
19
- expect(button).toMatchSnapshot();
6
+ const mockOnClick = jest.fn();
7
+
8
+ beforeEach(() => {
9
+ mockOnClick.mockClear();
20
10
  });
21
11
 
22
- test('should call history back on click if no path is defined', () => {
23
- const wrapper = getWrapper();
24
- const history = getHistory(wrapper);
12
+ test('should render back button with navigation icon and accessible text', () => {
13
+ render(<BackButton onClick={mockOnClick} />);
25
14
 
26
- history.goBack = jest.fn();
15
+ const button = screen.getByRole('button');
16
+ expect(button).toBeInTheDocument();
17
+ expect(button).toHaveClass('bdl-BackButton');
27
18
 
28
- wrapper.simulate('click');
19
+ expect(screen.getByText('Back')).toBeInTheDocument();
29
20
 
30
- expect(history.goBack).toHaveBeenCalled();
21
+ const icon = button.querySelector('svg');
22
+ expect(icon).toBeInTheDocument();
23
+ expect(icon).toHaveClass('icon-navigate-left');
31
24
  });
32
25
 
33
- test('should call history.push on click if a path is defined', () => {
34
- const wrapper = getWrapper({ to: '/new' });
35
- const history = getHistory(wrapper);
26
+ test('should call onClick handler when clicked', async () => {
27
+ const user = userEvent();
28
+
29
+ render(<BackButton onClick={mockOnClick} />);
36
30
 
37
- history.push = jest.fn();
31
+ const button = screen.getByRole('button');
32
+ await user.click(button);
33
+
34
+ expect(mockOnClick).toHaveBeenCalledTimes(1);
35
+ });
36
+
37
+ test('should pass through additional props', () => {
38
+ render(<BackButton onClick={mockOnClick} data-testid="test-back-button" data-resin-target="back" />);
39
+
40
+ const button = screen.getByTestId('test-back-button');
41
+ expect(button).toBeInTheDocument();
42
+ expect(button).toHaveAttribute('data-resin-target', 'back');
43
+ });
38
44
 
39
- wrapper.simulate('click');
45
+ test('should apply custom className alongside default class', () => {
46
+ render(<BackButton onClick={mockOnClick} className="custom-class" />);
40
47
 
41
- expect(history.push).toHaveBeenCalledWith('/new');
48
+ const button = screen.getByRole('button');
49
+ expect(button).toHaveClass('bdl-BackButton');
50
+ expect(button).toHaveClass('custom-class');
42
51
  });
43
52
  });
@@ -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
 
10
11
  import BoxDrive140 from '../../../illustration/BoxDrive140';
11
12
 
@@ -45,51 +46,55 @@ const StaticVersionsSidebar = ({ isLoading, onUpgradeClick, parentName }: Props)
45
46
  });
46
47
 
47
48
  return (
48
- <div
49
- className="bcs-StaticVersionSidebar"
50
- role="tabpanel"
51
- data-resin-component="preview"
52
- data-resin-feature="versions"
53
- >
54
- <div className="bcs-StaticVersionSidebar-header">
55
- <h3 className="bcs-StaticVersionSidebar-title">
56
- <>
57
- <BackButton data-resin-target="back" to={`/${parentName}`} />
58
- <FormattedMessage {...messages.versionsTitle} />
59
- </>
60
- </h3>
61
- </div>
62
-
63
- <div className="bcs-StaticVersionSidebar-content-wrapper">
64
- <LoadingIndicatorWrapper
65
- className="bcs-StaticVersionSidebar-content"
66
- crawlerPosition="top"
67
- isLoading={isLoading}
49
+ <Route>
50
+ {({ history }) => (
51
+ <div
52
+ className="bcs-StaticVersionSidebar"
53
+ role="tabpanel"
54
+ data-resin-component="preview"
55
+ data-resin-feature="versions"
68
56
  >
69
- <VersionsMenu versions={versions} fileId="1" versionCount={3} versionLimit={3} />
70
- </LoadingIndicatorWrapper>
71
- </div>
57
+ <div className="bcs-StaticVersionSidebar-header">
58
+ <h3 className="bcs-StaticVersionSidebar-title">
59
+ <>
60
+ <BackButton data-resin-target="back" onClick={() => history.push(`/${parentName}`)} />
61
+ <FormattedMessage {...messages.versionsTitle} />
62
+ </>
63
+ </h3>
64
+ </div>
65
+
66
+ <div className="bcs-StaticVersionSidebar-content-wrapper">
67
+ <LoadingIndicatorWrapper
68
+ className="bcs-StaticVersionSidebar-content"
69
+ crawlerPosition="top"
70
+ isLoading={isLoading}
71
+ >
72
+ <VersionsMenu versions={versions} fileId="1" versionCount={3} versionLimit={3} />
73
+ </LoadingIndicatorWrapper>
74
+ </div>
72
75
 
73
- <div className="bcs-StaticVersionSidebar-upsell-wrapper">
74
- <div className="bcs-StaticVersionSidebar-upsell">
75
- <BoxDrive140 className="bcs-StaticVersionSidebar-upsell-icon" />
76
- <p className="bcs-StaticVersionSidebar-upsell-header">
77
- <FormattedMessage {...messages.versionUpgradeLink} />
78
- </p>
79
- <p>
80
- <FormattedMessage {...messages.versionUpsell} />
81
- </p>
82
- <PrimaryButton
83
- className="bcs-StaticVersionSidebar-upsell-button"
84
- data-resin-target="versioning_error_upgrade_cta"
85
- onClick={onUpgradeClick}
86
- type="button"
87
- >
88
- <FormattedMessage {...messages.upgradeButton} />
89
- </PrimaryButton>
76
+ <div className="bcs-StaticVersionSidebar-upsell-wrapper">
77
+ <div className="bcs-StaticVersionSidebar-upsell">
78
+ <BoxDrive140 className="bcs-StaticVersionSidebar-upsell-icon" />
79
+ <p className="bcs-StaticVersionSidebar-upsell-header">
80
+ <FormattedMessage {...messages.versionUpgradeLink} />
81
+ </p>
82
+ <p>
83
+ <FormattedMessage {...messages.versionUpsell} />
84
+ </p>
85
+ <PrimaryButton
86
+ className="bcs-StaticVersionSidebar-upsell-button"
87
+ data-resin-target="versioning_error_upgrade_cta"
88
+ onClick={onUpgradeClick}
89
+ type="button"
90
+ >
91
+ <FormattedMessage {...messages.upgradeButton} />
92
+ </PrimaryButton>
93
+ </div>
94
+ </div>
90
95
  </div>
91
- </div>
92
- </div>
96
+ )}
97
+ </Route>
93
98
  );
94
99
  };
95
100
 
@@ -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
- <SidebarContent
40
- className="bcs-Versions"
41
- data-resin-component="preview"
42
- data-resin-feature="versions"
43
- title={
44
- <>
45
- <BackButton data-resin-target="back" to={`/${parentName}`} />
46
- <FormattedMessage {...messages.versionsTitle} />
47
- </>
48
- }
49
- >
50
- <LoadingIndicatorWrapper className="bcs-Versions-content" crawlerPosition="top" isLoading={isLoading}>
51
- {showError && (
52
- <InlineError title={<FormattedMessage {...messages.versionServerError} />}>
53
- <FormattedMessage {...error} />
54
- </InlineError>
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
- {showEmpty && (
58
- <div className="bcs-Versions-empty">
59
- <FormattedMessage {...messages.versionsEmpty} />
60
- </div>
61
- )}
64
+ {showEmpty && (
65
+ <div className="bcs-Versions-empty">
66
+ <FormattedMessage {...messages.versionsEmpty} />
67
+ </div>
68
+ )}
62
69
 
63
- {showVersions && (
64
- <div className="bcs-Versions-menu" data-testid="bcs-Versions-menu">
65
- <VersionsMenu versions={versions} {...rest} />
66
- </div>
67
- )}
68
- {showLimit && (
69
- <div className="bcs-Versions-maxEntries" data-testid="max-versions">
70
- <FormattedMessage
71
- {...messages.versionMaxEntries}
72
- values={{
73
- maxVersions: MAX_VERSIONS,
74
- }}
75
- />
76
- </div>
77
- )}
78
- </LoadingIndicatorWrapper>
79
- </SidebarContent>
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,38 +1,165 @@
1
1
  import * as React from 'react';
2
- import { shallow } from 'enzyme/build';
3
- import InlineError from '../../../../components/inline-error';
2
+ import { MemoryRouter, Route } from 'react-router-dom';
3
+ import { render, screen, userEvent } from '../../../../test-utils/testing-library';
4
4
  import messages from '../messages';
5
- import VersionsMenu from '../VersionsMenu';
6
5
  import VersionsSidebar from '../VersionsSidebar';
7
6
 
8
7
  jest.mock('../../../common/nav-button', () => ({
9
- BackButton: () => <button type="button">Back</button>,
8
+ BackButton: ({ onClick, 'data-resin-target': dataResinTarget }) => (
9
+ <button type="button" onClick={onClick} data-resin-target={dataResinTarget} data-testid="back-button">
10
+ Back
11
+ </button>
12
+ ),
10
13
  }));
11
14
 
15
+ jest.mock('../VersionsMenu', () => ({ versions, fileId, versionCount, versionLimit }) => (
16
+ <div data-testid="versions-menu">
17
+ Versions: {versions.length}, FileId: {fileId}, Count: {versionCount}, Limit: {versionLimit}
18
+ </div>
19
+ ));
20
+
21
+ jest.mock('../../../../components/loading-indicator', () => ({
22
+ LoadingIndicatorWrapper: ({ children, isLoading, className, crawlerPosition }) => (
23
+ <div
24
+ className={className}
25
+ data-testid="loading-wrapper"
26
+ data-loading={isLoading}
27
+ data-crawler-position={crawlerPosition}
28
+ >
29
+ {children}
30
+ </div>
31
+ ),
32
+ }));
33
+
34
+ jest.mock('../../../../components/inline-error', () => ({ title, children }) => (
35
+ <div data-testid="inline-error">
36
+ <div data-testid="error-title">{title}</div>
37
+ <div data-testid="error-message">{children}</div>
38
+ </div>
39
+ ));
40
+
12
41
  describe('elements/content-sidebar/versions/VersionsSidebar', () => {
13
- const getWrapper = (props = {}) => shallow(<VersionsSidebar parentName="activity" {...props} />);
42
+ const defaultProps = {
43
+ fileId: '123',
44
+ isLoading: false,
45
+ parentName: 'activity',
46
+ versionCount: 1,
47
+ versionLimit: 10,
48
+ versions: [{ id: '12345' }],
49
+ };
14
50
 
15
- describe('render', () => {
16
- test('should show the versions list if no error prop is provided', () => {
17
- const wrapper = getWrapper({ versions: [{ id: '12345' }] });
51
+ const renderComponent = (props = {}) => {
52
+ return render(
53
+ <MemoryRouter initialEntries={['/versions']}>
54
+ <VersionsSidebar {...defaultProps} {...props} />
55
+ </MemoryRouter>,
56
+ );
57
+ };
18
58
 
19
- expect(wrapper.exists(InlineError)).toBe(false);
20
- expect(wrapper.exists(VersionsMenu)).toBe(true);
21
- expect(wrapper).toMatchSnapshot();
22
- });
59
+ test('should show the versions list if no error prop is provided', () => {
60
+ renderComponent({ versions: [{ id: '12345' }] });
23
61
 
24
- test('should show an inline error if the prop is provided', () => {
25
- const wrapper = getWrapper({ error: messages.versionFetchError, versions: [] });
62
+ expect(screen.queryByTestId('inline-error')).not.toBeInTheDocument();
63
+ expect(screen.getByTestId('versions-menu')).toBeInTheDocument();
64
+ expect(screen.getByText('Version History')).toBeInTheDocument();
65
+ expect(screen.getByTestId('back-button')).toBeInTheDocument();
66
+ });
26
67
 
27
- expect(wrapper.exists(InlineError)).toBe(true);
28
- expect(wrapper).toMatchSnapshot();
68
+ test('should show an inline error if the prop is provided', () => {
69
+ renderComponent({
70
+ error: messages.versionFetchError,
71
+ versions: [],
29
72
  });
30
73
 
31
- test('should show max versions text if max versions provided', () => {
32
- const versions = Array.from({ length: 1000 }).map((item, index) => ({ id: index }));
33
- const wrapper = getWrapper({ versions });
74
+ expect(screen.getByTestId('inline-error')).toBeInTheDocument();
75
+ expect(screen.getByTestId('error-title')).toBeInTheDocument();
76
+ expect(screen.getByTestId('error-message')).toBeInTheDocument();
77
+ expect(screen.queryByTestId('versions-menu')).not.toBeInTheDocument();
78
+ expect(screen.queryByTestId('max-versions')).not.toBeInTheDocument();
79
+ expect(screen.getByText('Version History')).toBeInTheDocument();
80
+ expect(screen.getByTestId('back-button')).toBeInTheDocument();
81
+ });
82
+
83
+ test('should show max versions text if max versions provided', () => {
84
+ const versions = Array.from({ length: 1000 }, (_, index) => ({ id: index }));
85
+ renderComponent({ versions });
86
+
87
+ expect(screen.getByTestId('max-versions')).toBeInTheDocument();
88
+ expect(screen.queryByTestId('inline-error')).not.toBeInTheDocument();
89
+ expect(screen.getByText('Version History')).toBeInTheDocument();
90
+ expect(screen.getByTestId('back-button')).toBeInTheDocument();
91
+ });
92
+
93
+ test('should not show max versions text if few versions provided', () => {
94
+ renderComponent({ versions: [{ id: '1' }, { id: '2' }] });
34
95
 
35
- expect(wrapper.exists('[data-testid="max-versions"]')).toBe(true);
96
+ expect(screen.queryByTestId('max-versions')).not.toBeInTheDocument();
97
+ expect(screen.queryByTestId('inline-error')).not.toBeInTheDocument();
98
+ });
99
+
100
+ test('should show empty state when no versions and not loading', () => {
101
+ renderComponent({
102
+ versions: [],
103
+ isLoading: false,
36
104
  });
105
+
106
+ expect(screen.getByText('No prior versions are available for this file.')).toBeInTheDocument();
107
+ expect(screen.queryByTestId('versions-menu')).not.toBeInTheDocument();
108
+ expect(screen.queryByTestId('max-versions')).not.toBeInTheDocument();
109
+ expect(screen.queryByTestId('inline-error')).not.toBeInTheDocument();
110
+ expect(screen.getByText('Version History')).toBeInTheDocument();
111
+ expect(screen.getByTestId('back-button')).toBeInTheDocument();
112
+ });
113
+
114
+ test('should pass loading state to LoadingIndicatorWrapper', () => {
115
+ renderComponent({ isLoading: true });
116
+
117
+ const loadingWrapper = screen.getByTestId('loading-wrapper');
118
+ expect(loadingWrapper).toHaveAttribute('data-loading', 'true');
119
+ expect(loadingWrapper).toHaveAttribute('data-crawler-position', 'top');
120
+ expect(loadingWrapper).toHaveClass('bcs-Versions-content');
121
+ expect(screen.queryByTestId('inline-error')).not.toBeInTheDocument();
122
+ expect(screen.getByText('Version History')).toBeInTheDocument();
123
+ expect(screen.getByTestId('back-button')).toBeInTheDocument();
124
+ });
125
+
126
+ test('should pass correct props to VersionsMenu', () => {
127
+ renderComponent();
128
+
129
+ const versionsMenu = screen.getByTestId('versions-menu');
130
+ expect(versionsMenu).toHaveTextContent('Versions: 1, FileId: 123, Count: 1, Limit: 10');
131
+ expect(screen.queryByTestId('inline-error')).not.toBeInTheDocument();
132
+ expect(screen.getByText('Version History')).toBeInTheDocument();
133
+ expect(screen.getByTestId('back-button')).toBeInTheDocument();
134
+ });
135
+
136
+ test('should navigate to parent name when back button is clicked', async () => {
137
+ let currentLocation;
138
+
139
+ const TestWrapper = ({ children }) => (
140
+ <MemoryRouter initialEntries={['/versions']}>
141
+ <Route
142
+ path="*"
143
+ render={({ location }) => {
144
+ currentLocation = location;
145
+ return children;
146
+ }}
147
+ />
148
+ </MemoryRouter>
149
+ );
150
+
151
+ render(
152
+ <TestWrapper>
153
+ <VersionsSidebar {...defaultProps} parentName="activity" />
154
+ </TestWrapper>,
155
+ );
156
+
157
+ expect(currentLocation.pathname).toBe('/versions');
158
+
159
+ const backButton = screen.getByTestId('back-button');
160
+ const user = userEvent();
161
+ await user.click(backButton);
162
+
163
+ expect(currentLocation.pathname).toBe('/activity');
37
164
  });
38
165
  });