box-ui-elements 23.4.0-beta.17 → 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.
@@ -1,10 +1,35 @@
1
1
  import * as React from 'react';
2
- import { IntlProvider } from 'react-intl';
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.unmock('react-intl');
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 getWrapper = (props = {}) =>
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
- const wrapper = getWrapper({ versions });
52
- const groups = wrapper.find(VersionsGroup);
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(groups.length).toBe(9);
55
- expect(groups.at(0).prop('versions').length).toBe(2); // Multiple versions collapse into a group
56
- expect(groups.at(0).prop('heading')).toBe('Today');
57
- expect(groups.at(1).prop('heading')).toBe('Yesterday');
58
- expect(groups.at(2).prop('heading')).toBe('Tuesday');
59
- expect(groups.at(3).prop('heading')).toBe('Monday');
60
- expect(groups.at(4).prop('heading')).toBe('Last Week');
61
- expect(groups.at(5).prop('heading')).toBe('This Month');
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
  });
@@ -1,14 +0,0 @@
1
- export const ViewType = Object.freeze({
2
- BOXAI: 'boxai',
3
- SKILLS: 'skills',
4
- ACTIVITY: 'activity',
5
- DETAILS: 'details',
6
- METADATA: 'metadata',
7
- DOCGEN: 'docgen'
8
- });
9
- export const FeedEntryType = Object.freeze({
10
- ANNOTATIONS: 'annotations',
11
- COMMENTS: 'comments',
12
- TASKS: 'tasks'
13
- });
14
- //# sourceMappingURL=SidebarNavigation.flow.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"SidebarNavigation.flow.js","names":["ViewType","Object","freeze","BOXAI","SKILLS","ACTIVITY","DETAILS","METADATA","DOCGEN","FeedEntryType","ANNOTATIONS","COMMENTS","TASKS"],"sources":["../../../../src/elements/common/types/SidebarNavigation.flow.js"],"sourcesContent":["/* @flow */\n\nexport const ViewType = Object.freeze({\n BOXAI: 'boxai',\n SKILLS: 'skills',\n ACTIVITY: 'activity',\n DETAILS: 'details',\n METADATA: 'metadata',\n DOCGEN: 'docgen',\n});\n\nexport const FeedEntryType = Object.freeze({\n ANNOTATIONS: 'annotations',\n COMMENTS: 'comments',\n TASKS: 'tasks',\n});\n\nexport type ViewTypeValues = $Values<typeof ViewType>;\nexport type FeedEntryTypeValues = $Values<typeof FeedEntryType>;\n\ntype VersionSidebarView = {\n sidebar: 'activity' | 'details',\n versionId: string,\n};\n\nexport type ActivityAnnotationsSidebarView = {\n sidebar: 'activity',\n activeFeedEntryType: 'annotations',\n fileVersionId: string,\n activeFeedEntryId: string,\n};\ntype ActivityCommentsSidebarView = {\n sidebar: 'activity',\n activeFeedEntryType: 'comments' | 'tasks',\n activeFeedEntryId: string,\n};\n\nexport type SidebarNavigation =\n | {|\n sidebar: ViewTypeValues,\n |}\n | VersionSidebarView\n | ActivityCommentsSidebarView\n | ActivityAnnotationsSidebarView;\n\nexport type InternalSidebarNavigation = SidebarNavigation & {\n open: boolean,\n};\n\nexport type SidebarNavigationHandler = (sidebar: SidebarNavigation, replace?: boolean) => void;\n\nexport type InternalSidebarNavigationHandler = (sidebar: InternalSidebarNavigation, replace?: boolean) => void;\n"],"mappings":"AAEA,OAAO,MAAMA,QAAQ,GAAGC,MAAM,CAACC,MAAM,CAAC;EAClCC,KAAK,EAAE,OAAO;EACdC,MAAM,EAAE,QAAQ;EAChBC,QAAQ,EAAE,UAAU;EACpBC,OAAO,EAAE,SAAS;EAClBC,QAAQ,EAAE,UAAU;EACpBC,MAAM,EAAE;AACZ,CAAC,CAAC;AAEF,OAAO,MAAMC,aAAa,GAAGR,MAAM,CAACC,MAAM,CAAC;EACvCQ,WAAW,EAAE,aAAa;EAC1BC,QAAQ,EAAE,UAAU;EACpBC,KAAK,EAAE;AACX,CAAC,CAAC","ignoreList":[]}
@@ -1,45 +0,0 @@
1
- // Jest Snapshot v1, https://goo.gl/fbAQLP
2
-
3
- exports[`elements/content-sidebar/versions/VersionsList render should match its snapshot 1`] = `
4
- <ul
5
- className="bcs-VersionsList"
6
- />
7
- `;
8
-
9
- exports[`elements/content-sidebar/versions/VersionsList render should match its snapshot 2`] = `
10
- <ul
11
- className="bcs-VersionsList"
12
- >
13
- <li
14
- className="bcs-VersionsList-item"
15
- key="12345"
16
- >
17
- <Route
18
- render={[Function]}
19
- />
20
- </li>
21
- </ul>
22
- `;
23
-
24
- exports[`elements/content-sidebar/versions/VersionsList render should match its snapshot 3`] = `
25
- <ul
26
- className="bcs-VersionsList"
27
- >
28
- <li
29
- className="bcs-VersionsList-item"
30
- key="12345"
31
- >
32
- <Route
33
- render={[Function]}
34
- />
35
- </li>
36
- <li
37
- className="bcs-VersionsList-item"
38
- key="45678"
39
- >
40
- <Route
41
- render={[Function]}
42
- />
43
- </li>
44
- </ul>
45
- `;