@looker/api-explorer 0.9.33-alpha.1522 → 0.9.33

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 (39) hide show
  1. package/CHANGELOG.md +26 -1
  2. package/dist/bundle.js +1 -1
  3. package/dist/bundle.js.LICENSE.txt +0 -9
  4. package/dist/bundle.js.map +1 -1
  5. package/e2e/diffScene.spec.ts +260 -0
  6. package/e2e/e2e.spec.ts +60 -29
  7. package/e2e/helpers.ts +9 -1
  8. package/jest-puppeteer.config.js +10 -0
  9. package/jest.config.js +25 -23
  10. package/lib/components/DocSource/DocSource.js +1 -1
  11. package/lib/components/DocSource/DocSource.js.map +1 -1
  12. package/lib/components/SideNav/SideNavMethods.js +7 -2
  13. package/lib/components/SideNav/SideNavMethods.js.map +1 -1
  14. package/lib/components/SideNav/SideNavTypes.js +6 -1
  15. package/lib/components/SideNav/SideNavTypes.js.map +1 -1
  16. package/lib/esm/components/DocSource/DocSource.js +2 -2
  17. package/lib/esm/components/DocSource/DocSource.js.map +1 -1
  18. package/lib/esm/components/SideNav/SideNavMethods.js +7 -2
  19. package/lib/esm/components/SideNav/SideNavMethods.js.map +1 -1
  20. package/lib/esm/components/SideNav/SideNavTypes.js +6 -1
  21. package/lib/esm/components/SideNav/SideNavTypes.js.map +1 -1
  22. package/lib/esm/scenes/DiffScene/DiffScene.js +1 -0
  23. package/lib/esm/scenes/DiffScene/DiffScene.js.map +1 -1
  24. package/lib/esm/scenes/DiffScene/DocDiff/DocDiff.js +2 -2
  25. package/lib/esm/scenes/DiffScene/DocDiff/DocDiff.js.map +1 -1
  26. package/lib/scenes/DiffScene/DiffScene.js +1 -0
  27. package/lib/scenes/DiffScene/DiffScene.js.map +1 -1
  28. package/lib/scenes/DiffScene/DocDiff/DocDiff.js +2 -2
  29. package/lib/scenes/DiffScene/DocDiff/DocDiff.js.map +1 -1
  30. package/package.json +12 -12
  31. package/src/components/DocSource/DocSource.spec.tsx +3 -3
  32. package/src/components/DocSource/DocSource.tsx +3 -2
  33. package/src/components/SideNav/SideNavMethods.spec.tsx +49 -3
  34. package/src/components/SideNav/SideNavMethods.tsx +6 -2
  35. package/src/components/SideNav/SideNavTypes.spec.tsx +46 -10
  36. package/src/components/SideNav/SideNavTypes.tsx +5 -1
  37. package/src/scenes/DiffScene/DiffScene.tsx +1 -0
  38. package/src/scenes/DiffScene/DocDiff/DocDiff.spec.tsx +112 -0
  39. package/src/scenes/DiffScene/DocDiff/DocDiff.tsx +2 -6
@@ -35,30 +35,76 @@ import {
35
35
  } from '../../test-utils'
36
36
  import { SideNavMethods } from './SideNavMethods'
37
37
 
38
+ const mockHistoryPush = jest.fn()
39
+ jest.mock('react-router-dom', () => {
40
+ const ReactRouterDOM = jest.requireActual('react-router-dom')
41
+ return {
42
+ ...ReactRouterDOM,
43
+ useHistory: () => ({
44
+ push: mockHistoryPush,
45
+ }),
46
+ }
47
+ })
48
+
38
49
  describe('SideNavMethods', () => {
39
50
  const tag = 'Dashboard'
40
51
  const methods = api.tags[tag]
52
+ const specKey = '3.1'
41
53
 
42
54
  test('it renders provided methods', () => {
43
55
  renderWithRouterAndReduxProvider(
44
- <SideNavMethods methods={methods} tag={tag} specKey={'3.1'} />
56
+ <SideNavMethods methods={methods} tag={tag} specKey={specKey} />
45
57
  )
46
58
  userEvent.click(screen.getByText(tag))
47
59
  const sideNavItems = screen.getAllByRole('link')
48
60
  expect(sideNavItems).toHaveLength(Object.keys(methods).length)
49
61
  expect(sideNavItems[0]).toHaveAttribute(
50
62
  'href',
51
- `/3.1/methods/${tag}/${Object.values(methods)[0].name}`
63
+ `/${specKey}/methods/${tag}/${Object.values(methods)[0].name}`
64
+ )
65
+ })
66
+
67
+ test('tag expands and displays methods after clicked', () => {
68
+ renderWithRouterAndReduxProvider(
69
+ <SideNavMethods methods={methods} tag={tag} specKey={specKey} />
70
+ )
71
+ const firstMethod = Object.values(methods)[0].schema.summary
72
+ expect(screen.queryByText(firstMethod)).not.toBeInTheDocument()
73
+ userEvent.click(screen.getByText(tag))
74
+ expect(mockHistoryPush).toHaveBeenCalledWith(`/${specKey}/methods/${tag}`)
75
+ expect(screen.getByRole('link', { name: firstMethod })).toBeInTheDocument()
76
+ expect(screen.getAllByRole('link')).toHaveLength(
77
+ Object.values(methods).length
52
78
  )
53
79
  })
54
80
 
81
+ test('expanded tag closes when clicked', () => {
82
+ renderWithRouterAndReduxProvider(
83
+ <SideNavMethods
84
+ methods={methods}
85
+ tag={tag}
86
+ specKey={specKey}
87
+ defaultOpen={true}
88
+ />
89
+ )
90
+ const firstMethod = Object.values(methods)[0].schema.summary
91
+ expect(screen.getByRole('link', { name: firstMethod })).toBeInTheDocument()
92
+ expect(screen.getAllByRole('link')).toHaveLength(
93
+ Object.values(methods).length
94
+ )
95
+ userEvent.click(screen.getByText(tag))
96
+ expect(mockHistoryPush).toHaveBeenCalledWith(`/${specKey}/methods`)
97
+ expect(screen.queryByText(firstMethod)).not.toBeInTheDocument()
98
+ expect(screen.queryByRole('link')).not.toBeInTheDocument()
99
+ })
100
+
55
101
  test('it highlights text matching search pattern in both tag and methods', () => {
56
102
  const store = createTestStore({ settings: { searchPattern: 'dash' } })
57
103
  renderWithRouterAndReduxProvider(
58
104
  <SideNavMethods
59
105
  methods={pick(methods, 'create_dashboard')}
60
106
  tag={tag}
61
- specKey={'3.1'}
107
+ specKey={specKey}
62
108
  />,
63
109
  undefined,
64
110
  store
@@ -55,7 +55,11 @@ export const SideNavMethods = styled(
55
55
  const handleOpen = () => {
56
56
  const _isOpen = !isOpen
57
57
  setIsOpen(_isOpen)
58
- if (_isOpen) history.push(`/${specKey}/methods/${tag}`)
58
+ if (_isOpen) {
59
+ history.push(`/${specKey}/methods/${tag}`)
60
+ } else {
61
+ history.push(`/${specKey}/methods`)
62
+ }
59
63
  }
60
64
 
61
65
  useEffect(() => {
@@ -63,7 +67,7 @@ export const SideNavMethods = styled(
63
67
  ? defaultOpen || match.params.methodTag === tag
64
68
  : defaultOpen
65
69
  setIsOpen(status)
66
- }, [defaultOpen, match, tag])
70
+ }, [defaultOpen])
67
71
 
68
72
  /* TODO: Fix highlighting. It is applied but it is somehow being overridden */
69
73
  return (
@@ -26,6 +26,7 @@
26
26
  import React from 'react'
27
27
  import { screen } from '@testing-library/react'
28
28
 
29
+ import userEvent from '@testing-library/user-event'
29
30
  import { api } from '../../test-data'
30
31
  import {
31
32
  createTestStore,
@@ -33,30 +34,65 @@ import {
33
34
  } from '../../test-utils'
34
35
  import { SideNavTypes } from './SideNavTypes'
35
36
 
37
+ const mockHistoryPush = jest.fn()
38
+ jest.mock('react-router-dom', () => {
39
+ const ReactRouterDOM = jest.requireActual('react-router-dom')
40
+ return {
41
+ ...ReactRouterDOM,
42
+ useHistory: () => ({
43
+ push: mockHistoryPush,
44
+ }),
45
+ }
46
+ })
47
+
36
48
  describe('SideNavTypes', () => {
49
+ const tag = 'Dashboard'
50
+ const specKey = '3.1'
51
+ const typeTags = Object.keys(api.typeTags[tag])
52
+
37
53
  test('it renders provided types', () => {
54
+ renderWithRouterAndReduxProvider(
55
+ <SideNavTypes specKey={specKey} types={{ ...api.types }} tag={tag} />
56
+ )
57
+ expect(screen.getByRole('heading', { level: 4 })).toHaveTextContent(tag)
58
+ })
59
+
60
+ test('tag expands and displays types after clicked', () => {
61
+ renderWithRouterAndReduxProvider(
62
+ <SideNavTypes types={{ ...api.types }} tag={tag} specKey={specKey} />
63
+ )
64
+ expect(screen.queryByText(typeTags[0])).not.toBeInTheDocument()
65
+ userEvent.click(screen.getByText(tag))
66
+ expect(mockHistoryPush).toHaveBeenCalledWith(`/${specKey}/types/${tag}`)
67
+ expect(screen.getByRole('link', { name: typeTags[0] })).toBeInTheDocument()
68
+ })
69
+
70
+ test('expanded tag closes when clicked', () => {
38
71
  renderWithRouterAndReduxProvider(
39
72
  <SideNavTypes
40
- specKey={'3.1'}
41
- types={{
42
- Dashboard: api.types.Dashboard,
43
- }}
44
- tag="Dashboard"
73
+ types={{ ...api.types }}
74
+ tag={tag}
75
+ specKey={specKey}
76
+ defaultOpen={true}
45
77
  />
46
78
  )
47
- const h4 = screen.getByRole('heading', { level: 4 })
48
- expect(h4).toHaveTextContent('Dashboard')
79
+ expect(screen.getByRole('link', { name: typeTags[0] })).toBeInTheDocument()
80
+ userEvent.click(screen.getAllByText(tag)[0])
81
+ expect(mockHistoryPush).toHaveBeenCalledWith(`/${specKey}/types`)
82
+ expect(
83
+ screen.queryByRole('link', { name: typeTags[0] })
84
+ ).not.toBeInTheDocument()
49
85
  })
50
86
 
51
87
  test('it highlights text matching search pattern', () => {
52
88
  const store = createTestStore({ settings: { searchPattern: 'dash' } })
53
89
  renderWithRouterAndReduxProvider(
54
90
  <SideNavTypes
55
- specKey={'3.1'}
91
+ specKey={specKey}
56
92
  types={{
57
- Dashboard: api.types.Dashboard,
93
+ ...api.types,
58
94
  }}
59
- tag="Dashboard"
95
+ tag={tag}
60
96
  />,
61
97
  undefined,
62
98
  store
@@ -55,7 +55,11 @@ export const SideNavTypes = styled(
55
55
  const handleOpen = () => {
56
56
  const _isOpen = !isOpen
57
57
  setIsOpen(_isOpen)
58
- if (_isOpen) history.push(`/${specKey}/types/${tag}`)
58
+ if (_isOpen) {
59
+ history.push(`/${specKey}/types/${tag}`)
60
+ } else {
61
+ history.push(`/${specKey}/types`)
62
+ }
59
63
  }
60
64
 
61
65
  useEffect(() => {
@@ -170,6 +170,7 @@ export const DiffScene: FC<DiffSceneProps> = ({ specs, toggleNavigation }) => {
170
170
  />
171
171
  </FlexItem>
172
172
  <IconButton
173
+ className="switch-button"
173
174
  label="switch"
174
175
  size="small"
175
176
  disabled={!leftKey || !rightKey}
@@ -0,0 +1,112 @@
1
+ /*
2
+
3
+ MIT License
4
+
5
+ Copyright (c) 2022 Looker Data Sciences, Inc.
6
+
7
+ Permission is hereby granted, free of charge, to any person obtaining a copy
8
+ of this software and associated documentation files (the "Software"), to deal
9
+ in the Software without restriction, including without limitation the rights
10
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11
+ copies of the Software, and to permit persons to whom the Software is
12
+ furnished to do so, subject to the following conditions:
13
+
14
+ The above copyright notice and this permission notice shall be included in all
15
+ copies or substantial portions of the Software.
16
+
17
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
23
+ SOFTWARE.
24
+
25
+ */
26
+ import React from 'react'
27
+ import { screen, waitFor } from '@testing-library/react'
28
+ import userEvent from '@testing-library/user-event'
29
+
30
+ import { getLoadedSpecs } from '../../../test-data'
31
+ import { diffSpecs, standardDiffToggles } from '../diffUtils'
32
+ import { renderWithReduxProvider } from '../../../test-utils'
33
+ import { DocDiff } from './DocDiff'
34
+
35
+ describe('DocDiff', () => {
36
+ const specs = getLoadedSpecs()
37
+ const leftKey = specs['3.1'].key
38
+ const rightKey = specs['4.0'].key
39
+ const leftApi = specs['3.1'].api!
40
+ const rightApi = specs['4.0'].api!
41
+
42
+ it('renders', () => {
43
+ const delta = diffSpecs(leftApi, rightApi, standardDiffToggles)
44
+ renderWithReduxProvider(
45
+ <DocDiff
46
+ leftKey={leftKey}
47
+ leftSpec={leftApi}
48
+ rightKey={rightKey}
49
+ rightSpec={rightApi}
50
+ delta={delta}
51
+ pageSize={1}
52
+ />
53
+ )
54
+ expect(screen.getByRole('heading', { level: 2 })).toHaveTextContent(
55
+ `${delta.length} differences between ${leftKey} and ${rightKey}`
56
+ )
57
+ expect(
58
+ screen.getByRole('button', { name: 'Previous page of results' })
59
+ ).toBeInTheDocument()
60
+ expect(
61
+ screen.getByRole('button', { name: 'Next page of results' })
62
+ ).toBeInTheDocument()
63
+ })
64
+ it('renders when there is no delta', () => {
65
+ renderWithReduxProvider(
66
+ <DocDiff
67
+ leftKey={leftKey}
68
+ leftSpec={leftApi}
69
+ rightKey={rightKey}
70
+ rightSpec={rightApi}
71
+ delta={[]}
72
+ />
73
+ )
74
+ expect(screen.getByText('No differences found')).toBeInTheDocument()
75
+ })
76
+
77
+ it('paginates', async () => {
78
+ const delta = diffSpecs(leftApi, rightApi, standardDiffToggles)
79
+ renderWithReduxProvider(
80
+ <DocDiff
81
+ leftKey={leftKey}
82
+ leftSpec={leftApi}
83
+ rightKey={rightKey}
84
+ rightSpec={rightApi}
85
+ delta={delta}
86
+ pageSize={1}
87
+ />
88
+ )
89
+
90
+ // page 1
91
+ const row1 = delta[0]
92
+ expect(screen.getByText(row1.name)).toBeInTheDocument()
93
+ expect(screen.getByText(row1.id)).toBeInTheDocument()
94
+ expect(
95
+ screen.getByText(rightApi.methods[row1.name].summary)
96
+ ).toBeInTheDocument()
97
+
98
+ // go to page 2
99
+ userEvent.click(
100
+ screen.getByRole('button', { name: 'Next page of results' })
101
+ )
102
+
103
+ await waitFor(() => {
104
+ const row2 = delta[1]
105
+ expect(screen.getByText(row2.name)).toBeInTheDocument()
106
+ expect(screen.getByText(row2.id)).toBeInTheDocument()
107
+ expect(
108
+ screen.getByText(rightApi.methods[row2.name].summary)
109
+ ).toBeInTheDocument()
110
+ })
111
+ })
112
+ })
@@ -64,11 +64,7 @@ export const DocDiff: FC<DocDiffProps> = ({
64
64
  if (delta.length === 0) return <Text>{'No differences found'}</Text>
65
65
 
66
66
  const pageCount = Math.round((delta.length - 1) / pageSize)
67
- // The +1 is to skip the header row
68
- const pageItemData = delta.slice(
69
- (page - 1) * pageSize + 1,
70
- page * pageSize + 1
71
- )
67
+ const pageItemData = delta.slice((page - 1) * pageSize, page * pageSize + 1)
72
68
 
73
69
  return (
74
70
  <>
@@ -82,7 +78,7 @@ export const DocDiff: FC<DocDiffProps> = ({
82
78
  <SpaceVertical mt="large" gap="xxsmall">
83
79
  {pageItemData.map((item, index) => (
84
80
  <DiffItem
85
- key={index}
81
+ key={`page-${page} item-${index}`}
86
82
  item={item}
87
83
  leftKey={leftKey}
88
84
  leftSpec={leftSpec}