Skip to content

Commit

Permalink
Modified verification screen test cases (#329)
Browse files Browse the repository at this point in the history
Signed-off-by: Aravindhan Alagesan <[email protected]>
  • Loading branch information
aranaravi authored Aug 29, 2024
1 parent 2238b8f commit 9808fd4
Showing 1 changed file with 69 additions and 204 deletions.
Original file line number Diff line number Diff line change
@@ -1,15 +1,43 @@
import { QueryCache, QueryClient } from "@tanstack/react-query";
import { screen } from "@testing-library/react";

import { renderWithClient } from "~utils/test";
import * as useStompClient from "~pages/shared/stompWs";
import { render, screen, fireEvent, waitFor } from '@testing-library/react';
import { useTranslation } from 'react-i18next';
import { EkycVerificationStep, useEkycVerificationStore } from '~pages/EkycVerificationPage/useEkycVerificationStore';
import { VerificationScreen } from '../VerificationScreen';
import { SettingsDto } from "~typings/types";

import { VerificationScreen } from "../VerificationScreen";

describe("VerificationScreen (vs)", () => {
const queryCache = new QueryCache();
const queryClient = new QueryClient({ queryCache });
// Mocking dependencies
jest.mock('react-i18next', () => ({
useTranslation: jest.fn(() => ({ t: (key: string) => key })),
}));

jest.mock('~services/langConfig.service', () => ({
getLangCodeMapping: jest.fn().mockResolvedValue({}),
}));

jest.mock('~pages/shared/stompWs', () => ({
useStompClient: () => ({
client: { activate: jest.fn(), deactivate: jest.fn() },
connected: true,
publish: jest.fn(),
subscribe: jest.fn(),
unsubscribe: jest.fn(),
}),
}));

jest.mock('../useEkycVerificationStore', () => ({
useEkycVerificationStore: jest.fn(() => ({
setIsNoBackground: jest.fn(),
setErrorBannerMessage: jest.fn(),
errorBannerMessage: null,
slotId: 'test-slot-id',
setStep: jest.fn(),
setSlotId: jest.fn(),
})),
}));

describe('VerificationScreen', () => {
const defaultProps = {
cancelPopup: jest.fn(),
};

const settings = {
response: {
Expand All @@ -19,204 +47,41 @@ describe("VerificationScreen (vs)", () => {
},
},
} as SettingsDto;
const cancelPopup = jest.fn();

it("should have a connected indicator when web socket is connected", async () => {
// Arrange
jest.spyOn(useStompClient, "default").mockReturnValue({
client: null,
connected: true,
subscribe: jest.fn(),
publish: jest.fn(),
unsubscribe: jest.fn(),
});

renderWithClient(
queryClient,
<VerificationScreen
settings={settings.response}
cancelPopup={cancelPopup}
/>
);

// Act

// Assert
const statusConnected = await screen.findByTestId("websocket-connected");
expect(statusConnected).toBeInTheDocument();
it('renders loading indicator when not connected', () => {
// Override the mock to simulate not connected state
jest.mock('~pages/shared/stompWs', () => ({
useStompClient: () => ({
client: { activate: jest.fn(), deactivate: jest.fn() },
connected: false,
publish: jest.fn(),
subscribe: jest.fn(),
unsubscribe: jest.fn(),
}),
}));

render(<VerificationScreen settings={settings.response} cancelPopup={defaultProps.cancelPopup}/>);

expect(screen.getByText('please_wait')).toBeInTheDocument();
});

it("should have a disconnected indicator when web socket is disconnected", async () => {
// Arrange
jest.spyOn(useStompClient, "default").mockReturnValue({
client: null,
connected: false,
subscribe: jest.fn(),
publish: jest.fn(),
unsubscribe: jest.fn(),
it('displays webcam and handles errors', async () => {
// Render the component
render(<VerificationScreen settings={settings.response} cancelPopup={defaultProps.cancelPopup}/>);

// Check if webcam is rendered
expect(screen.getByRole('button', { hidden: true })).toBeInTheDocument();

// Simulate error scenario
await waitFor(() => {
// Set the error in the mock store
const mockStore = useEkycVerificationStore();
mockStore.setErrorBannerMessage('Test Error Message');

// Check if error message is displayed
expect(screen.getByText('Test Error Message')).toBeInTheDocument();
});

renderWithClient(
queryClient,
<VerificationScreen
settings={settings.response}
cancelPopup={cancelPopup}
/>
);

// Act

// Assert
const statusDisconnected = await screen.findByTestId(
"websocket-disconnected"
);
expect(statusDisconnected).toBeInTheDocument();
});

it("should show onscreen instructions above the video frame", async () => {
// Arrange
jest.spyOn(useStompClient, "default").mockReturnValue({
client: null,
connected: true,
subscribe: jest.fn(),
publish: jest.fn(),
unsubscribe: jest.fn(),
});

renderWithClient(
queryClient,
<VerificationScreen
settings={settings.response}
cancelPopup={cancelPopup}
/>
);

// Act

// Assert
// 1. `vs-onscreen-instruction` is in the document
// 2. `vs-onscreen-instruction` should say "Welcome! Initiating Identity verification process in..."
const vsOnScreenInstruction = await screen.findByTestId(
"vs-onscreen-instruction"
);
expect(vsOnScreenInstruction).toBeInTheDocument();
});

// Currently not sure since liveness depends on the web socket's response
it("should show liveliness verification screen", () => {
// Arrange
renderWithClient(
queryClient,
<VerificationScreen
settings={settings.response}
cancelPopup={cancelPopup}
/>
);

// Act

// Assert
const vsLiveliness = screen.getByTestId("vs-liveliness");
expect(vsLiveliness).toBeInTheDocument();
});

// Currently not sure since liveness depends on the web socket's response
it("should show solid colors across the full screen for color based frame verification", async () => {
// Arrange
renderWithClient(
queryClient,
<VerificationScreen
settings={settings.response}
cancelPopup={cancelPopup}
/>
);

// Act
// TODO: add wait for x seconds

// Assert
const vsSolidColorScreen = screen.getByTestId("vs-solid-color-screen");
expect(vsSolidColorScreen).toBeInTheDocument();
});

// Currently not sure since liveness depends on the web socket's response
it("should show NID verification screen", () => {
// Arrange
renderWithClient(
queryClient,
<VerificationScreen
settings={settings.response}
cancelPopup={cancelPopup}
/>
);

// Act

// Assert
const vsNID = screen.getByTestId("vs-nid");
expect(vsNID).toBeInTheDocument();
});

// This one should be moved to IdentityVerificationScreen instead
// https://xd.adobe.com/view/d1ca3fd3-a54c-4055-b7a2-ee5ad0389788-8499/screen/ba9b246e-7658-4c2b-adb5-b908ecdc3825/specs/
// https://xd.adobe.com/view/d1ca3fd3-a54c-4055-b7a2-ee5ad0389788-8499/screen/8f43b20a-1a6a-4a49-b751-e1e2ccb2346b/specs/
it("should show feedback message when verification fails", () => {
// Arrange
// TODO: mock failed verification
renderWithClient(
queryClient,
<VerificationScreen
settings={settings.response}
cancelPopup={cancelPopup}
/>
);

// Act

// Assert
const vsFailedVerification = screen.getByTestId("vs-failed-verification");
expect(vsFailedVerification).toBeInTheDocument();
});

// This one should be moved to IdentityVerificationScreen instead
// https://xd.adobe.com/view/d1ca3fd3-a54c-4055-b7a2-ee5ad0389788-8499/screen/ba9b246e-7658-4c2b-adb5-b908ecdc3825/specs/
// https://xd.adobe.com/view/d1ca3fd3-a54c-4055-b7a2-ee5ad0389788-8499/screen/8f43b20a-1a6a-4a49-b751-e1e2ccb2346b/specs/
it("should show warning message if there is any technical issue", () => {
// Arrange
// TODO: mock technical issue: internet connection lost, ...
renderWithClient(
queryClient,
<VerificationScreen
settings={settings.response}
cancelPopup={cancelPopup}
/>
);

// Act

// Assert
const vsTechnicalIssueWarningMsg = screen.getByTestId(
"vs-technical-issue-warning-msg"
);
expect(vsTechnicalIssueWarningMsg).toBeInTheDocument();
});

// This one should be moved to IdentityVerificationScreen instead
// https://xd.adobe.com/view/d1ca3fd3-a54c-4055-b7a2-ee5ad0389788-8499/screen/8ee5c56c-1cd5-4b52-adc4-4350f88e8973/specs/
it("should be redirected to the leading screen when the verification is successful", () => {
// Arrange
// TODO: mock successful verification
renderWithClient(
queryClient,
<VerificationScreen
settings={settings.response}
cancelPopup={cancelPopup}
/>
);

// Act

// Assert
// to be redirected to and land on the leading screen
});
// Add more test cases to cover different scenarios
});

0 comments on commit 9808fd4

Please sign in to comment.