teamdigitale/italia-app

View on GitHub
ts/features/messages/components/MessageDetail/__tests__/MessageDetailsPaymentButton.test.tsx

Summary

Maintainability
A
2 hrs
Test Coverage
import * as React from "react";
import { createStore } from "redux";
import { applicationChangeState } from "../../../../../store/actions/application";
import { preferencesDesignSystemSetEnabled } from "../../../../../store/actions/persistedPreferences";
import { appReducer } from "../../../../../store/reducers";
import { MessageDetailsPaymentButton } from "../MessageDetailsPaymentButton";
import { renderScreenWithNavigationStoreContext } from "../../../../../utils/testWrapper";
import { PaymentData, UIMessageId } from "../../../types";
import { ServiceId } from "../../../../../../definitions/backend/ServiceId";

describe("MessageDetailsPaymentButton", () => {
  it("should match snapshot when not loading", () => {
    const screen = renderScreen(false);
    expect(screen.toJSON()).toMatchSnapshot();
  });
  it("should match snapshot when loading", () => {
    const screen = renderScreen(true);
    expect(screen.toJSON()).toMatchSnapshot();
  });
});

const renderScreen = (isLoading: boolean) => {
  const initialState = appReducer(undefined, applicationChangeState("active"));
  const designSystemState = appReducer(
    initialState,
    preferencesDesignSystemSetEnabled({ isDesignSystemEnabled: true })
  );
  const store = createStore(appReducer, designSystemState as any);

  return renderScreenWithNavigationStoreContext(
    () => (
      <MessageDetailsPaymentButton
        messageId={"" as UIMessageId}
        serviceId={"01J5ZQEMZ92CJN7NKZD4NE0RAH" as ServiceId}
        canNavigateToPayment={true}
        isLoading={isLoading}
        paymentData={
          {
            amount: 199,
            noticeNumber: "012345678912345670",
            payee: {
              fiscalCode: "01234567890"
            }
          } as PaymentData
        }
      />
    ),
    "DUMMY",
    {},
    store
  );
};