Sha256: 3ffedcd0fac673e0db4f141dd71e3ed4cda0c34c2c2807ef1b450575e7417863

Contents?: true

Size: 1.61 KB

Versions: 64

Compression:

Stored size: 1.61 KB

Contents

import React from 'react';
import { testComponentSnapshotsWithFixtures, mount } from '@theforeman/test';
import { useForemanModal } from 'foremanReact/components/ForemanModal/ForemanModalHooks';
import { ClickConfirmation } from './';

const fixtures = {
  render: {
    title: 'some-title',
    confirmType: 'danger',
    body: 'some-body',
    confirmationMessage: 'some-message',
    id: 'some-id',
    confirmAction: 'some-confirm',
    onClick: jest.fn(),
  },
};

describe('ClickConfirmation', () => {
  testComponentSnapshotsWithFixtures(ClickConfirmation, fixtures);
  it('enable button on checkbox click', () => {
    const component = mount(<ClickConfirmation {...fixtures.render} />);
    const getButton = () => component.find('.confirm-button').at(0);
    expect(getButton().props().disabled).toBeTruthy();
    const checkbox = component.find('input').at(0);
    checkbox.simulate('change', { target: { checked: true } });
    expect(getButton().props().disabled).toBeFalsy();
  });

  it('click test', () => {
    const setModalClosed = jest.fn();
    useForemanModal.mockImplementation(id => ({
      setModalClosed: () => setModalClosed(id),
    }));
    const onClick = jest.fn();
    const props = { ...fixtures.render, onClick };
    const component = mount(<ClickConfirmation {...props} />);
    const getButton = () => component.find('.confirm-button').at(0);
    const checkbox = component.find('input').at(0);
    checkbox.simulate('change', { target: { checked: true } });
    getButton().simulate('click');
    expect(onClick).toBeCalled();
    expect(setModalClosed).toBeCalledWith({ id: fixtures.render.id });
  });
});

Version data entries

64 entries across 64 versions & 1 rubygems

Version Path
foreman-tasks-8.1.2 webpack/ForemanTasks/Components/common/ClickConfirmation/ClickConfirmation.test.js
foreman-tasks-8.1.1 webpack/ForemanTasks/Components/common/ClickConfirmation/ClickConfirmation.test.js
foreman-tasks-8.1.0 webpack/ForemanTasks/Components/common/ClickConfirmation/ClickConfirmation.test.js
foreman-tasks-8.0.2 webpack/ForemanTasks/Components/common/ClickConfirmation/ClickConfirmation.test.js
foreman-tasks-8.0.1 webpack/ForemanTasks/Components/common/ClickConfirmation/ClickConfirmation.test.js
foreman-tasks-8.0.0 webpack/ForemanTasks/Components/common/ClickConfirmation/ClickConfirmation.test.js
foreman-tasks-7.2.1 webpack/ForemanTasks/Components/common/ClickConfirmation/ClickConfirmation.test.js
foreman-tasks-7.1.1 webpack/ForemanTasks/Components/common/ClickConfirmation/ClickConfirmation.test.js
foreman-tasks-7.2.0 webpack/ForemanTasks/Components/common/ClickConfirmation/ClickConfirmation.test.js
foreman-tasks-7.1.0 webpack/ForemanTasks/Components/common/ClickConfirmation/ClickConfirmation.test.js
foreman-tasks-6.0.3 webpack/ForemanTasks/Components/common/ClickConfirmation/ClickConfirmation.test.js
foreman-tasks-7.0.0 webpack/ForemanTasks/Components/common/ClickConfirmation/ClickConfirmation.test.js
foreman-tasks-6.0.2 webpack/ForemanTasks/Components/common/ClickConfirmation/ClickConfirmation.test.js
foreman-tasks-4.1.6 webpack/ForemanTasks/Components/common/ClickConfirmation/ClickConfirmation.test.js
foreman-tasks-5.2.3 webpack/ForemanTasks/Components/common/ClickConfirmation/ClickConfirmation.test.js
foreman-tasks-6.0.1 webpack/ForemanTasks/Components/common/ClickConfirmation/ClickConfirmation.test.js
foreman-tasks-5.2.2 webpack/ForemanTasks/Components/common/ClickConfirmation/ClickConfirmation.test.js
foreman-tasks-6.0.0 webpack/ForemanTasks/Components/common/ClickConfirmation/ClickConfirmation.test.js
foreman-tasks-5.2.1 webpack/ForemanTasks/Components/common/ClickConfirmation/ClickConfirmation.test.js
foreman-tasks-5.3.0 webpack/ForemanTasks/Components/common/ClickConfirmation/ClickConfirmation.test.js