Skip to content

Instantly share code, notes, and snippets.

@jvanderen1
Created December 1, 2019 21:12
Show Gist options
  • Save jvanderen1/ce97dbe6bb8ef07cafb68b0c2d432949 to your computer and use it in GitHub Desktop.
Save jvanderen1/ce97dbe6bb8ef07cafb68b0c2d432949 to your computer and use it in GitHub Desktop.
describe('Interaction', () => {
let root;
let instance;
beforeEach(() => {
component = getComponent();
root = component.root;
instance = root.instance;
});
afterEach(() => {
jest.clearAllMocks();
});
describe('Set columns button', () => {
let numericInputComponent;
beforeEach(() => {
[ numericInputComponent ] = root.findAllByType('NumericInputComponent');
});
it('handles `handleSetNumCols` with change in columns correctly', () => {
const numCols = 1;
const value = { tableValues: [ [ 0 ], [ 0 ] ] };
instance.setState = jest.fn();
numericInputComponent.props.onClick(numCols);
expect(instance.setState).toHaveBeenCalledWith(value);
expect(instance.props.setNumCols).toHaveBeenCalledWith(numCols);
});
it('handles `handleSetNumCols` with no change in columns correctly', () => {
const numCols = 2;
instance.setState = jest.fn();
numericInputComponent.props.onClick(numCols);
expect(instance.setState).not.toHaveBeenCalled();
expect(instance.props.setNumCols).not.toHaveBeenCalled();
});
});
describe('Set rows button', () => {
let numericInputComponent;
beforeEach(() => {
[ , numericInputComponent ] = root.findAllByType('NumericInputComponent');
});
it('handles `handleSetNumRows` with change in rows correctly', () => {
const numRows = 1;
const value = { tableValues: [ [ 0, 0 ] ] };
instance.setState = jest.fn();
numericInputComponent.props.onClick(numRows);
expect(instance.setState).toHaveBeenCalledWith(value);
expect(instance.props.setNumRows).toHaveBeenCalledWith(numRows);
});
it('handles `handleSetNumRows` with no change in rows correctly', () => {
const numRows = 2;
instance.setState = jest.fn();
numericInputComponent.props.onClick(numRows);
expect(instance.setState).not.toHaveBeenCalled();
expect(instance.props.setNumRows).not.toHaveBeenCalled();
});
});
describe('Randomize button', () => {
let buttonComponent;
beforeEach(() => {
buttonComponent = root.findByType('ButtonComponent');
});
it('handles `setTableValues` correctly', () => {
const value = { tableValues: [ [ 0, 0 ], [ 0, 0 ] ] };
instance.setState = jest.fn();
buttonComponent.props.onClick();
expect(instance.setState).toHaveBeenCalledWith(value);
});
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment