Skip to content

Commit

Permalink
test: migrate editors-non-ideal-state test to RTL (#1627)
Browse files Browse the repository at this point in the history
  • Loading branch information
erikian authored Aug 20, 2024
1 parent 88e1209 commit f6d785d
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 40 deletions.
33 changes: 33 additions & 0 deletions rtl-spec/components/editors-non-ideal-state.spec.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import React from 'react';

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 component', () => {
let editorMosaic: EditorMosaic;

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

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

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

it('handles a click', async () => {
const resetLayoutSpy = jest.spyOn(editorMosaic, 'resetLayout');
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.

23 changes: 0 additions & 23 deletions tests/renderer/components/editors-non-ideal-state-spec.tsx

This file was deleted.

0 comments on commit f6d785d

Please sign in to comment.