|
|
@@ -1,4 +1,4 @@
|
|
|
-import { act, fireEvent, render } from '@testing-library/react';
|
|
|
+import { act, fireEvent, render, RenderResult } from '@testing-library/react';
|
|
|
import React from 'react';
|
|
|
|
|
|
import { Identify, Props } from './identify';
|
|
|
@@ -7,6 +7,7 @@ describe(Identify.name, () => {
|
|
|
const props: Props = {
|
|
|
connecting: false,
|
|
|
onIdentify: jest.fn(),
|
|
|
+ setInteracted: jest.fn(),
|
|
|
};
|
|
|
|
|
|
it('should render an input', () => {
|
|
|
@@ -22,11 +23,10 @@ describe(Identify.name, () => {
|
|
|
});
|
|
|
|
|
|
describe('when pressing the connect button', () => {
|
|
|
- it('should call the onIdentify prop', () => {
|
|
|
- expect.assertions(2);
|
|
|
- const { getByDisplayValue, getByText } = render(<Identify {...props} />);
|
|
|
- const input = getByDisplayValue('');
|
|
|
- const button = getByText('Connect');
|
|
|
+ const setupConnect = (): RenderResult => {
|
|
|
+ const renderResult = render(<Identify {...props} />);
|
|
|
+ const input = renderResult.getByDisplayValue('');
|
|
|
+ const button = renderResult.getByText('Connect');
|
|
|
|
|
|
act(() => {
|
|
|
fireEvent.change(input, { target: { value: 'my-computer' } });
|
|
|
@@ -35,9 +35,24 @@ describe(Identify.name, () => {
|
|
|
fireEvent.click(button);
|
|
|
});
|
|
|
|
|
|
+ return renderResult;
|
|
|
+ };
|
|
|
+
|
|
|
+ it('should call the onIdentify prop', () => {
|
|
|
+ expect.assertions(2);
|
|
|
+ setupConnect();
|
|
|
+
|
|
|
expect(props.onIdentify).toHaveBeenCalledTimes(1);
|
|
|
expect(props.onIdentify).toHaveBeenCalledWith('my-computer');
|
|
|
});
|
|
|
+
|
|
|
+ it('should set interacted to true', () => {
|
|
|
+ expect.assertions(2);
|
|
|
+ setupConnect();
|
|
|
+
|
|
|
+ expect(props.setInteracted).toHaveBeenCalledTimes(1);
|
|
|
+ expect(props.setInteracted).toHaveBeenCalledWith(true);
|
|
|
+ });
|
|
|
});
|
|
|
|
|
|
describe('when connecting', () => {
|