@constructor-io/constructorio-ui-quizzes 1.9.9 → 1.10.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (86) hide show
  1. package/README.md +2 -3
  2. package/dist/constructorio-ui-quizzes-bundled.js +14 -14
  3. package/lib/cjs/components/CioQuiz/actions.js +1 -0
  4. package/lib/cjs/components/CioQuiz/index.js +10 -6
  5. package/lib/cjs/components/CioQuiz/quizApiReducer.js +4 -1
  6. package/lib/cjs/components/ResultContainer/ResultContainer.js +25 -19
  7. package/lib/cjs/components/ShareButton/ShareButton.js +17 -0
  8. package/lib/cjs/components/ShareButton/ShareSVG.js +11 -0
  9. package/lib/cjs/components/ShareResultsModal/AlertCircleSVG.js +11 -0
  10. package/lib/cjs/components/ShareResultsModal/CheckMarkCircleSVG.js +10 -0
  11. package/lib/cjs/components/ShareResultsModal/CloseSVG.js +10 -0
  12. package/lib/cjs/components/ShareResultsModal/EmailField.js +50 -0
  13. package/lib/cjs/components/ShareResultsModal/LinkField.js +30 -0
  14. package/lib/cjs/components/ShareResultsModal/ShareResultsModal.js +24 -0
  15. package/lib/cjs/constants.js +3 -42
  16. package/lib/cjs/hooks/useConsoleErrors.js +4 -8
  17. package/lib/cjs/hooks/usePropsGetters/index.js +2 -0
  18. package/lib/cjs/hooks/useQueryParams.js +31 -0
  19. package/lib/cjs/hooks/useQuiz.js +3 -3
  20. package/lib/cjs/hooks/useQuizEvents/index.js +10 -5
  21. package/lib/cjs/hooks/useQuizEvents/useQuizResetClick.js +15 -2
  22. package/lib/cjs/hooks/useQuizState/useQuizApiState.js +27 -2
  23. package/lib/cjs/hooks/useShareResultsLink.js +18 -0
  24. package/lib/cjs/index.js +3 -1
  25. package/lib/cjs/services/index.js +3 -1
  26. package/lib/cjs/stories/Quiz/argTypes.js +258 -7
  27. package/lib/cjs/utils.js +1 -0
  28. package/lib/cjs/version.js +1 -1
  29. package/lib/mjs/components/CioQuiz/actions.js +1 -0
  30. package/lib/mjs/components/CioQuiz/index.js +10 -6
  31. package/lib/mjs/components/CioQuiz/quizApiReducer.js +9 -0
  32. package/lib/mjs/components/ResultContainer/ResultContainer.js +25 -19
  33. package/lib/mjs/components/ShareButton/ShareButton.js +14 -0
  34. package/lib/mjs/components/ShareButton/ShareSVG.js +7 -0
  35. package/lib/mjs/components/ShareResultsModal/AlertCircleSVG.js +7 -0
  36. package/lib/mjs/components/ShareResultsModal/CheckMarkCircleSVG.js +6 -0
  37. package/lib/mjs/components/ShareResultsModal/CloseSVG.js +6 -0
  38. package/lib/mjs/components/ShareResultsModal/EmailField.js +46 -0
  39. package/lib/mjs/components/ShareResultsModal/LinkField.js +26 -0
  40. package/lib/mjs/components/ShareResultsModal/ShareResultsModal.js +20 -0
  41. package/lib/mjs/constants.js +2 -41
  42. package/lib/mjs/hooks/useConsoleErrors.js +4 -8
  43. package/lib/mjs/hooks/usePropsGetters/index.js +2 -0
  44. package/lib/mjs/hooks/useQueryParams.js +29 -0
  45. package/lib/mjs/hooks/useQuiz.js +3 -3
  46. package/lib/mjs/hooks/useQuizEvents/index.js +10 -5
  47. package/lib/mjs/hooks/useQuizEvents/useQuizResetClick.js +14 -2
  48. package/lib/mjs/hooks/useQuizState/useQuizApiState.js +28 -3
  49. package/lib/mjs/hooks/useShareResultsLink.js +14 -0
  50. package/lib/mjs/index.js +1 -0
  51. package/lib/mjs/services/index.js +1 -0
  52. package/lib/mjs/stories/Quiz/argTypes.js +257 -6
  53. package/lib/mjs/utils.js +1 -0
  54. package/lib/mjs/version.js +1 -1
  55. package/lib/styles.css +194 -2
  56. package/lib/types/components/CioQuiz/actions.d.ts +7 -3
  57. package/lib/types/components/CioQuiz/context.d.ts +2 -1
  58. package/lib/types/components/CioQuiz/quizApiReducer.d.ts +2 -2
  59. package/lib/types/components/ResultCard/ResultCard.d.ts +2 -2
  60. package/lib/types/components/ResultContainer/ResultContainer.d.ts +5 -3
  61. package/lib/types/components/Results/Results.d.ts +2 -2
  62. package/lib/types/components/ShareButton/ShareButton.d.ts +7 -0
  63. package/lib/types/components/ShareButton/ShareSVG.d.ts +2 -0
  64. package/lib/types/components/ShareResultsModal/AlertCircleSVG.d.ts +2 -0
  65. package/lib/types/components/ShareResultsModal/CheckMarkCircleSVG.d.ts +2 -0
  66. package/lib/types/components/ShareResultsModal/CloseSVG.d.ts +2 -0
  67. package/lib/types/components/ShareResultsModal/EmailField.d.ts +6 -0
  68. package/lib/types/components/ShareResultsModal/LinkField.d.ts +6 -0
  69. package/lib/types/components/ShareResultsModal/ShareResultsModal.d.ts +9 -0
  70. package/lib/types/constants.d.ts +1 -5
  71. package/lib/types/hooks/usePropsGetters/index.d.ts +2 -1
  72. package/lib/types/hooks/useQueryParams.d.ts +7 -0
  73. package/lib/types/hooks/useQuizEvents/useQuizNextClick.d.ts +2 -2
  74. package/lib/types/hooks/useQuizEvents/useQuizResetClick.d.ts +9 -2
  75. package/lib/types/hooks/useQuizEvents/useQuizSkipClick.d.ts +2 -2
  76. package/lib/types/hooks/useShareResultsLink.d.ts +2 -0
  77. package/lib/types/index.d.ts +1 -0
  78. package/lib/types/services/index.d.ts +6 -5
  79. package/lib/types/stories/Quiz/argTypes.d.ts +253 -6
  80. package/lib/types/types.d.ts +32 -14
  81. package/lib/types/utils.d.ts +2 -1
  82. package/lib/types/version.d.ts +1 -1
  83. package/package.json +2 -2
  84. package/lib/cjs/stories/Quiz/tests/mocks.js +0 -170
  85. package/lib/mjs/stories/Quiz/tests/mocks.js +0 -198
  86. package/lib/types/stories/Quiz/tests/mocks.d.ts +0 -44
@@ -1,35 +1,282 @@
1
1
  export declare const argTypes: {
2
+ quizId: {
3
+ description: string;
4
+ control: {
5
+ type: string;
6
+ };
7
+ };
8
+ quizVersionId: {
9
+ description: string;
10
+ };
2
11
  apiKey: {
3
- type: {
4
- name: string;
12
+ description: string;
13
+ };
14
+ 'callbacks.onQuizNextQuestion': {
15
+ description: string;
16
+ control: boolean;
17
+ table: {
18
+ subcategory: string;
19
+ defaultValue: {
20
+ summary: string;
21
+ };
22
+ type: {
23
+ summary: string;
24
+ detail: string;
25
+ };
26
+ };
27
+ };
28
+ 'callbacks.onQuizResultsLoaded': {
29
+ description: string;
30
+ control: boolean;
31
+ table: {
32
+ subcategory: string;
33
+ defaultValue: {
34
+ summary: string;
35
+ };
36
+ type: {
37
+ summary: string;
38
+ detail: string;
39
+ };
40
+ };
41
+ };
42
+ 'callbacks.onQuizResultClick': {
43
+ description: string;
44
+ control: boolean;
45
+ table: {
46
+ subcategory: string;
47
+ defaultValue: {
48
+ summary: string;
49
+ };
50
+ type: {
51
+ summary: string;
52
+ detail: string;
53
+ };
5
54
  };
55
+ };
56
+ 'callbacks.onAddToCartClick': {
6
57
  description: string;
58
+ control: boolean;
7
59
  table: {
60
+ subcategory: string;
61
+ defaultValue: {
62
+ summary: string;
63
+ };
8
64
  type: {
9
65
  summary: string;
66
+ detail: string;
10
67
  };
11
68
  };
69
+ };
70
+ 'callbacks.onAddToFavoritesClick': {
71
+ description: string;
72
+ control: boolean;
73
+ table: {
74
+ subcategory: string;
75
+ defaultValue: {
76
+ summary: string;
77
+ };
78
+ type: {
79
+ summary: string;
80
+ detail: string;
81
+ };
82
+ };
83
+ };
84
+ 'callbacks.onEmailResults': {
85
+ description: string;
86
+ control: boolean;
87
+ table: {
88
+ subcategory: string;
89
+ defaultValue: {
90
+ summary: string;
91
+ };
92
+ type: {
93
+ summary: string;
94
+ detail: string;
95
+ };
96
+ };
97
+ };
98
+ cioJsClient: {
99
+ description: string;
100
+ };
101
+ primaryColor: {
102
+ description: string;
12
103
  control: {
13
104
  type: string;
14
105
  };
106
+ defaultValue: {
107
+ summary: string;
108
+ };
15
109
  };
16
- quizId: {
17
- type: {
18
- name: string;
110
+ 'resultCardOptions.resultCardRegularPriceKey': {
111
+ description: string;
112
+ control: {
113
+ type: string;
114
+ };
115
+ table: {
116
+ subcategory: string;
117
+ defaultValue: {
118
+ summary: string;
119
+ };
120
+ type: {
121
+ summary: string;
122
+ };
123
+ };
124
+ };
125
+ 'resultCardOptions.resultCardSalePriceKey': {
126
+ description: string;
127
+ control: {
128
+ type: string;
129
+ };
130
+ table: {
131
+ subcategory: string;
132
+ defaultValue: {
133
+ summary: string;
134
+ };
135
+ type: {
136
+ summary: string;
137
+ };
138
+ };
139
+ };
140
+ 'resultCardOptions.resultCardRatingCountKey': {
141
+ description: string;
142
+ control: {
143
+ type: string;
144
+ };
145
+ table: {
146
+ subcategory: string;
147
+ defaultValue: {
148
+ summary: string;
149
+ };
150
+ type: {
151
+ summary: string;
152
+ };
153
+ };
154
+ };
155
+ 'resultCardOptions.resultCardRatingScoreKey': {
156
+ description: string;
157
+ control: {
158
+ type: string;
159
+ };
160
+ table: {
161
+ subcategory: string;
162
+ defaultValue: {
163
+ summary: string;
164
+ };
165
+ type: {
166
+ summary: string;
167
+ };
19
168
  };
169
+ };
170
+ 'resultCardOptions.renderResultCardPriceDetails': {
20
171
  description: string;
172
+ control: boolean;
21
173
  table: {
174
+ subcategory: string;
175
+ defaultValue: {
176
+ summary: string;
177
+ };
22
178
  type: {
23
179
  summary: string;
180
+ detail: string;
24
181
  };
25
182
  };
183
+ };
184
+ 'resultsPageOptions.numResultsToDisplay': {
185
+ description: string;
26
186
  control: {
27
187
  type: string;
28
188
  };
189
+ table: {
190
+ subcategory: string;
191
+ defaultValue: {
192
+ summary: number;
193
+ };
194
+ type: {
195
+ summary: string;
196
+ };
197
+ };
29
198
  };
30
- primaryColor: {
199
+ 'resultsPageOptions.favoriteItems': {
200
+ description: string;
201
+ control: boolean;
202
+ table: {
203
+ subcategory: string;
204
+ type: {
205
+ summary: string;
206
+ };
207
+ };
208
+ };
209
+ 'resultsPageOptions.showShareResultsButton': {
210
+ description: string;
31
211
  control: {
32
212
  type: string;
33
213
  };
214
+ table: {
215
+ subcategory: string;
216
+ defaultValue: {
217
+ summary: boolean;
218
+ };
219
+ type: {
220
+ summary: string;
221
+ };
222
+ };
223
+ };
224
+ 'sessionStateOptions.showSessionModal': {
225
+ description: string;
226
+ control: {
227
+ type: string;
228
+ };
229
+ table: {
230
+ subcategory: string;
231
+ defaultValue: {
232
+ summary: boolean;
233
+ };
234
+ type: {
235
+ summary: string;
236
+ };
237
+ };
34
238
  };
239
+ 'sessionStateOptions.showSessionModalOnResults': {
240
+ description: string;
241
+ control: {
242
+ type: string;
243
+ };
244
+ table: {
245
+ subcategory: string;
246
+ defaultValue: {
247
+ summary: boolean;
248
+ };
249
+ type: {
250
+ summary: string;
251
+ };
252
+ };
253
+ };
254
+ 'sessionStateOptions.sessionStateKey': {
255
+ description: string;
256
+ control: {
257
+ type: string;
258
+ };
259
+ table: {
260
+ subcategory: string;
261
+ defaultValue: {
262
+ summary: string;
263
+ };
264
+ type: {
265
+ summary: string;
266
+ };
267
+ };
268
+ };
269
+ enableHydration: {
270
+ description: string;
271
+ defaultValue: {
272
+ summary: string;
273
+ };
274
+ };
275
+ };
276
+ export declare const docsControls: {
277
+ sort: string;
278
+ exclude: string[];
279
+ };
280
+ export declare const storiesControls: {
281
+ include: string[];
35
282
  };
@@ -1,11 +1,15 @@
1
- /// <reference types="react" />
1
+ import { CSSProperties } from 'react';
2
2
  import { QuizResultData, NextQuestionResponse, QuizResultsResponse, QuestionOption, Question } from '@constructor-io/constructorio-client-javascript/lib/types';
3
- import ConstructorIOClient from '@constructor-io/constructorio-client-javascript';
3
+ import ConstructorIOClient, { GetBrowseResultsForItemIdsResponse } from '@constructor-io/constructorio-client-javascript';
4
4
  import { RequestStates } from './constants';
5
5
  import { QuestionTypes } from './components/CioQuiz/actions';
6
6
  export type { QuestionOption, QuestionImages, Question, NextQuestionResponse, QuizResultsResponse, BrowseResultData, BrowseRequestType, QuizzesParameters, QuizzesResultsParameters, } from '@constructor-io/constructorio-client-javascript/lib/types';
7
7
  export type QuizResultDataPartial = Partial<QuizResultData>;
8
- export interface ResultCardProps {
8
+ export type QuizEmailResults = {
9
+ email: string;
10
+ url: string;
11
+ };
12
+ export interface ResultCardOptions {
9
13
  resultCardSalePriceKey?: string;
10
14
  resultCardRegularPriceKey?: string;
11
15
  resultCardRatingCountKey?: string;
@@ -17,14 +21,14 @@ export declare namespace QuizResultsEventsProps {
17
21
  type OnQuizResultClick = (result: QuizResultDataPartial, position: number) => void;
18
22
  type OnAddToCartClick = (result: QuizResultDataPartial) => void;
19
23
  type OnAddToFavoritesClick = (result: QuizResultDataPartial) => void;
24
+ type OnQuizNextQuestion = (question: QuestionWithAnswer) => void;
25
+ type OnQuizSkipQuestion = (question: QuestionWithAnswer) => void;
26
+ type OnEmailResults = (data: QuizEmailResults) => Promise<void>;
20
27
  }
21
- export interface ResultsPageOptions extends ResultCardProps {
28
+ export interface ResultsPageOptions {
22
29
  numResultsToDisplay?: number;
23
30
  favoriteItems?: string[];
24
- onQuizResultsLoaded?: QuizResultsEventsProps.OnQuizResultsLoaded;
25
- onQuizResultClick?: QuizResultsEventsProps.OnQuizResultClick;
26
- onAddToCartClick: QuizResultsEventsProps.OnAddToCartClick;
27
- onAddToFavoritesClick?: QuizResultsEventsProps.OnAddToFavoritesClick;
31
+ showShareResultsButton?: boolean;
28
32
  }
29
33
  export interface QuestionsPageOptions {
30
34
  skipQuestionButtonText?: string;
@@ -37,18 +41,22 @@ export interface SessionStateOptions {
37
41
  export type QuestionWithAnswer = Question & {
38
42
  answer: AnswerInput;
39
43
  };
40
- export type OnQuizNextQuestion = (question: QuestionWithAnswer) => void;
41
- export type OnQuizSkipQuestion = (question: QuestionWithAnswer) => void;
42
44
  export interface Callbacks {
43
- onQuizNextQuestion?: OnQuizNextQuestion;
44
- onQuizSkipQuestion?: OnQuizSkipQuestion;
45
+ onQuizNextQuestion?: QuizResultsEventsProps.OnQuizNextQuestion;
46
+ onQuizResultsLoaded?: QuizResultsEventsProps.OnQuizResultsLoaded;
47
+ onQuizResultClick?: QuizResultsEventsProps.OnQuizResultClick;
48
+ onAddToCartClick: QuizResultsEventsProps.OnAddToCartClick;
49
+ onAddToFavoritesClick?: QuizResultsEventsProps.OnAddToFavoritesClick;
50
+ onQuizSkipQuestion?: QuizResultsEventsProps.OnQuizSkipQuestion;
51
+ onEmailResults?: QuizResultsEventsProps.OnEmailResults;
45
52
  }
46
53
  export interface IQuizProps {
47
54
  apiKey?: string;
48
55
  cioJsClient?: ConstructorIOClient;
49
56
  quizId: string;
50
57
  quizVersionId?: string;
51
- resultsPageOptions: ResultsPageOptions;
58
+ resultsPageOptions?: ResultsPageOptions;
59
+ resultCardOptions?: ResultCardOptions;
52
60
  sessionStateOptions?: SessionStateOptions;
53
61
  primaryColor?: string;
54
62
  enableHydration?: boolean;
@@ -64,7 +72,7 @@ export interface QuizReturnState {
64
72
  versionId?: string;
65
73
  sessionId?: string;
66
74
  currentQuestion?: CurrentQuestion | undefined;
67
- results?: QuizResultsResponse | undefined;
75
+ results?: QuizResultsResponse | QuizSharedResultsData | undefined;
68
76
  selectedOptionsWithAttributes?: string[];
69
77
  };
70
78
  quizSessionStorageState: QuizSessionStorageState;
@@ -121,6 +129,9 @@ export interface OpenTextInputProps {
121
129
  onChange: React.ChangeEventHandler<HTMLInputElement>;
122
130
  onKeyDown: React.KeyboardEventHandler<HTMLInputElement>;
123
131
  }
132
+ export interface QuizSharedResultsData extends GetBrowseResultsForItemIdsResponse {
133
+ attributes: string[];
134
+ }
124
135
  export interface CoverQuestionProps {
125
136
  }
126
137
  export interface NextQuestionButtonProps {
@@ -147,6 +158,11 @@ export interface ResetQuizButtonProps {
147
158
  onClick: React.MouseEventHandler<HTMLElement>;
148
159
  style?: Record<string, string>;
149
160
  }
161
+ export interface ShareResultsButtonProps {
162
+ className: string;
163
+ onClick?: React.MouseEventHandler<HTMLElement>;
164
+ style?: CSSProperties;
165
+ }
150
166
  export interface HydrateQuizButtonProps {
151
167
  className: string;
152
168
  type: 'submit' | 'reset' | 'button' | undefined;
@@ -192,6 +208,7 @@ export type GetNextQuestionButtonProps = () => NextQuestionButtonProps;
192
208
  export type GetSkipQuestionButtonProps = () => SkipQuestionButtonProps;
193
209
  export type GetPreviousQuestionButtonProps = () => PreviousQuestionButtonProps;
194
210
  export type GetResetQuizButtonProps = (stylesType?: 'primary' | 'secondary') => ResetQuizButtonProps;
211
+ export type GetShareResultsButtonProps = () => ShareResultsButtonProps;
195
212
  export type GetHydrateQuizButtonProps = () => HydrateQuizButtonProps;
196
213
  export type GetAddToCartButtonProps = (result: QuizResultDataPartial, price?: number) => AddToCartButtonProps;
197
214
  export type GetAddToFavoritesButtonProps = (result: QuizResultDataPartial, price?: number, clickHandler?: () => void) => AddToCartButtonProps;
@@ -222,6 +239,7 @@ export interface UseQuizReturn {
222
239
  getSelectInputProps: GetSelectInputProps;
223
240
  getCoverQuestionProps: GetCoverQuestionProps;
224
241
  getResetQuizButtonProps: GetResetQuizButtonProps;
242
+ getShareResultsButtonProps: GetShareResultsButtonProps;
225
243
  getHydrateQuizButtonProps: GetHydrateQuizButtonProps;
226
244
  getAddToCartButtonProps: GetAddToCartButtonProps;
227
245
  getAddToFavoritesButtonProps: GetAddToFavoritesButtonProps;
@@ -19,11 +19,12 @@ export declare const functionStrings: {
19
19
  onQuizResultsLoaded: string;
20
20
  onQuizNextQuestion: string;
21
21
  onQuizSkipQuestion: string;
22
+ onEmailResults: string;
22
23
  cioJsClient: string;
23
24
  };
24
25
  export declare const stringifyWithDefaults: (obj: {
25
26
  cioJsClient?: any;
26
- resultsPageOptions: {
27
+ callbacks: {
27
28
  onAddToCartClick: any;
28
29
  onQuizResultClick: any;
29
30
  onQuizResultsLoaded: any;
@@ -1,2 +1,2 @@
1
- declare const _default: "1.9.7";
1
+ declare const _default: "1.10.0";
2
2
  export default _default;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@constructor-io/constructorio-ui-quizzes",
3
- "version": "1.9.9",
3
+ "version": "1.10.0",
4
4
  "description": "Constructor.io Quizzes UI library for web applications",
5
5
  "author": "constructor.io",
6
6
  "license": "MIT",
@@ -69,10 +69,10 @@
69
69
  "@cspell/eslint-plugin": "^6.18.1",
70
70
  "@storybook/addon-a11y": "^7.4.6",
71
71
  "@storybook/addon-actions": "7.4.6",
72
+ "@storybook/addon-docs": "7.4.6",
72
73
  "@storybook/addon-essentials": "7.4.6",
73
74
  "@storybook/addon-interactions": "^7.4.6",
74
75
  "@storybook/addon-links": "7.4.6",
75
- "@storybook/addon-docs": "7.4.6",
76
76
  "@storybook/jest": "^0.2.3",
77
77
  "@storybook/react-webpack5": "7.4.6",
78
78
  "@storybook/test-runner": "0.13.0",
@@ -1,170 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.useMockContextValue = exports.getMockState = exports.questionOptions = exports.questionOptionsWithImages = exports.getMockQuestionWithImage = exports.getMockQuestion = void 0;
4
- const tslib_1 = require("tslib");
5
- const constants_1 = require("../../../constants");
6
- const useOpenTextInputProps_1 = tslib_1.__importDefault(require("../../../hooks/usePropsGetters/useOpenTextInputProps"));
7
- const useCoverQuestionProps_1 = tslib_1.__importDefault(require("../../../hooks/usePropsGetters/useCoverQuestionProps"));
8
- const useSelectInputProps_1 = tslib_1.__importDefault(require("../../../hooks/usePropsGetters/useSelectInputProps"));
9
- const getMockQuestion = (type) => ({
10
- id: 1,
11
- title: 'This is question title',
12
- description: 'This is question description',
13
- cta_text: 'Continue',
14
- type,
15
- input_placeholder: 'Answer here...',
16
- });
17
- exports.getMockQuestion = getMockQuestion;
18
- const getMockImages = () => ({
19
- images: {
20
- primary_url: 'https://demo.constructor.io/sandbox_files/farmstandquizassets/HiThereNameInput.png',
21
- },
22
- });
23
- const getMockQuestionWithImage = (type) => (Object.assign(Object.assign({}, (0, exports.getMockQuestion)(type)), getMockImages()));
24
- exports.getMockQuestionWithImage = getMockQuestionWithImage;
25
- const getMockOption = (id, value) => ({
26
- id,
27
- value,
28
- attribute: {
29
- name: value,
30
- value,
31
- },
32
- });
33
- const getMockOptionWithImage = (id, value) => (Object.assign(Object.assign({}, getMockOption(id, value)), getMockImages()));
34
- exports.questionOptionsWithImages = [
35
- Object.assign({}, getMockOptionWithImage(0, 'coffee')),
36
- Object.assign({}, getMockOptionWithImage(1, 'tea')),
37
- Object.assign({}, getMockOptionWithImage(2, 'water')),
38
- ];
39
- exports.questionOptions = [
40
- Object.assign({}, getMockOption(0, 'coffee')),
41
- Object.assign({}, getMockOption(1, 'tea')),
42
- Object.assign({}, getMockOption(2, 'water')),
43
- ];
44
- const getMockState = (question) => ({
45
- answers: {
46
- inputs: {
47
- 1: {
48
- type: question === null || question === void 0 ? void 0 : question.type,
49
- value: '',
50
- },
51
- }, // Key is the question Id and value is the answer input
52
- },
53
- quiz: {
54
- requestState: constants_1.RequestStates.Success,
55
- versionId: '',
56
- sessionId: '',
57
- currentQuestion: {
58
- next_question: question,
59
- isFirstQuestion: false,
60
- isOpenQuestion: (question === null || question === void 0 ? void 0 : question.type) === 'open',
61
- isCoverQuestion: (question === null || question === void 0 ? void 0 : question.type) === 'cover',
62
- isSingleQuestion: (question === null || question === void 0 ? void 0 : question.type) === 'single',
63
- isMultipleQuestion: (question === null || question === void 0 ? void 0 : question.type) === 'multiple',
64
- isSelectQuestion: (question === null || question === void 0 ? void 0 : question.type) === 'single',
65
- total_questions: 1,
66
- },
67
- results: {
68
- response: {
69
- results: [
70
- {
71
- value: 'This is a result card item',
72
- data: {
73
- id: '0',
74
- price: 100,
75
- ratingCount: '12',
76
- ratingScore: '4',
77
- image_url: 'https://demo.constructor.io/sandbox_files/farmstandquizassets/HiThereNameInput.png',
78
- discount: '59.9',
79
- },
80
- },
81
- {
82
- value: 'This is a result card item',
83
- data: {
84
- id: '1',
85
- price: 200,
86
- salePrice: 150,
87
- ratingCount: '6',
88
- ratingScore: '3',
89
- image_url: 'https://demo.constructor.io/sandbox_files/farmstandquizassets/HiThereNameInput.png',
90
- },
91
- },
92
- {
93
- value: 'This is a result card item',
94
- data: {
95
- id: '2',
96
- price: 300,
97
- salePrice: 250,
98
- ratingCount: '2',
99
- ratingScore: '5',
100
- image_url: 'https://demo.constructor.io/sandbox_files/farmstandquizassets/HiThereNameInput.png',
101
- },
102
- },
103
- ],
104
- facets: [],
105
- groups: [],
106
- sort_options: [],
107
- refined_content: [],
108
- total_num_results: 10,
109
- features: [],
110
- result_sources: {},
111
- },
112
- quiz_id: '',
113
- quiz_session_id: '',
114
- quiz_version_id: '',
115
- quiz_selected_options: [
116
- { value: 'Chocolate', has_attribute: true },
117
- { value: 'Medium', has_attribute: true },
118
- ],
119
- },
120
- selectedOptionsWithAttributes: ['Chocolate', 'Medium'],
121
- },
122
- quizSessionStorageState: {
123
- key: constants_1.quizSessionStateKey,
124
- skipToResults: true,
125
- hasSessionStorageState: () => true,
126
- },
127
- });
128
- exports.getMockState = getMockState;
129
- const mockElementProps = {
130
- className: '',
131
- type: 'submit',
132
- onClick: () => { },
133
- onChange: () => { },
134
- onKeyDown: () => { },
135
- role: 'button',
136
- tabIndex: 0,
137
- key: 0,
138
- style: {},
139
- placeholder: '',
140
- value: '',
141
- };
142
- const useMockContextValue = (question) => {
143
- const getOpenTextInputProps = (0, useOpenTextInputProps_1.default)(() => { }, () => { }, question);
144
- const getCoverQuestionProps = (0, useCoverQuestionProps_1.default)(() => { }, question);
145
- const getSelectInputProps = (0, useSelectInputProps_1.default)(() => { }, () => { }, question);
146
- return {
147
- state: (0, exports.getMockState)(question),
148
- getCoverQuestionProps,
149
- getOpenTextInputProps,
150
- getSelectInputProps,
151
- getAddToCartButtonProps: () => (Object.assign(Object.assign({}, mockElementProps), { className: 'cio-result-card-cta-button' })),
152
- getAddToFavoritesButtonProps: () => (Object.assign(Object.assign({}, mockElementProps), { className: 'cio-result-card-favorites-button' })),
153
- getHydrateQuizButtonProps: () => (Object.assign(Object.assign({}, mockElementProps), { className: 'cio-question-cta-button' })),
154
- getNextQuestionButtonProps: () => (Object.assign(Object.assign({}, mockElementProps), { className: 'cio-question-cta-button' })),
155
- getSkipQuestionButtonProps: () => (Object.assign(Object.assign({}, mockElementProps), { className: 'cio-question-skip-button' })),
156
- getPreviousQuestionButtonProps: () => (Object.assign(Object.assign({}, mockElementProps), { className: 'cio-question-back-button' })),
157
- getQuizImageProps: () => mockElementProps,
158
- getQuizResultButtonProps: () => mockElementProps,
159
- getQuizResultLinkProps: () => mockElementProps,
160
- getResetQuizButtonProps: () => (Object.assign(Object.assign({}, mockElementProps), { className: 'cio-question-redo-button' })),
161
- primaryColorStyles: {
162
- '--primary-color-h': '12',
163
- '--primary-color-s': '14',
164
- '--primary-color-l': '14',
165
- },
166
- customClickItemCallback: false,
167
- customAddToFavoritesCallback: true,
168
- };
169
- };
170
- exports.useMockContextValue = useMockContextValue;