Skip to content

Commit 3175c0e

Browse files
stanlp1esezen
andauthored
[CI-4062] Make callbacks prop required (#217)
* make callbacks required * fix tests * Use ts-expect-error declaration Co-authored-by: Enes Kutay SEZEN <[email protected]> * ts-expect-error declaration --------- Co-authored-by: Enes Kutay SEZEN <[email protected]>
1 parent 0827150 commit 3175c0e

File tree

8 files changed

+17
-10
lines changed

8 files changed

+17
-10
lines changed

cspell.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
"Favorited",
1919
"favorited",
2020
"Skippable",
21-
"cnstrc"
21+
"cnstrc",
22+
"nocheck"
2223
]
2324
}

spec/hooks/useConsoleErrors/useConsoleErrors.test.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,8 @@ describe('Testing Hook (client): useConsoleErrors', () => {
2121
});
2222

2323
it('logs error if onAddToCartClick is missing', () => {
24-
const quizOptions = { quizId: QUIZ_ID };
24+
const quizOptions = { quizId: QUIZ_ID, callbacks: {} };
25+
// @ts-expect-error Testing the error itself
2526
renderHook(() => useConsoleErrors(quizOptions));
2627

2728
expect(console.error).toHaveBeenCalledWith(

spec/hooks/useQuizState/useQuizApiState/useQuizApiState.server.test.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ describe('useQuizApiState - Server', () => {
2121
const quizOptions = {
2222
quizId: QUIZ_ID,
2323
quizVersionId: QUIZ_VERSION_ID,
24+
callbacks: { onAddToCartClick: () => {}},
2425
resultsPageOptions: {},
2526
};
2627
const quizLocalState = {

spec/hooks/useQuizState/useQuizApiState/useQuizApiState.test.tsx

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,13 @@ jest.mock('../../../../src/services', () => ({
1818
}));
1919

2020
describe('Testing Hook (client): useQuizApiState', () => {
21+
const quizOptions = {
22+
quizId: QUIZ_ID,
23+
quizVersionId: QUIZ_VERSION_ID,
24+
callbacks: { onAddToCartClick: () => {} },
25+
resultsPageOptions: {},
26+
};
27+
2128
(getQuizResults as jest.Mock).mockResolvedValue({
2229
quiz_selected_options: [
2330
{ has_attribute: true, value: 'option1' },
@@ -26,7 +33,6 @@ describe('Testing Hook (client): useQuizApiState', () => {
2633
});
2734

2835
it('executes quiz flow correctly', async () => {
29-
const quizOptions = { quizId: QUIZ_ID, quizVersionId: QUIZ_VERSION_ID, resultsPageOptions: {} };
3036
const quizLocalState = {
3137
answers: [],
3238
answerInputs: {},
@@ -67,7 +73,6 @@ describe('Testing Hook (client): useQuizApiState', () => {
6773
});
6874

6975
it('sets loading state correctly around async operations', async () => {
70-
const quizOptions = { quizId: QUIZ_ID, quizVersionId: QUIZ_VERSION_ID, resultsPageOptions: {} };
7176
const quizLocalState = {
7277
answers: [],
7378
answerInputs: {},
@@ -93,7 +98,6 @@ describe('Testing Hook (client): useQuizApiState', () => {
9398
});
9499

95100
it('dispatches quiz results upon completion', async () => {
96-
const quizOptions = { quizId: QUIZ_ID, quizVersionId: QUIZ_VERSION_ID, resultsPageOptions: {} };
97101
const quizLocalState = {
98102
answers: [['1']],
99103
isQuizCompleted: true,

src/stories/Quiz/Component/Props.mdx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,6 @@ import * as ComponentStories from './ComponentStories.stories';
55
<Meta of={ComponentStories} />
66

77
## Quiz Component Props
8-
<p>The props below are available to customize the quiz component. The `quizId` and `apiKey` or `cioJsClient` are required props.</p>
8+
<p>The props below are available to customize the quiz component. The `quizId` and `apiKey` or `cioJsClient` and `callbacks.onAddToCartClick` are required props.</p>
99

10-
<ArgTypes of={e2eInteractionTest} />
10+
<ArgTypes of={e2eInteractionTest} />

src/stories/Quiz/Hooks/Docs/Props.mdx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,6 @@ import * as HooksStories from '../HooksStories.stories';
55
<Meta of={HooksStories} />
66

77
## useCioQuiz Props
8-
<p>The props below are available to customize the quiz component. The `quizId` and `apiKey` or `cioJsClient` are required props.</p>
8+
<p>The props below are available to customize the quiz component. The `quizId` and `apiKey` or `cioJsClient` and `callbacks.onAddToCartClick` are required props.</p>
99

1010
<ArgTypes of={e2eInteractionTest} />

src/stories/Quiz/argTypes.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ export const argTypes = {
5555
},
5656
},
5757
'callbacks.onAddToCartClick': {
58-
description: 'Callback function to be called when the add to cart button is clicked',
58+
description: 'Callback function to be called when the add to cart button is clicked. Required',
5959
control: false,
6060
table: {
6161
subcategory: 'callbacks',

src/types.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ export interface IQuizProps {
115115
sessionStateOptions?: SessionStateOptions;
116116
primaryColor?: string;
117117
enableHydration?: boolean;
118-
callbacks?: Callbacks;
118+
callbacks: Callbacks;
119119
questionsPageOptions?: QuestionsPageOptions;
120120
}
121121

0 commit comments

Comments
 (0)