-
Notifications
You must be signed in to change notification settings - Fork 687
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test: use RTL in the version selector tests
- Loading branch information
Showing
7 changed files
with
115 additions
and
253 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
import * as React from 'react'; | ||
|
||
import { render, screen } from '@testing-library/react'; | ||
import userEvent from '@testing-library/user-event'; | ||
|
||
import { VersionChooser } from '../../src/renderer/components/commands-version-chooser'; | ||
import { AppState } from '../../src/renderer/state'; | ||
import { mockVersion1, prepareAppState } from '../test-utils/versions'; | ||
|
||
describe('VersionSelect component', () => { | ||
let appState: AppState; | ||
|
||
beforeEach(() => { | ||
appState = prepareAppState(); | ||
|
||
// the version selector is disabled when bisecting | ||
appState.Bisector = undefined; | ||
}); | ||
|
||
it('selects a new version', async () => { | ||
const { getByRole } = render(<VersionChooser appState={appState} />); | ||
|
||
const btnOpenVersionSelector = getByRole('button'); | ||
|
||
await userEvent.click(btnOpenVersionSelector); | ||
|
||
const versionButton = screen.getByText(mockVersion1.version); | ||
|
||
await userEvent.click(versionButton); | ||
|
||
expect(appState.setVersion).toHaveBeenCalledWith(mockVersion1.version); | ||
}); | ||
}); |
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,44 @@ | ||
import { | ||
ElectronReleaseChannel, | ||
InstallState, | ||
VersionSource, | ||
} from '../../src/interfaces'; | ||
import { VersionsMock } from '../../tests/mocks/electron-versions'; | ||
import { StateMock } from '../../tests/mocks/state'; | ||
|
||
const { missing } = InstallState; | ||
const { remote } = VersionSource; | ||
|
||
export const mockVersion1 = { | ||
source: remote, | ||
state: missing, | ||
version: '1.0.0', | ||
}; | ||
|
||
export const mockVersion2 = { | ||
source: remote, | ||
state: missing, | ||
version: '3.0.0-unsupported', | ||
}; | ||
|
||
/** | ||
* Initializes the app state with our mock versions. | ||
*/ | ||
export function prepareAppState() { | ||
const { state: appState } = window.ElectronFiddle.app; | ||
|
||
const { mockVersions } = new VersionsMock(); | ||
|
||
(appState as unknown as StateMock).initVersions('2.0.2', { | ||
...mockVersions, | ||
'1.0.0': { ...mockVersion1 }, | ||
'3.0.0-unsupported': { ...mockVersion2 }, | ||
}); | ||
|
||
appState.channelsToShow = [ | ||
ElectronReleaseChannel.stable, | ||
ElectronReleaseChannel.beta, | ||
]; | ||
|
||
return appState; | ||
} |
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
45 changes: 0 additions & 45 deletions
45
tests/renderer/components/__snapshots__/commands-version-chooser-spec.tsx.snap
This file was deleted.
Oops, something went wrong.
86 changes: 0 additions & 86 deletions
86
tests/renderer/components/__snapshots__/version-select-spec.tsx.snap
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.