<commit_before>import React from 'react';
import { expect } from 'chai';
import { render } from '@testing-library/react';
import { SERVICE_PROVIDERS } from 'platform/user/authentication/constants';
import * as authUtilities from 'platform/user/authentication/utilities';
import { externalApplicationsConfig } from 'platform/user/authentication/usip-config';
import VerifyAccountLink from 'platform/user/authentication/components/VerifyAccountLink';
import { mockCrypto } from 'platform/utilities/oauth/mockCrypto';

const csps = ['logingov', 'idme'];

describe('VerifyAccountLink', () => {
  csps.forEach(policy => {
    const oldCrypto = global.window.crypto;

    beforeEach(() => {
      global.window.crypto = mockCrypto;
    });

    afterEach(() => {
      global.window.crypto = oldCrypto;
    });

    it(`should render correctly for each ${policy}`, async () => {
      const screen = render(<VerifyAccountLink policy={policy} />);
      const anchor = await screen.findByTestId(policy);

      expect(anchor.textContent).to.include(
        `Create an account with ${SERVICE_PROVIDERS[policy].label}`,
      );

      screen.unmount();
    });

    it(`should set correct href for ${policy} (SAML)`, async () => {
      const screen = render(
        <VerifyAccountLink policy={policy} useOAuth={false} />,
      );
      const anchor = await screen.findByTestId(policy);
      const href = await authUtilities.signupOrVerify({
        policy,
        isLink: true,
        isSignup: false,
        useOAuth: false,
      });

      expect(anchor.href).to.eql(href);

      screen.unmount();
    });

    it(`should set correct href for ${policy} (OAuth)`, async () => {
      const screen = render(<VerifyAccountLink policy={policy} useOAuth />);
      const anchor = await screen.findByTestId(policy);
      const expectedAcr =
        externalApplicationsConfig.default.oAuthOptions.acrVerify[policy];
      expect(anchor.href).to.include(`type=${policy}`);
      expect(anchor.href).to.include(`acr=${expectedAcr}`);
      expect(anchor.href).to.include(`client_id=web`);
      expect(anchor.href).to.include('/authorize');
      expect(anchor.href).to.include('response_type=code');
      expect(anchor.href).to.include('code_challenge=');
      expect(anchor.href).to.include('state=');
      screen.unmount();
    });
  });
});<commit_msg>hot fix for verify account link (#22324)<commit_after>import React from 'react';
import { expect } from 'chai';
import { render, waitFor } from '@testing-library/react';
import { SERVICE_PROVIDERS } from 'platform/user/authentication/constants';
import * as authUtilities from 'platform/user/authentication/utilities';
import { externalApplicationsConfig } from 'platform/user/authentication/usip-config';
import VerifyAccountLink from 'platform/user/authentication/components/VerifyAccountLink';
import { mockCrypto } from 'platform/utilities/oauth/mockCrypto';

const csps = ['logingov', 'idme'];

describe('VerifyAccountLink', () => {
  csps.forEach(policy => {
    const oldCrypto = global.window.crypto;

    beforeEach(() => {
      global.window.crypto = mockCrypto;
    });

    afterEach(() => {
      global.window.crypto = oldCrypto;
    });

    it(`should render correctly for each ${policy}`, async () => {
      const screen = render(<VerifyAccountLink policy={policy} />);
      const anchor = await screen.findByTestId(policy);

      expect(anchor.textContent).to.include(
        `Create an account with ${SERVICE_PROVIDERS[policy].label}`,
      );

      screen.unmount();
    });

    it(`should set correct href for ${policy} (SAML)`, async () => {
      const screen = render(
        <VerifyAccountLink policy={policy} useOAuth={false} />,
      );
      const anchor = await screen.findByTestId(policy);
      const href = await authUtilities.signupOrVerify({
        policy,
        isLink: true,
        isSignup: false,
        useOAuth: false,
      });

      await waitFor(() => expect(anchor.href).to.eql(href));
      screen.unmount();
    });

    it(`should set correct href for ${policy} (OAuth)`, async () => {
      const screen = render(<VerifyAccountLink policy={policy} useOAuth />);
      const anchor = await screen.findByTestId(policy);
      const expectedAcr =
        externalApplicationsConfig.default.oAuthOptions.acrVerify[policy];

      await waitFor(() => expect(anchor.href).to.include(`type=${policy}`));
      await waitFor(() => expect(anchor.href).to.include(`acr=${expectedAcr}`));
      await waitFor(() => expect(anchor.href).to.include(`client_id=web`));
      await waitFor(() => expect(anchor.href).to.include('/authorize'));
      await waitFor(() => expect(anchor.href).to.include('response_type=code'));
      await waitFor(() => expect(anchor.href).to.include('code_challenge='));
      await waitFor(() => expect(anchor.href).to.include('state='));
      screen.unmount();
    });
  });
});
{'fraction_non_alphanumeric': 0.15541090317331163, 'fraction_numerical': 0.0010170870626525631, 'mean_word_length': 3.6299435028248586, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 31, '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': '6964275', 'n_tokens_mistral': 1436, 'n_tokens_neox': 1433, 'n_words': 281}