-
Notifications
You must be signed in to change notification settings - Fork 42
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
ES-1011: Verification Screen Unit Test Integration (#295)
* fix: move from msw service to worker Signed-off-by: bunsy-0900 <[email protected]> * wip: testing mock stomp broker Signed-off-by: bunsy-0900 <[email protected]> * fix: add todos and jest-websocket-mock Signed-off-by: bunsy-0900 <[email protected]> * chore: add what to do Signed-off-by: bunsy-0900 <[email protected]> * fix: add unit test for web socket indicator Signed-off-by: bunsy-0900 <[email protected]> --------- Signed-off-by: bunsy-0900 <[email protected]> Signed-off-by: Aravindhan Alagesan <[email protected]> Co-authored-by: Aravindhan Alagesan <[email protected]>
- Loading branch information
1 parent
1149ded
commit 0f86a49
Showing
14 changed files
with
333 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,37 @@ | ||
/// <reference types="jest-extended" /> | ||
|
||
declare module "mock-stomp-broker" { | ||
interface Config { | ||
port?: number; | ||
portRange?: [number, number]; | ||
endpoint?: string; | ||
} | ||
|
||
class MockStompBroker { | ||
private static PORTS_IN_USE; | ||
private static BASE_SESSION; | ||
private static getRandomInt; | ||
private static getPort; | ||
private readonly port; | ||
private readonly httpServer; | ||
private readonly stompServer; | ||
private readonly sentMessageIds; | ||
private queriedSessionIds; | ||
private sessions; | ||
private thereAreNewSessions; | ||
private setMiddleware; | ||
private registerMiddlewares; | ||
|
||
constructor({ port, portRange, endpoint }?: Config); | ||
|
||
public newSessionsConnected(): Promise<string[]>; | ||
public subscribed(sessionId: string): Promise<void>; | ||
public scheduleMessage(topic: string, payload: any, headers?: {}): string; | ||
public messageSent(messageId: string): Promise<void>; | ||
public disconnected(sessionId: string): Promise<void>; | ||
public kill(): void; | ||
public getPort(): number; | ||
} | ||
|
||
export default MockStompBroker; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,9 @@ | ||
import { checkSlotHandlers } from "./slot-checking"; | ||
import { testConnectionHandlers } from "./test-connection"; | ||
|
||
export const handlers = [...checkSlotHandlers]; | ||
export const handlers = [ | ||
// intercept the "test connection" endpoint | ||
...testConnectionHandlers, | ||
// intercept the "check slot" endpoint | ||
...checkSlotHandlers, | ||
]; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
import { http, HttpResponse } from "msw"; | ||
|
||
// endpoint to be intercepted | ||
const testConnectionEP = "http://localhost:8088/v1/signup/test"; | ||
|
||
const testConnectionSuccess = http.get(testConnectionEP, async () => { | ||
return HttpResponse.json({ | ||
responseTime: "2024-03-25T18:10:18.520Z", | ||
response: { | ||
connection: true, | ||
}, | ||
errors: [], | ||
}); | ||
}); | ||
|
||
export const testConnectionHandlers = [testConnectionSuccess]; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
import { setupWorker } from "msw/browser"; | ||
|
||
import { handlers } from "./handlers"; | ||
|
||
export const mswWorker = setupWorker(...handlers); |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -469,4 +469,4 @@ export const VerificationScreen = ({ | |
</button> | ||
</div> | ||
); | ||
}; | ||
}; |
222 changes: 222 additions & 0 deletions
222
...i/src/pages/EkycVerificationPage/VerificationScreen/__tests__/VerificationScreen.test.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,222 @@ | ||
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 { SettingsDto } from "~typings/types"; | ||
|
||
import { VerificationScreen } from "../VerificationScreen"; | ||
|
||
describe("VerificationScreen (vs)", () => { | ||
const queryCache = new QueryCache(); | ||
const queryClient = new QueryClient({ queryCache }); | ||
|
||
const settings = { | ||
response: { | ||
configs: { | ||
"signin.redirect-url": | ||
"https://esignet.camdgc-dev1.mosip.net/authorize", | ||
}, | ||
}, | ||
} 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("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(), | ||
}); | ||
|
||
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 | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
declare module 'stomp-broker-js'; |
Oops, something went wrong.