Skip to content

Commit 38e4c56

Browse files
author
Artyom Podymov
committed
#RI-2062 - update styles and add unit tests
1 parent cf5a82a commit 38e4c56

File tree

14 files changed

+171
-24
lines changed

14 files changed

+171
-24
lines changed

redisinsight/ui/src/constants/mocks/mock-enablement-area.ts

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,20 @@ export const MOCK_ENABLEMENT_AREA_ITEMS: Record<string, IEnablementAreaItem> = {
1414
path: 'static/workbench/quick-guides/document-capabilities.html',
1515
},
1616
},
17-
'document': {
17+
'working-with-json': {
1818
type: EnablementAreaComponent.InternalLink,
19-
id: 'document',
20-
label: 'Document',
19+
id: 'working-with-json',
20+
label: 'Working with JSON',
2121
args: {
22-
path: 'static/workbench/quick-guides/document.html',
22+
path: 'static/workbench/quick-guides/working-with-json.html',
23+
},
24+
},
25+
'working-with-hash': {
26+
type: EnablementAreaComponent.InternalLink,
27+
id: 'working-with-hash',
28+
label: 'Working with HASH',
29+
args: {
30+
path: 'static/workbench/quick-guides/working-with-hash.html',
2331
},
2432
}
2533
}
@@ -32,6 +40,14 @@ export const MOCK_ENABLEMENT_AREA_ITEMS: Record<string, IEnablementAreaItem> = {
3240
path: 'static/workbench/quick-guides/document-capabilities.html'
3341
},
3442
},
43+
'second-internal-page': {
44+
type: EnablementAreaComponent.InternalLink,
45+
id: 'second-internal-page',
46+
label: 'Second Internal Page',
47+
args: {
48+
path: 'static/workbench/quick-guides/document-capabilities.html'
49+
},
50+
},
3551
'manual': {
3652
type: EnablementAreaComponent.CodeButton,
3753
id: 'manual',

redisinsight/ui/src/pages/workbench/components/enablament-area/EnablementArea/components/CodeButton/CodeButton.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ const CodeButton = ({ onClick, label, isLoading, ...rest }: Props) => (
1717
onClick={onClick}
1818
fullWidth
1919
color="secondary"
20-
contentProps={{ className: styles.button }}
20+
className={styles.button}
2121
textProps={{ className: styles.buttonText }}
2222
data-testid={`preselect-${label}`}
2323
{...rest}

redisinsight/ui/src/pages/workbench/components/enablament-area/EnablementArea/components/CodeButton/styles.module.scss

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,15 @@
1+
@import '@elastic/eui/src/global_styling/index';
2+
13
.button {
24
justify-content: space-between;
5+
&[class*='euiButton--secondary']:not([class*='isDisabled']) {
6+
&:hover,
7+
&:focus,
8+
&:focus-within {
9+
background-color: var(--euiColorSecondary) !important;
10+
border-color: var(--euiColorSecondary) !important;
11+
}
12+
}
313
&:not(:hover) {
414
span {
515
color: var(--euiTextSubduedColor);

redisinsight/ui/src/pages/workbench/components/enablament-area/EnablementArea/components/Group/styles.scss

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@
3636
line-height: 24px;
3737
max-height: 30px;
3838
&:hover {
39-
background-color: var(--hoverInListColorLight);
39+
background-color: var(--hoverInListColorDarken);
4040
color: var(--euiTextColor)
4141
}
4242
}

redisinsight/ui/src/pages/workbench/components/enablament-area/EnablementArea/components/InternalPage/InternalPage.tsx

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@ import {
33
EuiFlyoutHeader,
44
EuiText,
55
EuiButtonEmpty,
6-
EuiLoadingContent, EuiHorizontalRule,
6+
EuiLoadingContent,
7+
EuiHorizontalRule,
78
} from '@elastic/eui'
89
import JsxParser from 'react-jsx-parser'
910
import cx from 'classnames'
@@ -13,7 +14,8 @@ import {
1314
LazyCodeButton,
1415
InternalLink,
1516
Image,
16-
EmptyPrompt, Pagination
17+
EmptyPrompt,
18+
Pagination
1719
} from 'uiSrc/pages/workbench/components/enablament-area/EnablementArea/components'
1820
import { IEnablementAreaItem } from 'uiSrc/slices/interfaces'
1921

redisinsight/ui/src/pages/workbench/components/enablament-area/EnablementArea/components/InternalPage/styles.module.scss

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@
4444
justify-content: flex-start;
4545
}
4646
&:hover {
47-
background-color: var(--hoverInListColorLight);
47+
background-color: var(--hoverInListColorDarken);
4848
color: var(--euiTextColor) !important;
4949
text-decoration: none !important;
5050
}
Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
import React from 'react'
2+
import { fireEvent, render, screen, waitFor } from 'uiSrc/utils/test-utils'
3+
import { MOCK_ENABLEMENT_AREA_ITEMS } from 'uiSrc/constants'
4+
import { defaultValue, EnablementAreaProvider } from 'uiSrc/pages/workbench/contexts/enablementAreaContext'
5+
import Pagination from './Pagination'
6+
7+
const paginationItems = Object.values(MOCK_ENABLEMENT_AREA_ITEMS['quick-guides']?.children || {})
8+
9+
describe('Pagination', () => {
10+
it('should render', () => {
11+
const component = render(<Pagination items={paginationItems} />)
12+
const { queryByTestId } = component
13+
14+
expect(component).toBeTruthy()
15+
expect(queryByTestId('enablement-area__prev-page-btn')).not.toBeInTheDocument()
16+
expect(queryByTestId('enablement-area__next-page-btn')).toBeInTheDocument()
17+
})
18+
it('should correctly open popover', () => {
19+
const { queryByTestId } = render(
20+
<Pagination items={paginationItems} activePageId={paginationItems[0].id} />
21+
)
22+
fireEvent.click(screen.getByTestId('enablement-area__pagination-popover-btn'))
23+
const popover = queryByTestId('enablement-area__pagination-popover')
24+
25+
expect(popover).toBeInTheDocument()
26+
expect(popover?.querySelectorAll('.pagesItem').length).toEqual(paginationItems.length)
27+
expect(popover?.querySelector('.pagesItemActive')).toHaveTextContent(paginationItems[0].label)
28+
})
29+
it('should correctly open next page', () => {
30+
const openPage = jest.fn()
31+
const pageIndex = 0
32+
33+
render(
34+
<EnablementAreaProvider value={{ ...defaultValue, openPage }}>
35+
<Pagination items={paginationItems} activePageId={paginationItems[pageIndex].id} />
36+
</EnablementAreaProvider>
37+
)
38+
fireEvent.click(screen.getByTestId('enablement-area__next-page-btn'))
39+
40+
expect(openPage).toBeCalledWith({ path: paginationItems[pageIndex + 1]?.args?.path })
41+
})
42+
it('should correctly open previous page', () => {
43+
const openPage = jest.fn()
44+
const pageIndex = 1
45+
46+
render(
47+
<EnablementAreaProvider value={{ ...defaultValue, openPage }}>
48+
<Pagination items={paginationItems} activePageId={paginationItems[pageIndex].id} />
49+
</EnablementAreaProvider>
50+
)
51+
fireEvent.click(screen.getByTestId('enablement-area__prev-page-btn'))
52+
53+
expect(openPage).toBeCalledWith({ path: paginationItems[pageIndex - 1]?.args?.path })
54+
})
55+
it('should correctly open by using pagination popover', async () => {
56+
const openPage = jest.fn()
57+
const { queryByTestId } = render(
58+
<EnablementAreaProvider value={{ ...defaultValue, openPage }}>
59+
<Pagination items={paginationItems} activePageId={paginationItems[0].id} />
60+
</EnablementAreaProvider>
61+
)
62+
63+
fireEvent.click(screen.getByTestId('enablement-area__pagination-popover-btn'))
64+
const popover = queryByTestId('enablement-area__pagination-popover')
65+
await waitFor(() => {
66+
popover?.querySelectorAll('.pagesItem').forEach(async (el) => {
67+
fireEvent.click(el)
68+
})
69+
})
70+
71+
expect(openPage).toBeCalledTimes(paginationItems.length - 1) // -1 because active item should not be clickable
72+
expect(openPage)
73+
.lastCalledWith({ path: paginationItems[paginationItems.length - 1]?.args?.path })
74+
})
75+
})

redisinsight/ui/src/pages/workbench/components/enablament-area/EnablementArea/components/Pagination/Pagination.tsx

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,18 +13,20 @@ import styles from './styles.module.scss'
1313

1414
export interface Props {
1515
items: IEnablementAreaItem[];
16-
activePageId: string;
16+
activePageId?: string;
1717
compressed?: boolean;
1818
}
1919

2020
const Pagination = ({ items = [], activePageId, compressed }: Props) => {
2121
const [isPopoverOpen, setPopover] = useState(false)
22-
const [activePage, setActivePage] = useState(-1)
22+
const [activePage, setActivePage] = useState(0)
2323
const { openPage } = useContext(EnablementAreaContext)
2424

2525
useEffect(() => {
26-
const index = items.findIndex((item) => item.id === activePageId)
27-
setActivePage(index)
26+
if (activePageId) {
27+
const index = items.findIndex((item) => item.id === activePageId)
28+
setActivePage(index)
29+
}
2830
}, [activePageId])
2931

3032
const togglePopover = () => {
@@ -57,7 +59,12 @@ const Pagination = ({ items = [], activePageId, compressed }: Props) => {
5759
<EuiPopover
5860
id="enablementAreaPagesMenu"
5961
button={(
60-
<button className={styles.popoverButton} type="button" onClick={togglePopover}>
62+
<button
63+
data-testid="enablement-area__pagination-popover-btn"
64+
className={styles.popoverButton}
65+
type="button"
66+
onClick={togglePopover}
67+
>
6168
{`${activePage + 1} of ${items.length}`}
6269
</button>
6370
)}
@@ -67,6 +74,7 @@ const Pagination = ({ items = [], activePageId, compressed }: Props) => {
6774
panelPaddingSize="none"
6875
>
6976
<EuiContextMenuPanel
77+
data-testid="enablement-area__pagination-popover"
7078
style={{ minWidth: !compressed ? '280px' : 'none' }}
7179
className={styles.panel}
7280
size="s"
@@ -82,6 +90,7 @@ const Pagination = ({ items = [], activePageId, compressed }: Props) => {
8290
<EuiButton
8391
aria-label="Previous page"
8492
fill
93+
data-testid="enablement-area__prev-page-btn"
8594
color="secondary"
8695
iconType="arrowLeft"
8796
iconSide="left"
@@ -101,6 +110,7 @@ const Pagination = ({ items = [], activePageId, compressed }: Props) => {
101110
<EuiButton
102111
aria-label="Next page"
103112
fill
113+
data-testid="enablement-area__next-page-btn"
104114
color="secondary"
105115
iconType="arrowRight"
106116
iconSide="right"

redisinsight/ui/src/pages/workbench/components/enablament-area/EnablementArea/components/Pagination/styles.module.scss

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,13 @@
1414

1515
.paginationCompressed {
1616
padding: 8px 6px;
17-
& > div:first-of-type,& > div:last-of-type {
17+
& > div:first-of-type, & > div:last-of-type {
1818
min-width: 70px;
1919
}
2020
}
2121

2222
.panel {
23-
padding-bottom: 1px;
23+
padding: 1px 0;
2424
button:first-of-type {
2525
border-radius: 3px 3px 0 0;
2626
}
@@ -31,8 +31,15 @@
3131

3232
.popover {
3333
border: 1px solid var(--euiColorPrimary) !important;
34-
& > div:before {
35-
border-top-color: var(--euiColorPrimary) !important;
34+
[class~=euiPopover__panelArrow] {
35+
&:before {
36+
border-top-color: var(--euiColorPrimary) !important;
37+
}
38+
}
39+
[class~=euiPopover__panelArrow--bottom] {
40+
&:before {
41+
border-bottom-color: var(--euiColorPrimary) !important;
42+
}
3643
}
3744
}
3845

redisinsight/ui/src/pages/workbench/components/enablament-area/EnablementArea/utils/getFileInfo.spec.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,18 @@ const getPagesInsideGroupTests = [
5555
input: [MOCK_ENABLEMENT_AREA_ITEMS, '/static/workbench/quick-guides'],
5656
expected: Object.values(MOCK_ENABLEMENT_AREA_ITEMS['quick-guides'].children || {})
5757
},
58+
{
59+
input: [MOCK_ENABLEMENT_AREA_ITEMS, '/static/workbench/'],
60+
expected: [MOCK_ENABLEMENT_AREA_ITEMS['internal-page'], MOCK_ENABLEMENT_AREA_ITEMS['second-internal-page']]
61+
},
62+
{
63+
input: [MOCK_ENABLEMENT_AREA_ITEMS, 'https://domen.com/workbench/enablement-area/'],
64+
expected: []
65+
},
66+
{
67+
input: [],
68+
expected: []
69+
},
5870
]
5971

6072
describe('getPagesInsideGroup', () => {

0 commit comments

Comments
 (0)