@hellotext/hellotext 1.7.8 → 1.8.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.
package/README.md CHANGED
@@ -123,8 +123,8 @@ Hellotext.initialize('HELLOTEXT_BUSINESS_ID', configurationOptions)
123
123
 
124
124
  #### Configuration Options
125
125
 
126
- | Property | Description | Type | Default |
127
- |---------------------|-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|---------|---------|
128
- | session | A valid Hellotext session which was stored previously. When not set, Hellotext attempts to retrieve the stored value from `document.cookie` when available, otherwise it creates a new session. | String | null |
129
- | autoGenerateSession | Whether the library should automatically generate a session when no session is found in the query or the cookies | Boolean | true |
130
- | autoMountForms | Whether the library should automatically mount forms collected or not | Boolean | true |
126
+ | Property | Description | Type | Default |
127
+ |---------------------|-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|---------|-------------------------------------------|
128
+ | session | A valid Hellotext session which was stored previously. When not set, Hellotext attempts to retrieve the stored value from `document.cookie` when available, otherwise it creates a new session. | String | null |
129
+ | autoGenerateSession | Whether the library should automatically generate a session when no session is found in the query or the cookies | Boolean | true |
130
+ | forms | An object that controls how Hellotext should control the forms on the page. See [Forms](/docs/forms.md) documentation for more information. | Object | { autoMount: true, successMessage: true } |
@@ -0,0 +1,30 @@
1
+ import { Forms } from '../../../src/core/configuration/forms'
2
+
3
+ describe('Forms', () => {
4
+ describe('.autoMount', () => {
5
+ it('is true by default', () => {
6
+ expect(Forms.autoMount).toEqual(true)
7
+ })
8
+
9
+ it('can be set to false', () => {
10
+ Forms.autoMount = false
11
+ expect(Forms.autoMount).toEqual(false)
12
+ })
13
+ })
14
+
15
+ describe('.successMessage', () => {
16
+ it('is true by default', () => {
17
+ expect(Forms.successMessage).toEqual(true)
18
+ })
19
+
20
+ it('can be set to false', () => {
21
+ Forms.successMessage = false
22
+ expect(Forms.successMessage).toEqual(false)
23
+ })
24
+
25
+ it('can be set to a string', () => {
26
+ Forms.successMessage = 'Thank you for your submission'
27
+ expect(Forms.successMessage).toEqual('Thank you for your submission')
28
+ })
29
+ })
30
+ })
@@ -0,0 +1,28 @@
1
+ import { Configuration } from '../../src/core'
2
+
3
+ describe('Configuration', () => {
4
+ describe('.autoGenerateSession', () => {
5
+ it('is true by default', () => {
6
+ expect(Configuration.autoGenerateSession).toEqual(true)
7
+ })
8
+
9
+ it('can be set to false', () => {
10
+ Configuration.autoGenerateSession = false
11
+ expect(Configuration.autoGenerateSession).toEqual(false)
12
+ })
13
+ })
14
+
15
+ describe('.forms', () => {
16
+ it('has default values', () => {
17
+ expect(Configuration.forms.autoMount).toEqual(true)
18
+ expect(Configuration.forms.successMessage).toEqual(true)
19
+ });
20
+
21
+ it('can be modified', () => {
22
+ Configuration.assign({ forms: { autoMount: false, successMessage: false } })
23
+
24
+ expect(Configuration.forms.autoMount).toEqual(false)
25
+ expect(Configuration.forms.successMessage).toEqual(false)
26
+ })
27
+ })
28
+ })
@@ -10,7 +10,9 @@ beforeEach(() => {
10
10
 
11
11
  Hellotext.initialize('M01az53K', {
12
12
  autoGenerateSession: false,
13
- autoMountForms: false
13
+ forms: {
14
+ autoMount: false,
15
+ }
14
16
  })
15
17
  })
16
18
 
@@ -79,3 +79,53 @@ describe('markAsCompleted', () => {
79
79
  expect(emit).toHaveBeenCalledWith('form:completed', { id: 1 })
80
80
  })
81
81
  })
82
+
83
+ describe('localeAuthKey', () => {
84
+ it('is email when the first step has an email input', () => {
85
+ const form = new Form({
86
+ steps: [
87
+ {
88
+ inputs: [{ kind: 'email' }]
89
+ }
90
+ ]
91
+ })
92
+
93
+ expect(form.localeAuthKey).toBe('email')
94
+ })
95
+
96
+ it('is phone when the first step has a phone input', () => {
97
+ const form = new Form({
98
+ steps: [
99
+ {
100
+ inputs: [{ kind: 'phone' }]
101
+ }
102
+ ]
103
+ })
104
+
105
+ expect(form.localeAuthKey).toBe('phone')
106
+ })
107
+
108
+ it('is phone_and_email when the first step has both email and phone inputs', () => {
109
+ const form = new Form({
110
+ steps: [
111
+ {
112
+ inputs: [{ kind: 'email' }, { kind: 'phone' }]
113
+ }
114
+ ]
115
+ })
116
+
117
+ expect(form.localeAuthKey).toBe('phone_and_email')
118
+ })
119
+
120
+ it('is none when the first step has neither email nor phone inputs', () => {
121
+ const form = new Form({
122
+ steps: [
123
+ {
124
+ inputs: [{ kind: 'first_name' }]
125
+ }
126
+ ]
127
+ })
128
+
129
+ expect(form.localeAuthKey).toBe('none')
130
+ })
131
+ })