Skip to content

Commit

Permalink
test: migrate editors-non-ideal-state test to RTL
Browse files Browse the repository at this point in the history
  • Loading branch information
erikian committed Aug 5, 2024
1 parent 44e1f03 commit 5c8cb85
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 24 deletions.
24 changes: 17 additions & 7 deletions rtl-spec/components/editors-non-ideal-state.spec.tsx
Original file line number Diff line number Diff line change
@@ -1,23 +1,33 @@
import { mount } from 'enzyme';
import React from 'react';

import { renderNonIdealState } from '../../src/renderer/components/editors-non-ideal-state';
import { render } from '@testing-library/react';
import userEvent from '@testing-library/user-event';

import { RenderNonIdealState } from '../../src/renderer/components/editors-non-ideal-state';
import { EditorMosaic } from '../../src/renderer/editor-mosaic';

describe('renderNonIdealState()', () => {
describe('RenderNonIdealState component', () => {
let editorMosaic: EditorMosaic;

beforeEach(() => {
({ editorMosaic } = window.app.state);
});

it('renders a non-ideal state', () => {
expect(renderNonIdealState({} as EditorMosaic)).toMatchSnapshot();
const { getByText } = render(
<RenderNonIdealState editorMosaic={{} as EditorMosaic} />,
);

expect(getByText('Reset editors')).toBeInTheDocument();
});

it('handles a click', () => {
it('handles a click', async () => {
const resetLayoutSpy = jest.spyOn(editorMosaic, 'resetLayout');
const wrapper = mount(renderNonIdealState(editorMosaic));
wrapper.find('button').simulate('click');
const { getByRole } = render(
<RenderNonIdealState editorMosaic={editorMosaic} />,
);
await userEvent.click(getByRole('button'));

expect(resetLayoutSpy).toHaveBeenCalledTimes(1);
});
});
8 changes: 7 additions & 1 deletion src/renderer/components/editors-non-ideal-state.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,13 @@ import { Button, NonIdealState } from '@blueprintjs/core';

import { EditorMosaic } from '../editor-mosaic';

export function renderNonIdealState(editorMosaic: EditorMosaic) {
type RenderNonIdealStateProps = {
editorMosaic: EditorMosaic;
};

export function RenderNonIdealState({
editorMosaic,
}: RenderNonIdealStateProps) {
const resolveButton = (
<Button text="Reset editors" onClick={() => editorMosaic.resetLayout()} />
);
Expand Down
4 changes: 2 additions & 2 deletions src/renderer/components/editors.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import {
} from 'react-mosaic-component';

import { Editor } from './editor';
import { renderNonIdealState } from './editors-non-ideal-state';
import { RenderNonIdealState } from './editors-non-ideal-state';
import { MaximizeButton, RemoveButton } from './editors-toolbar-button';
import { EditorId, SetFiddleOptions } from '../../interfaces';
import { AppState } from '../state';
Expand Down Expand Up @@ -262,7 +262,7 @@ export const Editors = observer(
className={`focused__${this.state.focused}`}
onChange={this.onChange}
value={editorMosaic.mosaic}
zeroStateView={renderNonIdealState(editorMosaic)}
zeroStateView={<RenderNonIdealState editorMosaic={editorMosaic} />}
renderTile={this.renderTile}
/>
);
Expand Down

This file was deleted.

0 comments on commit 5c8cb85

Please sign in to comment.