<commit_before>import { mount } from 'enzyme';
import React from 'react';
import Modal from '../src/Modal';
import { shouldWarn } from './helpers';

describe('<Modal>', () => {
  afterEach(() => {
    // make sure the dangling portal elements get cleaned up
    document.body.innerHTML = '';
  });

  it('Should render the modal content', () => {
    const noOp = () => {};
    mount(
      <Modal show onHide={noOp} animation={false}>
        <strong>Message</strong>
      </Modal>,
    )
      .find('strong')
      .text()
      .should.equal('Message');
  });

  it('Should sets `display: block` to `div.modal` when animation is false', () => {
    const node = mount(
      <Modal show animation={false}>
        <strong>Message</strong>
      </Modal>,
    )
      .find('div.modal')
      .getDOMNode();

    expect(node.style.display).to.equal('block');
  });

  it('Should close the modal when the modal dialog is clicked', (done) => {
    const doneOp = () => {
      done();
    };

    mount(
      <Modal show onHide={doneOp}>
        <strong>Message</strong>
      </Modal>,
    )
      .find('div.modal') // the modal-dialog element is pointer-events: none;
      .simulate('click');
  });

  it('Should not close the modal when the "static" dialog is clicked', () => {
    const onHideSpy = sinon.spy();
    mount(
      <Modal show onHide={onHideSpy} backdrop="static">
        <strong>Message</strong>
      </Modal>,
    )
      .find('ModalDialog')
      .simulate('click');

    expect(onHideSpy).to.not.have.been.called;
  });

  it('Should show "static" dialog animation when backdrop is clicked', () => {
    const noOp = () => {};
    const wrapper = mount(
      <Modal show onHide={noOp} backdrop="static">
        <strong>Message</strong>
      </Modal>,
    );

    const modal = wrapper.find('.modal');
    modal.simulate('click');

    expect(wrapper.find('.modal-static').length).to.equal(1);
  });

  it('Should show "static" dialog animation when esc pressed and keyboard is false', () => {
    const noOp = () => {};
    const wrapper = mount(
      <Modal show onHide={noOp} backdrop="static" keyboard={false}>
        <strong>Message</strong>
      </Modal>,
    );

    const event = new KeyboardEvent('keydown', { keyCode: 27 });
    document.dispatchEvent(event);
    wrapper.update();

    expect(wrapper.find('.modal-static').length).to.equal(1);
  });

  it('Should not show "static" dialog animation when esc pressed and keyboard is true', () => {
    const noOp = () => {};
    const wrapper = mount(
      <Modal show onHide={noOp} backdrop="static" keyboard>
        <strong>Message</strong>
      </Modal>,
    );

    const event = new KeyboardEvent('keydown', { keyCode: 27 });
    document.dispatchEvent(event);
    wrapper.update();

    expect(wrapper.find('.modal-static').length).to.equal(0);
  });

  it('Should not show "static" dialog animation modal backdrop is not "static"', () => {
    const noOp = () => {};
    const wrapper = mount(
      <Modal show onHide={noOp} backdrop>
        <strong>Message</strong>
      </Modal>,
    );

    const modal = wrapper.find('.modal');
    modal.simulate('click');

    expect(wrapper.find('.modal-static').length).to.equal(0);
  });

  it('Should close the modal when the modal close button is clicked', (done) => {
    const doneOp = () => {
      done();
    };

    mount(
      <Modal show onHide={doneOp}>
        <Modal.Header closeButton />
        <strong>Message</strong>
      </Modal>,
    )
      .find('.close')
      .simulate('click');
  });

  it('Should pass className to the dialog', () => {
    const noOp = () => {};
    mount(
      <Modal show className="mymodal" onHide={noOp}>
        <strong>Message</strong>
      </Modal>,
    ).assertSingle('div.modal.mymodal');
  });

  it('Should use backdropClassName to add classes to the backdrop', () => {
    const noOp = () => {};

    mount(
      <Modal show backdropClassName="my-modal-backdrop" onHide={noOp}>
        <strong>Message</strong>
      </Modal>,
    ).find('.modal-backdrop.my-modal-backdrop');
  });

  it('Should pass size to the dialog', () => {
    const noOp = () => {};
    mount(
      <Modal show size="sm" onHide={noOp}>
        <strong>Message</strong>
      </Modal>,
    ).find('.modal-dialog.modal-sm');<commit_msg>test: Increase modal test coverage (#5459)<commit_after>import { mount } from 'enzyme';
import React from 'react';
import Modal from '../src/Modal';
import { shouldWarn } from './helpers';

describe('<Modal>', () => {
  afterEach(() => {
    // make sure the dangling portal elements get cleaned up
    document.body.innerHTML = '';
  });

  it('Should render the modal content', () => {
    const noOp = () => {};
    mount(
      <Modal show onHide={noOp} animation={false}>
        <strong>Message</strong>
      </Modal>,
    )
      .find('strong')
      .text()
      .should.equal('Message');
  });

  it('Should sets `display: block` to `div.modal` when animation is false', () => {
    const node = mount(
      <Modal show animation={false}>
        <strong>Message</strong>
      </Modal>,
    )
      .find('div.modal')
      .getDOMNode();

    expect(node.style.display).to.equal('block');
  });

  it('Should close the modal when the modal dialog is clicked', (done) => {
    const doneOp = () => {
      done();
    };

    mount(
      <Modal show onHide={doneOp}>
        <strong>Message</strong>
      </Modal>,
    )
      .find('div.modal') // the modal-dialog element is pointer-events: none;
      .simulate('click');
  });

  it('Should not close the modal when the "static" dialog is clicked', () => {
    const onHideSpy = sinon.spy();
    mount(
      <Modal show onHide={onHideSpy} backdrop="static">
        <strong>Message</strong>
      </Modal>,
    )
      .find('ModalDialog')
      .simulate('click');

    expect(onHideSpy).to.not.have.been.called;
  });

  it('Should show "static" dialog animation when backdrop is clicked', () => {
    const noOp = () => {};
    const wrapper = mount(
      <Modal show onHide={noOp} backdrop="static">
        <strong>Message</strong>
      </Modal>,
    );

    const modal = wrapper.find('.modal');
    modal.simulate('click');

    expect(wrapper.find('.modal-static').length).to.equal(1);
  });

  it('Should show "static" dialog animation when esc pressed and keyboard is false', () => {
    const noOp = () => {};
    const wrapper = mount(
      <Modal show onHide={noOp} backdrop="static" keyboard={false}>
        <strong>Message</strong>
      </Modal>,
    );

    const event = new KeyboardEvent('keydown', { keyCode: 27 });
    document.dispatchEvent(event);
    wrapper.update();

    expect(wrapper.find('.modal-static').length).to.equal(1);
  });

  it('Should not show "static" dialog animation when esc pressed and keyboard is true', () => {
    const noOp = () => {};
    const wrapper = mount(
      <Modal show onHide={noOp} backdrop="static" keyboard>
        <strong>Message</strong>
      </Modal>,
    );

    const event = new KeyboardEvent('keydown', { keyCode: 27 });
    document.dispatchEvent(event);
    wrapper.update();

    expect(wrapper.find('.modal-static').length).to.equal(0);
  });

  it('Should not show "static" dialog animation modal backdrop is not "static"', () => {
    const noOp = () => {};
    const wrapper = mount(
      <Modal show onHide={noOp} backdrop>
        <strong>Message</strong>
      </Modal>,
    );

    const modal = wrapper.find('.modal');
    modal.simulate('click');

    expect(wrapper.find('.modal-static').length).to.equal(0);
  });

  it('Should close the modal when the modal close button is clicked', (done) => {
    const doneOp = () => {
      done();
    };

    mount(
      <Modal show onHide={doneOp}>
        <Modal.Header closeButton />
        <strong>Message</strong>
      </Modal>,
    )
      .find('.close')
      .simulate('click');
  });

  it('Should pass className to the dialog', () => {
    const noOp = () => {};
    mount(
      <Modal show className="mymodal" onHide={noOp}>
        <strong>Message</strong>
      </Modal>,
    ).assertSingle('div.modal.mymodal');
  });

  it('Should use backdropClassName to add classes to the backdrop', () => {
    const noOp = () => {};

    mount(
      <Modal show backdropClassName="my-modal-backdrop" onHide={noOp}>
        <strong>Message</strong>
      </Modal>,
    ).find('.modal-backdrop.my-modal-backdrop');
  });

  it('Should pass size to the dialog', () => {
    const noOp = () => {};
    mount(
      <Modal show size="sm" onHide={noOp}>
        <strong>Message</strong>
      </Modal>,
    ).find('.modal-dialog.modal-sm');
  });

  it('Should pass centered to the dialog', () => {
    const noOp = () => {};
    mount(
      <Modal show centered onHide={noOp}>
        <strong>Message</strong>
      </Modal>,
    ).find('.modal-dialog.modal-dialog-centered');
  });

  it('Should pass scrollable to the dialog', () => {
    const noOp = () => {};
    mount(
      <Modal show scrollable onHide={noOp}>
        <strong>Message</strong>
      </Modal>,
    ).find('.modal-dialog.modal-dialog-scrollable');
{'fraction_non_alphanumeric': 0.1800896076931483, 'fraction_numerical': 0.0021855534914217026, 'mean_word_length': 2.669607056936648, 'pattern_counts': {'":': 0, '<': 111, '<?xml version=': 0, '>': 163, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4762844', 'n_tokens_mistral': 2812, 'n_tokens_neox': 2719, 'n_words': 662}