|
1 | 1 | import React from 'react'
|
2 |
| -import { render, screen } from 'uiSrc/utils/test-utils' |
| 2 | +import { act, fireEvent, render, screen } from 'uiSrc/utils/test-utils' |
3 | 3 |
|
4 | 4 | import { ADD_KEY_TYPE_OPTIONS } from 'uiSrc/pages/browser/components/add-key/constants/key-type-options'
|
| 5 | +import { connectedInstanceSelector } from 'uiSrc/slices/instances/instances' |
| 6 | +import { RedisDefaultModules } from 'uiSrc/slices/interfaces' |
5 | 7 | import AddKey from './AddKey'
|
6 | 8 |
|
7 | 9 | const handleAddKeyPanelMock = () => {}
|
8 | 10 | const handleCloseKeyMock = () => {}
|
9 | 11 |
|
| 12 | +jest.mock('uiSrc/slices/instances/instances', () => ({ |
| 13 | + ...jest.requireActual('uiSrc/slices/instances/instances'), |
| 14 | + connectedInstanceSelector: jest.fn().mockReturnValue({ |
| 15 | + id: '1', |
| 16 | + modules: [] |
| 17 | + }), |
| 18 | +})) |
| 19 | + |
10 | 20 | describe('AddKey', () => {
|
11 | 21 | it('should render', () => {
|
12 | 22 | expect(render(<AddKey
|
13 |
| - handleAddKeyPanel={handleAddKeyPanelMock} |
14 |
| - handleCloseKey={handleCloseKeyMock} |
| 23 | + onAddKeyPanel={handleAddKeyPanelMock} |
| 24 | + onClosePanel={handleCloseKeyMock} |
15 | 25 | />)).toBeTruthy()
|
16 | 26 | })
|
17 | 27 |
|
18 | 28 | it('should render type select label', () => {
|
19 | 29 | render(<AddKey
|
20 |
| - handleAddKeyPanel={handleAddKeyPanelMock} |
21 |
| - handleCloseKey={handleCloseKeyMock} |
| 30 | + onAddKeyPanel={handleAddKeyPanelMock} |
| 31 | + onClosePanel={handleCloseKeyMock} |
22 | 32 | />)
|
23 | 33 |
|
24 | 34 | expect(screen.getByText(/Key Type\*/i)).toBeInTheDocument()
|
25 | 35 | })
|
26 | 36 |
|
27 | 37 | it('should have key type select with predefined first value from options', () => {
|
28 | 38 | render(<AddKey
|
29 |
| - handleAddKeyPanel={handleAddKeyPanelMock} |
30 |
| - handleCloseKey={handleCloseKeyMock} |
| 39 | + onAddKeyPanel={handleAddKeyPanelMock} |
| 40 | + onClosePanel={handleCloseKeyMock} |
31 | 41 | />)
|
32 | 42 |
|
33 | 43 | expect(screen.getByDisplayValue(ADD_KEY_TYPE_OPTIONS[0].value)).toBeInTheDocument()
|
34 | 44 | })
|
| 45 | + |
| 46 | + it('should show text if db not contains ReJSON module', async () => { |
| 47 | + render(<AddKey |
| 48 | + onAddKeyPanel={handleAddKeyPanelMock} |
| 49 | + onClosePanel={handleCloseKeyMock} |
| 50 | + />) |
| 51 | + |
| 52 | + fireEvent.click(screen.getByTestId('select-key-type')) |
| 53 | + await act(() => { |
| 54 | + fireEvent.click( |
| 55 | + screen.queryByText('JSON') || document |
| 56 | + ) |
| 57 | + }) |
| 58 | + |
| 59 | + expect(screen.getByTestId('json-not-loaded-text')).toBeInTheDocument() |
| 60 | + }) |
| 61 | + |
| 62 | + it('should not show text if db contains ReJSON module', async () => { |
| 63 | + (connectedInstanceSelector as jest.Mock).mockImplementation(() => ({ |
| 64 | + modules: [{ name: RedisDefaultModules.FT }, { name: RedisDefaultModules.ReJSON }] |
| 65 | + })) |
| 66 | + |
| 67 | + render(<AddKey |
| 68 | + onAddKeyPanel={handleAddKeyPanelMock} |
| 69 | + onClosePanel={handleCloseKeyMock} |
| 70 | + />) |
| 71 | + |
| 72 | + fireEvent.click(screen.getByTestId('select-key-type')) |
| 73 | + await act(() => { |
| 74 | + fireEvent.click( |
| 75 | + screen.queryByText('JSON') || document |
| 76 | + ) |
| 77 | + }) |
| 78 | + |
| 79 | + expect(screen.queryByTestId('json-not-loaded-text')).not.toBeInTheDocument() |
| 80 | + }) |
35 | 81 | })
|
0 commit comments