<commit_before>import React from 'react';
import { shallow } from 'enzyme';
import { Message } from 'retranslate';

import { Link, Redirect } from 'react-router-dom';
import { ConfirmMandate } from './ConfirmMandate';
import FundTransferTable from './fundTransferTable';
import MandateNotFilledAlert from './mandateNotFilledAlert';
import { Loader, AuthenticationLoader, ErrorMessage } from '../../../common';

describe('Confirm mandate step', () => {
  let component;

  beforeEach(() => {
    component = shallow(
      <ConfirmMandate
        exchange={{
          loadingSourceFunds: false,
          loadingTargetFunds: false,
          sourceSelection: [],
          selectedFutureContributionsFundIsin: null,
          agreedToTerms: false,
        }}
      />,
    );
  });

  it('redirects to previous path only when no address', () => {
    component.setProps({
      previousPath: '/a-path',
      exchange: {
        sourceSelection: [],
        selectedFutureContributionsFundIsin: 'EE123',
      },
    });
    const redirects = () => component.contains(<Redirect to="/a-path" />);

    expect(redirects()).toBe(true);
    component.setProps({ hasAddress: true });
    expect(redirects()).toBe(false);
  });

  it('renders a loader if it is loading the user or funds', () => {
    const expectComponentToBeLoader = () =>
      expect(component.at(0).getElement(0)).toEqual(<Loader className="align-middle" />);
    const expectComponentNotToBeLoader = () =>
      expect(component.at(0).getElement(0)).not.toEqual(<Loader className="align-middle" />);

    component.setProps({ loading: true });
    expectComponentToBeLoader();

    component.setProps({ loading: false });
    expectComponentNotToBeLoader();
  });

  it('shows the intro to the mandate', () => {
    const exchange = {
      sourceSelection: [],
      selectedFutureContributionsFundIsin: 'asd',
    };
    component.setProps({ exchange });
    expect(component.contains(<Message>confirm.mandate.intro</Message>)).toBe(true);
  });

  it('shows the future contribution fund if one is given', () => {
    const exchange = {
      selectedFutureContributionsFundIsin: 'test isin',
      sourceSelection: [],
    };
    const selectedFutureContributionsFund = { name: 'test name' };
    component.setProps({ exchange, selectedFutureContributionsFund });
    expect(
      component.contains(
        <div className="mt-4">
          <Message>confirm.mandate.future.contribution</Message>
          <b className="highlight">test name</b>
        </div>,
      ),
    ).toBe(true);
    exchange.selectedFutureContributionsFundIsin = null;
    component.setProps({ exchange });
    expect(component.contains(<Message>confirm.mandate.future.contribution</Message>)).toBe(false);
  });

  it('has a back button', () => {
    const onPreviousStep = jest.fn();
    component.setProps({
      exchange: {
        sourceSelection: [],
        selectedFutureContributionsFundIsin: 'asd',
      },
      onPreviousStep,
    });
    expect(
      component.contains(
        <Link to="/2nd-pillar-flow">
          <button type="button" className="btn btn-secondary mb-2">
            <Message>steps.previous</Message>
          </button>
        </Link>,
      ),
    ).toBe(true);
  });

  it('does not show the funds table if you are not transferring funds', () => {
    const sourceSelection = [
      { percentage: 0, sourceFundIsin: 'source 1', targetFundIsin: 'target 2' },<commit_msg>Update spec<commit_after>import React from 'react';
import { shallow } from 'enzyme';
import { Message } from 'retranslate';

import { Link, Redirect } from 'react-router-dom';
import { ConfirmMandate } from './ConfirmMandate';
import FundTransferTable from './fundTransferTable';
import MandateNotFilledAlert from './mandateNotFilledAlert';
import { Loader, AuthenticationLoader, ErrorMessage } from '../../../common';

describe('Confirm mandate step', () => {
  let component;

  beforeEach(() => {
    component = shallow(
      <ConfirmMandate
        exchange={{
          loadingSourceFunds: false,
          loadingTargetFunds: false,
          sourceSelection: [],
          selectedFutureContributionsFundIsin: null,
          agreedToTerms: false,
        }}
      />,
    );
  });

  it('redirects to previous path only when no address', () => {
    component.setProps({
      previousPath: '/a-path',
      exchange: {
        sourceSelection: [],
        selectedFutureContributionsFundIsin: 'EE123',
      },
    });
    const redirects = () => component.contains(<Redirect to="/a-path" />);

    expect(redirects()).toBe(true);
    component.setProps({ hasAddress: true });
    expect(redirects()).toBe(false);
  });

  it('renders a loader if it is loading the user or funds', () => {
    const expectComponentToBeLoader = () =>
      expect(component.at(0).getElement(0)).toEqual(<Loader className="align-middle" />);
    const expectComponentNotToBeLoader = () =>
      expect(component.at(0).getElement(0)).not.toEqual(<Loader className="align-middle" />);

    component.setProps({ loading: true });
    expectComponentToBeLoader();

    component.setProps({ loading: false });
    expectComponentNotToBeLoader();
  });

  it('shows the intro to the mandate', () => {
    const exchange = {
      sourceSelection: [],
      selectedFutureContributionsFundIsin: 'asd',
    };
    component.setProps({ exchange });
    expect(component.contains(<Message>confirm.mandate.intro</Message>)).toBe(true);
  });

  it('shows the future contribution fund if one is given', () => {
    const exchange = {
      selectedFutureContributionsFundIsin: 'test isin',
      sourceSelection: [],
    };
    const selectedFutureContributionsFund = { name: '<NAME>' };
    component.setProps({ exchange, selectedFutureContributionsFund });
    expect(
      component.contains(
        <div className="mt-4">
          <Message>confirm.mandate.future.contribution</Message>
          <b className="highlight">test name</b>
        </div>,
      ),
    ).toBe(true);
    exchange.selectedFutureContributionsFundIsin = null;
    component.setProps({ exchange });
    expect(component.contains(<Message>confirm.mandate.future.contribution</Message>)).toBe(false);
  });

  it('has a back button', () => {
    const onPreviousStep = jest.fn();
    component.setProps({
      exchange: {
        sourceSelection: [],
        selectedFutureContributionsFundIsin: 'asd',
      },
      onPreviousStep,
    });
    expect(
      component.contains(
        <Link to="/2nd-pillar-flow/select-sources">
          <button type="button" className="btn btn-secondary mb-2">
            <Message>confirm.mandate.back</Message>
          </button>
        </Link>,
      ),
    ).toBe(true);
  });

  it('does not show the funds table if you are not transferring funds', () => {
    const sourceSelection = [
      { percentage: 0, sourceFundIsin: 'source 1', targetFundIsin: 'target 2' },
{'fraction_non_alphanumeric': 0.146133871898442, 'fraction_numerical': 0.0037507212925562607, 'mean_word_length': 3.1218787158145065, 'pattern_counts': {'":': 0, '<': 44, '<?xml version=': 0, '>': 66, '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': '3957988', 'n_tokens_mistral': 1996, 'n_tokens_neox': 1905, 'n_words': 410}