freemium-survey-components 0.10.37 → 0.10.40

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.
@@ -0,0 +1,67 @@
1
+ /// <reference types="cypress" />
2
+ import { mockSurvey, mockPlaceholders } from '../fixtures/mock'
3
+ import { sanitiseQuestion } from '../../src/survey/utils'
4
+ const getQuestionText = (htmlText: string) => {
5
+ const text = htmlText.replace(/<[^>]+>/g, '')
6
+ return sanitiseQuestion(text, mockPlaceholders, null)
7
+ }
8
+ const { questions } = mockSurvey.question_details
9
+ describe('load', () => {
10
+ it('visit page', () => {
11
+ cy.visit({
12
+ url: `http://localhost:6006/iframe.html?id=test-survey--card-survey&args=&viewMode=story`,
13
+ })
14
+ })
15
+ })
16
+ describe('renders nps question', () => {
17
+ it('mounts nps question', () => {
18
+ cy.contains(getQuestionText(questions[0].text))
19
+ })
20
+ it('check min max validation', () => {
21
+ cy.get('[data-test-nps-choice]')
22
+ .first()
23
+ .contains(questions[0].type_info.validation.min.toString())
24
+ cy.get('[data-test-nps-choice]')
25
+ .last()
26
+ .contains(questions[0].type_info.validation.max.toString())
27
+ })
28
+
29
+ describe('test detractor Range', () => {
30
+ beforeEach(() => {
31
+ cy.reload()
32
+ })
33
+ afterEach(() => {
34
+ const expectedNextQuestion = questions.find(
35
+ (question) => question.name === 'Q_22',
36
+ )
37
+ cy.get('[data-test-question-name="Q_22').contains(
38
+ getQuestionText(expectedNextQuestion.text),
39
+ )
40
+ })
41
+ it('navigate to next based_on_rating question (detractor min)', () => {
42
+ const detractorRange = questions[0].type_info.meta.branches.find(
43
+ (each) => each.id === 'detractor',
44
+ )
45
+ cy.get(`[data-test-nps-choice="${detractorRange.min}"]`).click()
46
+ })
47
+ it('navigate to next based_on_rating question (detractor max)', () => {
48
+ const detractorRange = questions[0].type_info.meta.branches.find(
49
+ (each) => each.id === 'detractor',
50
+ )
51
+ cy.get(`[data-test-nps-choice="${detractorRange.max}"]`).click()
52
+ })
53
+ it('navigate to next based_on_rating question (detractor min < random < max )', () => {
54
+ const detractorRange = questions[0].type_info.meta.branches.find(
55
+ (each) => each.id === 'detractor',
56
+ )
57
+ cy.get(
58
+ `[data-test-nps-choice="${Math.ceil(
59
+ Math.random() * (detractorRange.max - detractorRange.min) +
60
+ detractorRange.min,
61
+ )}"]`,
62
+ ).click()
63
+ })
64
+ })
65
+ // it('navigate to next based_on_rating question (passive)', () => {})
66
+ // it('navigate to next based_on_rating question (promoter)', () => {})
67
+ })
@@ -0,0 +1,317 @@
1
+ export const mockSurvey = {
2
+ name: 'Hello',
3
+ desc: '',
4
+ type: 'NPS',
5
+ state: 'DRAFT',
6
+ is_template: false,
7
+ question_details: {
8
+ questions: [
9
+ {
10
+ id: '45cc1a3c-8f28-41f9-88f1-144a57322eee',
11
+ text: '<p>How likely are you to recommend <span class="placeholder-tag"><span contenteditable="false">{{account.company_name}}</span></span> to your colleagues or professional network?</p>',
12
+ name: 'Q_1',
13
+ position: 1,
14
+ required: false,
15
+ type_info: {
16
+ comment: false,
17
+ driver: false,
18
+ question_type: 'RANGE',
19
+ validation: {
20
+ min: 1,
21
+ max: 10,
22
+ },
23
+ linear_scale: {
24
+ point_scale: null,
25
+ scale_order: null,
26
+ button_style: 'highlighted',
27
+ button_shape: 'rounded',
28
+ },
29
+ rating_presets: {
30
+ start: 'Very unlikely',
31
+ end: 'Very likely',
32
+ },
33
+ choices: [
34
+ {
35
+ position: '1',
36
+ value: '1',
37
+ dependent_question_names: ['Q_22', 'TY_02'],
38
+ },
39
+ {
40
+ position: '2',
41
+ value: '2',
42
+ dependent_question_names: ['Q_22', 'TY_02'],
43
+ },
44
+ {
45
+ position: '3',
46
+ value: '3',
47
+ dependent_question_names: ['Q_22', 'TY_02'],
48
+ },
49
+ {
50
+ position: '4',
51
+ value: '4',
52
+ dependent_question_names: ['Q_22', 'TY_02'],
53
+ },
54
+ {
55
+ position: '5',
56
+ value: '5',
57
+ dependent_question_names: ['Q_22', 'TY_02'],
58
+ },
59
+ {
60
+ position: '6',
61
+ value: '6',
62
+ dependent_question_names: ['Q_22', 'TY_02'],
63
+ },
64
+ {
65
+ position: '7',
66
+ value: '7',
67
+ dependent_question_names: ['Q_21', 'TY_01'],
68
+ },
69
+ {
70
+ position: '8',
71
+ value: '8',
72
+ dependent_question_names: ['Q_21', 'TY_01'],
73
+ },
74
+ {
75
+ position: '9',
76
+ value: '9',
77
+ dependent_question_names: ['Q_20', 'TY_0'],
78
+ },
79
+ {
80
+ position: '10',
81
+ value: '10',
82
+ dependent_question_names: ['Q_20', 'TY_0'],
83
+ },
84
+ ],
85
+ footer_text: 'We look forward to your feedback.',
86
+ meta: {
87
+ block: {
88
+ name: 'NPS',
89
+ title: 'NPS',
90
+ is_based_on_rating: false,
91
+ },
92
+ branches: [
93
+ {
94
+ min: 1,
95
+ max: 6,
96
+ id: 'detractor',
97
+ },
98
+ {
99
+ min: 7,
100
+ max: 8,
101
+ id: 'passive',
102
+ },
103
+ {
104
+ min: 9,
105
+ max: 10,
106
+ id: 'promoter',
107
+ },
108
+ ],
109
+ branchType: 'logic',
110
+ },
111
+ pivot_question: true,
112
+ },
113
+ },
114
+ {
115
+ id: '22413e27-9225-49cc-9620-55d2c43eda23',
116
+ text: '<p>Wow! You made our day. Thank you for giving us a <span class="placeholder-tag"><span contenteditable="false">{{nps.rating}}</span></span>. Please tell us what you liked the most.</p>',
117
+ name: 'Q_20',
118
+ position: 2,
119
+ required: false,
120
+ type_info: {
121
+ comment: false,
122
+ driver: false,
123
+ question_type: 'PARAGRAPH',
124
+ validation: null,
125
+ linear_scale: null,
126
+ rating_presets: null,
127
+ choices: null,
128
+ footer_text: null,
129
+ meta: {
130
+ block: {
131
+ name: 'B_2',
132
+ title: 'Q2',
133
+ is_based_on_rating: true,
134
+ question_names: ['Q_20', 'Q_21', 'Q_22'],
135
+ },
136
+ },
137
+ pivot_question: false,
138
+ },
139
+ },
140
+ {
141
+ id: 'c391f15b-6a09-4711-8887-8675623c1557',
142
+ text: '<p>Thank you for giving us a <span class="placeholder-tag"><span contenteditable="false">{{nps.rating}}</span></span>. Do you see any areas where we could improve?</p>',
143
+ name: 'Q_21',
144
+ position: 3,
145
+ required: false,
146
+ type_info: {
147
+ comment: false,
148
+ driver: false,
149
+ question_type: 'PARAGRAPH',
150
+ validation: null,
151
+ linear_scale: null,
152
+ rating_presets: null,
153
+ choices: null,
154
+ footer_text: null,
155
+ meta: null,
156
+ pivot_question: false,
157
+ },
158
+ },
159
+ {
160
+ id: 'a39e9193-ffa7-41a0-bcc7-9d91c01602b3',
161
+ text: "<p>We see we've fallen short of your expectation. Please accept our apologies. Any feedback you might have will certainly help us improve.</p>",
162
+ name: 'Q_22',
163
+ position: 4,
164
+ required: false,
165
+ type_info: {
166
+ comment: false,
167
+ driver: false,
168
+ question_type: 'PARAGRAPH',
169
+ validation: null,
170
+ linear_scale: null,
171
+ rating_presets: null,
172
+ choices: null,
173
+ footer_text: null,
174
+ meta: null,
175
+ pivot_question: false,
176
+ },
177
+ },
178
+ {
179
+ id: 'ddf185e8-017b-4403-8333-00ee7b683c59',
180
+ text: 'Promotors\n',
181
+ name: 'TY_0',
182
+ position: 5,
183
+ required: false,
184
+ type_info: {
185
+ comment: false,
186
+ driver: false,
187
+ question_type: 'TEXT',
188
+ validation: null,
189
+ linear_scale: null,
190
+ rating_presets: null,
191
+ choices: null,
192
+ footer_text: null,
193
+ meta: {
194
+ block: {
195
+ name: 'TY',
196
+ title: 'Thank you',
197
+ is_based_on_rating: true,
198
+ question_names: ['TY_0', 'TY_01', 'TY_02'],
199
+ },
200
+ },
201
+ pivot_question: false,
202
+ },
203
+ },
204
+ {
205
+ id: 'a541b019-25b6-43fd-8304-47b720c34ad9',
206
+ text: 'Passive (7-8)',
207
+ name: 'TY_01',
208
+ position: 6,
209
+ required: false,
210
+ type_info: {
211
+ comment: false,
212
+ driver: false,
213
+ question_type: 'TEXT',
214
+ validation: null,
215
+ linear_scale: null,
216
+ rating_presets: null,
217
+ choices: null,
218
+ footer_text: null,
219
+ meta: {},
220
+ pivot_question: false,
221
+ },
222
+ },
223
+ {
224
+ id: '02a22da0-7aff-4589-9636-64b485928fcd',
225
+ text: 'Detractors',
226
+ name: 'TY_02',
227
+ position: 7,
228
+ required: false,
229
+ type_info: {
230
+ comment: false,
231
+ driver: false,
232
+ question_type: 'TEXT',
233
+ validation: null,
234
+ linear_scale: null,
235
+ rating_presets: null,
236
+ choices: null,
237
+ footer_text: null,
238
+ meta: {},
239
+ pivot_question: false,
240
+ },
241
+ },
242
+ ],
243
+ },
244
+ created_at: '2022-05-20T04:38:14.167Z',
245
+ updated_at: '2022-05-20T04:38:14.167Z',
246
+ gratitude_message: null,
247
+ ui_branding: {
248
+ logo_url: null,
249
+ name: null,
250
+ },
251
+ ui_theme: {
252
+ body_background_color: null,
253
+ primary_font: null,
254
+ secondary_font: null,
255
+ primary_background_color: null,
256
+ secondary_background_color: null,
257
+ primary_button_color: null,
258
+ secondary_button_color: null,
259
+ brand_color: '#e51923',
260
+ primary_button_text_color: '#fff',
261
+ button_style: null,
262
+ secondary_button_text_color: '#111',
263
+ question_background_color: '#abc',
264
+ question_text_color: '#12344d',
265
+ css_url: null,
266
+ },
267
+ meta: {
268
+ survey_layout: 'card',
269
+ created_by: 'user-541',
270
+ },
271
+ channels: null,
272
+ template: false,
273
+ header_message:
274
+ 'Thank you for your time. This survey should take under a minute to complete.',
275
+ contact_info: null,
276
+ schedule_info: null,
277
+ throttle_info: null,
278
+ channel_info: null,
279
+ product_client_id: '_199-3',
280
+ }
281
+
282
+ export const mockPlaceholders = {
283
+ '{{account.organisation_domain}}': 'test.int.myfreshworks.dev',
284
+ '{{account.company_name}}': 'Acme Inc',
285
+ '{{account.logo_url}}': '',
286
+ '{{account.brand_color}}': '#E50914',
287
+ '{{account.name}}': 'test',
288
+ '{{account.domain}}': 'test.sta91ng-freshsurvey.com',
289
+ '{{account.id}}': 'acc-208',
290
+ '{{account.timezone}}': '',
291
+ '{{survey.desc}}': 'Survey Description goes here',
292
+ '{{survey.id}}': 'f18fa279-eb2a-45ff-acd3-f7d4e4f03814',
293
+ '{{survey.name}}': 'Untitled NPS Survey',
294
+ '{{contact.updated_at}}': '1644730335625',
295
+ '{{contact.external_id}}': '154328a3-4b7a-4cbe-8c67-933f3340761d',
296
+ '{{contact.zipcode}}': '',
297
+ '{{contact.industry}}': '',
298
+ '{{contact.first_name}}': 'Kill',
299
+ '{{contact.address}}': '',
300
+ '{{contact.city}}': '',
301
+ '{{contact.list_ids}}': '[cl-135]',
302
+ '{{contact.company_website}}': '',
303
+ '{{contact.creater_id}}': '412842723848100367',
304
+ '{{contact.work_number}}': '',
305
+ '{{contact.created_at}}': '1644730321825',
306
+ '{{contact.mobile_number}}': '',
307
+ '{{contact.company_name}}': '',
308
+ '{{contact.timezone}}': '',
309
+ '{{contact.updater_id}}': '412842723848100367',
310
+ '{{contact.sub_state}}': '1',
311
+ '{{contact.designation}}': '',
312
+ '{{contact.last_name}}': 'Bill',
313
+ '{{contact.state}}': '',
314
+ '{{contact.language}}': '',
315
+ '{{contact.work_email}}': 'test@freshworks.com',
316
+ '{{contact.country}}': '',
317
+ }
@@ -0,0 +1,34 @@
1
+ import { withKnobs } from '@storybook/addon-knobs'
2
+ import { storiesOf } from '@storybook/react'
3
+ import React from 'react'
4
+ import { Survey } from '../../src'
5
+ import { mockSurvey, mockPlaceholders } from '../fixtures/mock'
6
+
7
+ const stories = storiesOf('Test Survey', module)
8
+ stories.addDecorator(withKnobs)
9
+
10
+ stories.add('Card Survey', () => {
11
+ return (
12
+ <div
13
+ style={{
14
+ display: 'flex',
15
+ flexDirection: 'column',
16
+ maxWidth: '700px',
17
+ margin: '0 auto',
18
+ }}
19
+ >
20
+ <Survey
21
+ survey={mockSurvey}
22
+ surveyStyle={'card'}
23
+ placeholders={mockPlaceholders}
24
+ onSubmit={(data, callback) => {
25
+ console.log(data)
26
+ callback?.()
27
+ }}
28
+ closePreview={() => console.log('Closing preview...')}
29
+ preview={true}
30
+ widgetNavigatorQuerySelector="#header"
31
+ />
32
+ </div>
33
+ )
34
+ })
@@ -0,0 +1,37 @@
1
+ /// <reference types="cypress" />
2
+ // ***********************************************
3
+ // This example commands.ts shows you how to
4
+ // create various custom commands and overwrite
5
+ // existing commands.
6
+ //
7
+ // For more comprehensive examples of custom
8
+ // commands please read more here:
9
+ // https://on.cypress.io/custom-commands
10
+ // ***********************************************
11
+ //
12
+ //
13
+ // -- This is a parent command --
14
+ // Cypress.Commands.add('login', (email, password) => { ... })
15
+ //
16
+ //
17
+ // -- This is a child command --
18
+ // Cypress.Commands.add('drag', { prevSubject: 'element'}, (subject, options) => { ... })
19
+ //
20
+ //
21
+ // -- This is a dual command --
22
+ // Cypress.Commands.add('dismiss', { prevSubject: 'optional'}, (subject, options) => { ... })
23
+ //
24
+ //
25
+ // -- This will overwrite an existing command --
26
+ // Cypress.Commands.overwrite('visit', (originalFn, url, options) => { ... })
27
+ //
28
+ // declare global {
29
+ // namespace Cypress {
30
+ // interface Chainable {
31
+ // login(email: string, password: string): Chainable<void>
32
+ // drag(subject: string, options?: Partial<TypeOptions>): Chainable<Element>
33
+ // dismiss(subject: string, options?: Partial<TypeOptions>): Chainable<Element>
34
+ // visit(originalFn: CommandOriginalFn, url: string, options: Partial<VisitOptions>): Chainable<Element>
35
+ // }
36
+ // }
37
+ // }
@@ -0,0 +1,20 @@
1
+ // ***********************************************************
2
+ // This example support/e2e.ts is processed and
3
+ // loaded automatically before your test files.
4
+ //
5
+ // This is a great place to put global configuration and
6
+ // behavior that modifies Cypress.
7
+ //
8
+ // You can change the location of this file or turn off
9
+ // automatically serving support files with the
10
+ // 'supportFile' configuration option.
11
+ //
12
+ // You can read more here:
13
+ // https://on.cypress.io/configuration
14
+ // ***********************************************************
15
+
16
+ // Import commands.js using ES2015 syntax:
17
+ import './commands'
18
+
19
+ // Alternatively you can use CommonJS syntax:
20
+ // require('./commands')
@@ -0,0 +1,7 @@
1
+ import { defineConfig } from 'cypress'
2
+
3
+ export default defineConfig({
4
+ e2e: {
5
+ baseUrl: 'http://localhost:6006',
6
+ },
7
+ })