Skip to content

Commit bc4af5f

Browse files
authored
test: [IOPID-2880] add unit test on authentication folder (#6896)
## Short description This pull request improves the test coverage of the authentication feature, focusing on reducers, selectors, hooks and key screens. The update includes both unit and integration tests, covering previously untested branches and edge cases. Also, the structure of the test files has been changed to make them clearer and more understandable | File | % Stmts | % Branch | % Funcs | % Lines | | - | - | - | - | - | | Before ❌ | 43.13 | 28.33 | 32.58 | 43.33 | | After ✅ | 79.48 | 65.42 | 73.65 | 79.78 | ## How to test To verify that the tests run successfully and coverage is correctly calculated, run the following command: ``` yarn jest ts/features/authentication --coverage --collectCoverageFrom="ts/features/authentication/**/*.{ts,tsx}" ``` Ensure all tests pass and the coverage summary reflects the expected increase. No app behavior should be impacted, as only test files were modified. However, some files have been modified by adding testID, exporting functions or types, or changing names.
1 parent 7010892 commit bc4af5f

File tree

113 files changed

+15777
-232
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

113 files changed

+15777
-232
lines changed

ts/components/ui/CircularProgress.tsx

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,10 @@ export const CircularProgress = ({
4242
}));
4343

4444
return (
45-
<View style={styles.circularProgressWrapper}>
45+
<View
46+
style={styles.circularProgressWrapper}
47+
testID={`circular-progress-${Math.round(progress)}`}
48+
>
4649
<Svg
4750
width={size}
4851
height={size}

ts/features/authentication/common/__tests__/authenticationSaga.test.ts

Lines changed: 0 additions & 54 deletions
This file was deleted.

ts/features/authentication/common/__tests__/watchLogoutSaga.test.ts

Lines changed: 0 additions & 39 deletions
This file was deleted.
Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
import { Text } from "react-native";
2+
import { LandingCardComponent } from "../../../../../components/LandingCardComponent";
3+
import { trackCarousel } from "../carouselAnalytics";
4+
import { mixpanelTrack } from "../../../../../mixpanel";
5+
6+
jest.mock("../../../../../mixpanel", () => ({
7+
mixpanelTrack: jest.fn()
8+
}));
9+
10+
describe("trackCarousel", () => {
11+
const createLandingCard = (key: string) => (
12+
<LandingCardComponent
13+
key={key}
14+
id={0}
15+
title={"title"}
16+
content={"content"}
17+
accessibilityLabel={"label"}
18+
pictogramName={"hello"}
19+
/>
20+
);
21+
22+
const cards: ReadonlyArray<JSX.Element> = [
23+
createLandingCard("0"),
24+
createLandingCard("1"),
25+
createLandingCard("2"),
26+
createLandingCard("3")
27+
];
28+
29+
beforeEach(() => {
30+
jest.clearAllMocks();
31+
});
32+
33+
it("should track LOGIN_CAROUSEL_2 when index is 1", () => {
34+
trackCarousel(1, cards);
35+
expect(mixpanelTrack).toHaveBeenCalledWith(
36+
"LOGIN_CAROUSEL_2",
37+
expect.objectContaining({
38+
event_category: "UX",
39+
event_type: "screen_view"
40+
})
41+
);
42+
});
43+
44+
it("should track LOGIN_CAROUSEL_3 when index is 2", () => {
45+
trackCarousel(2, cards);
46+
expect(mixpanelTrack).toHaveBeenCalledWith(
47+
"LOGIN_CAROUSEL_3",
48+
expect.objectContaining({
49+
event_category: "UX",
50+
event_type: "screen_view"
51+
})
52+
);
53+
});
54+
55+
it("should track LOGIN_CAROUSEL_4 when index is 3", () => {
56+
trackCarousel(3, cards);
57+
expect(mixpanelTrack).toHaveBeenCalledWith(
58+
"LOGIN_CAROUSEL_4",
59+
expect.objectContaining({
60+
event_category: "UX",
61+
event_type: "screen_view"
62+
})
63+
);
64+
});
65+
66+
it("should not track if the component is not a LandingCardComponent", () => {
67+
const fakeCard = <Text key="fake">Fake</Text>;
68+
const fakeCards = [fakeCard, fakeCard, fakeCard];
69+
trackCarousel(0, fakeCards);
70+
expect(mixpanelTrack).not.toHaveBeenCalled();
71+
});
72+
});
Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
1+
import { mixpanelTrack } from "../../../../../mixpanel";
2+
import { buildEventProperties } from "../../../../../utils/analytics";
3+
import {
4+
trackLoginCiePinScreen,
5+
trackLoginCiePinInfo,
6+
trackLoginCieCardReaderScreen,
7+
trackLoginCieCardReadingSuccess,
8+
trackLoginCieConsentDataUsageScreen,
9+
trackLoginCieCardReadingError,
10+
trackLoginCieDataSharingError
11+
} from "../cieAnalytics";
12+
13+
jest.mock("../../../../../mixpanel", () => ({
14+
mixpanelTrack: jest.fn()
15+
}));
16+
17+
jest.mock("../../../../../utils/analytics", () => ({
18+
buildEventProperties: jest.fn()
19+
}));
20+
21+
describe("cieAnalytics", () => {
22+
beforeEach(() => {
23+
jest.clearAllMocks();
24+
});
25+
26+
it("tracks LOGIN_CIE_PIN screen view", () => {
27+
const mockProps = { mock: true };
28+
(buildEventProperties as jest.Mock).mockReturnValue(mockProps);
29+
trackLoginCiePinScreen();
30+
expect(mixpanelTrack).toHaveBeenCalledWith("LOGIN_CIE_PIN", mockProps);
31+
expect(buildEventProperties).toHaveBeenCalledWith("UX", "screen_view");
32+
});
33+
34+
it("tracks LOGIN_CIE_PIN_INFO action", () => {
35+
const mockProps = { mock: true };
36+
(buildEventProperties as jest.Mock).mockReturnValue(mockProps);
37+
trackLoginCiePinInfo();
38+
expect(mixpanelTrack).toHaveBeenCalledWith("LOGIN_CIE_PIN_INFO", mockProps);
39+
expect(buildEventProperties).toHaveBeenCalledWith("UX", "action");
40+
});
41+
42+
it("tracks LOGIN_CIE_CARD_READER screen view", () => {
43+
const mockProps = { mock: true };
44+
(buildEventProperties as jest.Mock).mockReturnValue(mockProps);
45+
trackLoginCieCardReaderScreen();
46+
expect(mixpanelTrack).toHaveBeenCalledWith(
47+
"LOGIN_CIE_CARD_READER",
48+
mockProps
49+
);
50+
expect(buildEventProperties).toHaveBeenCalledWith("UX", "screen_view");
51+
});
52+
53+
it("tracks LOGIN_CIE_CARD_READING_SUCCESS confirm", () => {
54+
const mockProps = { mock: true };
55+
(buildEventProperties as jest.Mock).mockReturnValue(mockProps);
56+
trackLoginCieCardReadingSuccess();
57+
expect(mixpanelTrack).toHaveBeenCalledWith(
58+
"LOGIN_CIE_CARD_READING_SUCCESS",
59+
mockProps
60+
);
61+
expect(buildEventProperties).toHaveBeenCalledWith("UX", "confirm");
62+
});
63+
64+
it("tracks LOGIN_CIE_CONSENT_DATA_USAGE screen view", () => {
65+
const mockProps = { mock: true };
66+
(buildEventProperties as jest.Mock).mockReturnValue(mockProps);
67+
trackLoginCieConsentDataUsageScreen();
68+
expect(mixpanelTrack).toHaveBeenCalledWith(
69+
"LOGIN_CIE_CONSENT_DATA_USAGE",
70+
mockProps
71+
);
72+
expect(buildEventProperties).toHaveBeenCalledWith("UX", "screen_view");
73+
});
74+
75+
it("tracks LOGIN_CIE_CARD_READING_ERROR with KO category", () => {
76+
const mockProps = { mock: true };
77+
(buildEventProperties as jest.Mock).mockReturnValue(mockProps);
78+
trackLoginCieCardReadingError();
79+
expect(mixpanelTrack).toHaveBeenCalledWith(
80+
"LOGIN_CIE_CARD_READING_ERROR",
81+
mockProps
82+
);
83+
expect(buildEventProperties).toHaveBeenCalledWith("KO", undefined);
84+
});
85+
86+
it("tracks LOGIN_CIE_DATA_SHARING_ERROR with KO category", () => {
87+
const mockProps = { mock: true };
88+
(buildEventProperties as jest.Mock).mockReturnValue(mockProps);
89+
trackLoginCieDataSharingError();
90+
expect(mixpanelTrack).toHaveBeenCalledWith(
91+
"LOGIN_CIE_DATA_SHARING_ERROR",
92+
mockProps
93+
);
94+
expect(buildEventProperties).toHaveBeenCalledWith("KO", undefined);
95+
});
96+
});

0 commit comments

Comments
 (0)