|
| 1 | +import { cloneDeep } from 'lodash' |
1 | 2 | import React from 'react'
|
2 |
| -import { render } from 'uiSrc/utils/test-utils' |
| 3 | +import { BuildType } from 'uiSrc/constants/env' |
| 4 | +import { EXTERNAL_LINKS } from 'uiSrc/constants/links' |
| 5 | +import { cleanup, mockedStore, render, screen, fireEvent } from 'uiSrc/utils/test-utils' |
3 | 6 |
|
4 | 7 | import NavigationMenu from './NavigationMenu'
|
5 | 8 |
|
| 9 | +let store: typeof mockedStore |
| 10 | +beforeEach(() => { |
| 11 | + cleanup() |
| 12 | + store = cloneDeep(mockedStore) |
| 13 | + store.clearActions() |
| 14 | +}) |
| 15 | + |
6 | 16 | describe('NavigationMenu', () => {
|
7 |
| - it('should render', () => { |
8 |
| - expect(render(<NavigationMenu />)).toBeTruthy() |
| 17 | + describe('without connectedInstance', () => { |
| 18 | + it('should render', () => { |
| 19 | + expect(render(<NavigationMenu buildType={BuildType.DockerOnPremise} />)).toBeTruthy() |
| 20 | + }) |
| 21 | + |
| 22 | + it('shouldn\'t render private routes', () => { |
| 23 | + render(<NavigationMenu buildType={BuildType.DockerOnPremise} />) |
| 24 | + |
| 25 | + expect(screen.queryByTestId('browser-page-btn"')).not.toBeInTheDocument() |
| 26 | + expect(screen.queryByTestId('workbench-page-btn')).not.toBeInTheDocument() |
| 27 | + }) |
| 28 | + |
| 29 | + it('should render help menu', () => { |
| 30 | + render(<NavigationMenu buildType={BuildType.RedisStack} />) |
| 31 | + |
| 32 | + expect(screen.getByTestId('help-menu-button')).toBeTruthy() |
| 33 | + }) |
| 34 | + |
| 35 | + it('should render help menu items with proper links', () => { |
| 36 | + render(<NavigationMenu buildType={BuildType.RedisStack} />) |
| 37 | + |
| 38 | + fireEvent.click(screen.getByTestId('help-menu-button')) |
| 39 | + |
| 40 | + const submitBugBtn = screen.getByTestId('submit-bug-btn') |
| 41 | + expect(submitBugBtn).toBeInTheDocument() |
| 42 | + expect(submitBugBtn?.getAttribute('href')).toEqual(EXTERNAL_LINKS.githubIssues) |
| 43 | + |
| 44 | + expect(screen.getByTestId('shortcuts-btn')).toBeInTheDocument() |
| 45 | + |
| 46 | + const releaseNotesBtn = screen.getByTestId('release-notes-btn') |
| 47 | + expect(releaseNotesBtn).toBeInTheDocument() |
| 48 | + expect(releaseNotesBtn?.getAttribute('href')).toEqual(EXTERNAL_LINKS.releaseNotes) |
| 49 | + }) |
| 50 | + }) |
| 51 | + |
| 52 | + describe('with connectedInstance', () => { |
| 53 | + beforeAll(() => { |
| 54 | + jest.mock('uiSrc/slices/instances', () => ({ |
| 55 | + ...jest.requireActual('uiSrc/slices/instances'), |
| 56 | + connectedInstanceSelector: jest.fn().mockReturnValue({ |
| 57 | + id: '123', |
| 58 | + connectionType: 'STANDALONE', |
| 59 | + db: 0, |
| 60 | + }) |
| 61 | + })) |
| 62 | + }) |
| 63 | + |
| 64 | + it('should render', () => { |
| 65 | + expect(render(<NavigationMenu buildType={BuildType.DockerOnPremise} />)).toBeTruthy() |
| 66 | + }) |
| 67 | + |
| 68 | + it('should render private routes with instanceId', () => { |
| 69 | + render(<NavigationMenu buildType={BuildType.DockerOnPremise} />) |
| 70 | + |
| 71 | + expect(screen.findByTestId('browser-page-btn')).toBeTruthy() |
| 72 | + expect(screen.findByTestId('workbench-page-btn')).toBeTruthy() |
| 73 | + }) |
| 74 | + |
| 75 | + it('should render public routes', () => { |
| 76 | + render(<NavigationMenu buildType={BuildType.DockerOnPremise} />) |
| 77 | + |
| 78 | + expect(screen.getByTestId('settings-page-btn')).toBeTruthy() |
| 79 | + }) |
| 80 | + |
| 81 | + it('should render github btn with proper link', () => { |
| 82 | + const { container } = render(<NavigationMenu buildType={BuildType.Electron} />) |
| 83 | + |
| 84 | + const githubBtn = container.querySelector('[data-test-subj="github-repo-btn"]') |
| 85 | + expect(githubBtn).toBeTruthy() |
| 86 | + expect(githubBtn?.getAttribute('href')).toEqual(EXTERNAL_LINKS.githubRepo) |
| 87 | + }) |
9 | 88 | })
|
10 | 89 | })
|
0 commit comments