-
Notifications
You must be signed in to change notification settings - Fork 35
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Also added more helpers for tests: - added new isSelected helper that returns true if an element has primary class - configures mobx without readonly checks in jest env so that we can spy on actions - now always create the "/virtual" memory volume when running jest tests
- Loading branch information
1 parent
7d07d9a
commit 8d1f465
Showing
11 changed files
with
139 additions
and
27 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,94 @@ | ||
/** | ||
* @jest-environment jsdom | ||
*/ | ||
import React from 'react' | ||
import { screen, render, setup, t, isSelected } from 'rtl' | ||
|
||
import { Nav } from '../Nav' | ||
import { AppState } from '$src/state/appState' | ||
import { Classes } from '@blueprintjs/core' | ||
|
||
describe('Nav', () => { | ||
const options = { | ||
providerProps: { | ||
appState: new AppState(), | ||
}, | ||
} | ||
|
||
beforeEach(async () => { | ||
const appState = new AppState() | ||
options.providerProps.appState = appState | ||
await options.providerProps.appState.loadSettingsAndPrepareViews() | ||
|
||
jest.spyOn(appState, 'showDownloadsTab') | ||
jest.spyOn(appState, 'showExplorerTab') | ||
jest.spyOn(appState, 'toggleSplitViewMode') | ||
|
||
jest.clearAllMocks() | ||
}) | ||
|
||
it('should display nav', () => { | ||
const { container } = render(<Nav />, options) | ||
|
||
expect(screen.getByText(t('APP_MENUS.ABOUT_TITLE'))).toBeInTheDocument() | ||
|
||
const explorerButton = screen.getByRole('button', { name: t('NAV.EXPLORER') }) | ||
expect(explorerButton).toBeInTheDocument() | ||
expect(isSelected(explorerButton)).toBe(true) | ||
|
||
const downloadsButton = screen.getByRole('button', { name: t('NAV.TRANSFERS') }) | ||
expect(downloadsButton).toBeInTheDocument() | ||
expect(isSelected(downloadsButton)).toBe(false) | ||
|
||
const splitViewButton = container.querySelector('[data-icon="panel-stats"]') | ||
expect(splitViewButton).toBeInTheDocument() | ||
expect(splitViewButton.classList.contains(Classes.INTENT_PRIMARY)).toBe( | ||
options.providerProps.appState.winStates[0].splitView, | ||
) | ||
}) | ||
|
||
it('should render badge', () => { | ||
// simulate 10 running transfers so that the badge is displayed | ||
jest.spyOn(options.providerProps.appState.transferListState, 'getRunningTransfers').mockReturnValue(10) | ||
render(<Nav />, options) | ||
|
||
expect(screen.getByText('10')).toBeInTheDocument() | ||
}) | ||
|
||
describe('actions', () => { | ||
it('should open hamburger menu when clicking on hamburger', async () => { | ||
const { user } = setup(<Nav />, options) | ||
|
||
await user.click(screen.getByRole('button', { name: t('NAV.TRANSFERS') })) | ||
|
||
expect(options.providerProps.appState.showDownloadsTab).toHaveBeenCalled() | ||
}) | ||
|
||
it('should show downloads when clicking on downloads button and show explorer when clicking on explorer button', async () => { | ||
const { user } = setup(<Nav />, options) | ||
|
||
const transfersButton = screen.getByRole('button', { name: t('NAV.TRANSFERS') }) | ||
const explorerButton = screen.getByRole('button', { name: t('NAV.EXPLORER') }) | ||
|
||
await user.click(transfersButton) | ||
|
||
expect(options.providerProps.appState.showDownloadsTab).toHaveBeenCalled() | ||
expect(isSelected(explorerButton)).toBe(false) | ||
expect(isSelected(transfersButton)).toBe(true) | ||
|
||
await user.click(explorerButton) | ||
expect(options.providerProps.appState.showExplorerTab).toHaveBeenCalled() | ||
expect(isSelected(explorerButton)).toBe(true) | ||
expect(isSelected(transfersButton)).toBe(false) | ||
}) | ||
|
||
it('should toggle splitview when clicking on splitview button', async () => { | ||
const { user, container } = setup(<Nav />, options) | ||
|
||
const splitViewButton = container.querySelector('[data-icon="panel-stats"]') | ||
await user.click(splitViewButton) | ||
|
||
expect(options.providerProps.appState.toggleSplitViewMode).toHaveBeenCalled() | ||
}) | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters