text: import React from 'react';
  import { Provider } from 'react-redux';
  import * as deps from '../../../Helpers/APIHelper';
  import CVEPairStatusModal from './CvePairStatusModal';
  import { mountWithIntl } from '../../../Helpers/MiscHelper';
  import ReducerRegistry from '../../../Utilities/ReducerRegistry';
  import { act } from 'react-dom/test-utils';
  
  const MockStore = ({ children }) => <Provider store={ReducerRegistry.getStore()}>{children}</Provider>;
  
  // testing for correct default checkbox, enabled alert box when statuses are different, and correct params sent to the setSystemCveStatus()
  describe('CvePairStatusModal component', () => {
      const cveSingle = [ 
          { id: "CVE-2020-0001", status_id: "3", justification: "old justification" } 
      ];
  
      const cveMultiple = [ 
          { id: "CVE-2020-0001", status_id: "3", justification: "old justification" },
          { id: "CVE-2020-0002", status_id: "4", justification: "old justification" } 
      ];
  
      const systemSingle = [
          { id: "system-1", status_id: "2", justification: "old justification" } 
      ];
  
      const systemMultiple = [ 
          { id: "system-1", status_id: "3", justification: "old justification" },
          { id: "system-2", status_id: "4", justification: "different old justification" } 
      ];
  
      it('should render from perspective of system CVE table with one CVE selected', () => {
          const setSystemCveStatusMock = jest.fn(parameters => new Promise(resolve => resolve(parameters)));
          deps.setSystemCveStatus = setSystemCveStatusMock;
  
          const pairStatusModal = mountWithIntl(
              <MockStore>
                  <CVEPairStatusModal open type={'systemDetail'} cveList={cveSingle} inventoryList={systemSingle}/>
              </MockStore>
          );
          
          const isStatusDisabled            = pairStatusModal.find('FormSelect').prop('isDisabled');
          const isJustificationNoteDisabled = pairStatusModal.find('TextArea').first().prop('disabled');
          const setStatus                   = pairStatusModal.find('FormSelect').prop('onChange');
          const setJustificationNote        = pairStatusModal.find('TextArea').first().prop('onChange');
          const setOverallCheckbox          = pairStatusModal.find('Checkbox').prop('onChange');
          const alertBox                    = pairStatusModal.find({ "aria-label": "Warning Alert"});
          const saveButton                  = pairStatusModal.find({ variant: 'primary' }).last();
  
          expect(alertBox.exists()).toBeFalsy();
  
          act(() => {
              setOverallCheckbox(false);
          });
          
          expect(isStatusDisabled).toBeFalsy();
          expect(isJustificationNoteDisabled).toBeFalsy();
  
          act(() => {
              setStatus(5);
              setJustificationNote('new justification');
          });
          saveButton.simulate('click');
          
          expect(setSystemCveStatusMock).toBeCalledWith({
              cve: ['CVE-2020-0001'],
              inventory_id: ['system-1'],
              status_id: 5,
              status_text: 'new justification'
          });
      });
  
      it('should render from perspective of system CVE table with multiple CVE with different statuses selected', () => {
          const setSystemCveStatusMock = jest.fn(parameters => new Promise(resolve => resolve(parameters)));
          deps.setSystemCveStatus = setSystemCveStatusMock;
  
          const pairStatusModal = mountWithIntl(
              <MockStore>
                  <CVEPairStatusModal open type={'systemDetail'} cveList={cveMultiple} inventoryList={systemSingle}/>
              </MockStore>
          );
  
          const setStatus            = pairStatusModal.find('FormSelect').prop('onChange');
          const setJustificationNote = pairStatusModal.find('TextArea').first().prop('onChange');
          const setOverallCheckbox   = pairStatusModal.find('Checkbox').prop('onChange');
          const alertBox             = pairStatusModal.find({ "aria-label": "Warning Alert"});
          const saveButton           = pairStatusModal.find({ variant: 'primary' }).last();
  
          expect(alertBox.exists()).toBeTruthy();
  
          act(() => {
              setOverallCheckbox(false);
              setStatus(5);
              setJustificationNote('new justification');
          });
          saveButton.simulate('click');
          
          expect(setSystemCveStatusMock).toBeCalledWith({
              cve: ['CVE-2020-0001', 'CVE-2020-0002'],
              inventory_id: ['system-1'],
              status_id: 5,
              status_text: 'new justification'
          });
      });
  
      it('should render from perspective of affected systems table with single system selected', () => {
          const setSystemCveStatusMock = jest.fn(parameters => new Promise(resolve => resolve(parameters)));
          deps.setSystemCveStatus = setSystemCveStatusMock;
  
          const pairStatusModal = mountWithIntl(
              <MockStore>
                  <CVEPairStatusModal open type={'systemsExposed'} cveList={cveSingle} inventoryList={systemSingle} />
              </MockStore>
          );
  
          const setStatus            = pairStatusModal.find('FormSelect').prop('onChange');
          const setJustificationNote = pairStatusModal.find('TextArea').first().prop('onChange');
          const setOverallCheckbox   = pairStatusModal.find('Checkbox').prop('onChange');
          const alertBox             = pairStatusModal.find({ "aria-label": "Warning Alert"});
          const saveButton           = pairStatusModal.find({ variant: 'primary' }).last();
  
          expect(alertBox.exists()).toBeFalsy();
          
          act(() => {
              setOverallCheckbox(false);
              setStatus(5);
              setJustificationNote('new justification');
          });
          saveButton.simulate('click');
          
          expect(setSystemCveStatusMock).toBeCalledWith({
              cve: ['CVE-2020-0001'],
              inventory_id: ['system-1'],
              status_id: 5,
              status_text: 'new justification'
          });
      });
  
      it('should render from perspective of affected systems table with multiple systems with different statuses selected', () => {
          const setSystemCveStatusMock = jest.fn(parameters => new Promise(resolve => resolve(parameters)));
          deps.setSystemCveStatus = setSystemCveStatusMock;
          
          const pairStatusModal = mountWithIntl(
              <MockStore>
                  <CVEPairStatusModal open type={'systemsExposed'} cveList={cveSingle} inventoryList={systemMultiple}/>
              </MockStore>
          );
  
          const setStatus            = pairStatusModal.find('FormSelect').prop('onChange');
          const setJustificationNote = pairStatusModal.find('TextArea').first().prop('onChange');
          const setOverallCheckbox   = pairStatusModal.find('Checkbox').prop('onChange');
          const alertBox             = pairStatusModal.find({ "aria-label": "Warning Alert"});
          const saveButton           = pairStatusModal.find({ variant: 'primary' }).last();
  
          expect(alertBox.exists()).toBeTruthy();
          
          act(() => {
              setOverallCheckbox(false);
              setStatus(5);
              setJustificationNote('new justification');
          })
          saveButton.simulate('click');
  
          
          expect(setSystemCveStatusMock).toBeCalledWith({
              cve: ['CVE-2020-0001'],
              inventory_id: ['system-1', 'system-2'],
              status_id: 5,
              status_text: 'new justification'
          });
      });
  
      it('should render from perspective of affected systems table with multiple systems selected and use overall justification', () => {
          const setSystemCveStatusMock = jest.fn(parameters => new Promise(resolve => resolve(parameters)));
          deps.setSystemCveStatus = setSystemCveStatusMock;
  
          const pairStatusModal = mountWithIntl(
              <MockStore>
                  <CVEPairStatusModal open type={'systemsExposed'} cveList={cveSingle} inventoryList={systemMultiple}/>
              </MockStore>
          );
  
          const isStatusDisabled            = pairStatusModal.find('FormSelect').prop('isDisabled');
          const isJustificationNoteDisabled = pairStatusModal.find('TextArea').first().prop('disabled');
          const setOverallCheckbox          = pairStatusModal.find('Checkbox').prop('onChange');
          const alertBox                    = pairStatusModal.find({ "aria-label": "Warning Alert"});
          const saveButton                  = pairStatusModal.find({ variant: 'primary' }).last();
  
          expect(alertBox.exists()).toBeTruthy();
  
          act(() => {
              setOverallCheckbox(true);
          })
  
          expect(isStatusDisabled).toBeFalsy();
          expect(isJustificationNoteDisabled).toBeFalsy();
  
          saveButton.simulate('click');
          
          expect(setSystemCveStatusMock).toBeCalledWith({
              cve: ['CVE-2020-0001'],
              inventory_id: ['system-1', 'system-2'],
          });
      });
  });
  