mirror of
https://github.com/TryGhost/Ghost.git
synced 2024-11-25 19:48:50 +03:00
Added render tests for common components
no issue - Adds tests for ActionButton and InputField components
This commit is contained in:
parent
eb4ed70303
commit
1a29d0926e
34
ghost/portal/src/components/common/ActionButton.test.js
Normal file
34
ghost/portal/src/components/common/ActionButton.test.js
Normal file
@ -0,0 +1,34 @@
|
||||
import React from 'react';
|
||||
import {render, fireEvent} from '@testing-library/react';
|
||||
import ActionButton from './ActionButton';
|
||||
|
||||
const setup = (overrides) => {
|
||||
const mockOnClickFn = jest.fn();
|
||||
const props = {
|
||||
label: 'Test Action Button', onClick: mockOnClickFn, disabled: false
|
||||
};
|
||||
const utils = render(
|
||||
<ActionButton {...props} />
|
||||
);
|
||||
|
||||
const buttonEl = utils.queryByRole('button', {name: props.label});
|
||||
return {
|
||||
buttonEl,
|
||||
mockOnClickFn,
|
||||
...utils
|
||||
};
|
||||
};
|
||||
|
||||
describe('ActionButton', () => {
|
||||
test('renders', () => {
|
||||
const {buttonEl} = setup();
|
||||
expect(buttonEl).toBeInTheDocument();
|
||||
});
|
||||
|
||||
test('fires onClick', () => {
|
||||
const {buttonEl, mockOnClickFn} = setup();
|
||||
|
||||
fireEvent.click(buttonEl);
|
||||
expect(mockOnClickFn).toHaveBeenCalled();
|
||||
});
|
||||
});
|
38
ghost/portal/src/components/common/InputField.test.js
Normal file
38
ghost/portal/src/components/common/InputField.test.js
Normal file
@ -0,0 +1,38 @@
|
||||
import React from 'react';
|
||||
import {render, fireEvent} from '@testing-library/react';
|
||||
import InputField from './InputField';
|
||||
|
||||
const setup = (overrides = {}) => {
|
||||
const mockOnChangeFn = jest.fn();
|
||||
const props = {
|
||||
name: 'test-input',
|
||||
label: 'Test Input',
|
||||
value: '',
|
||||
placeholder: 'Test placeholder',
|
||||
onChange: mockOnChangeFn
|
||||
};
|
||||
const utils = render(
|
||||
<InputField {...props} />
|
||||
);
|
||||
|
||||
const inputEl = utils.getByLabelText(props.label);
|
||||
return {
|
||||
inputEl,
|
||||
mockOnChangeFn,
|
||||
...utils
|
||||
};
|
||||
};
|
||||
|
||||
describe('InputField', () => {
|
||||
test('renders', () => {
|
||||
const {inputEl} = setup();
|
||||
expect(inputEl).toBeInTheDocument();
|
||||
});
|
||||
|
||||
test('calls onChange on value', () => {
|
||||
const {inputEl, mockOnChangeFn} = setup();
|
||||
fireEvent.change(inputEl, {target: {value: 'Test'}});
|
||||
|
||||
expect(mockOnChangeFn).toHaveBeenCalled();
|
||||
});
|
||||
});
|
Loading…
Reference in New Issue
Block a user