Skip to content

Commit a9e8b05

Browse files
committed
fix broken tests
1 parent a2dcc94 commit a9e8b05

File tree

2 files changed

+30
-12
lines changed

2 files changed

+30
-12
lines changed

src/main.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ module.exports = function (public_key, config) {
9292

9393
if (config.url_root === undefined) {
9494
config.url_root = window.location.pathname
95-
} else if (!config.url_root.startsWith('/')) {
95+
} else if (config.url_root[0] !== '/') {
9696
config.url_root = window.location.pathname
9797
error = 'the "url_root" config parameter should start (and probably end) with a slash "/"'
9898
}
@@ -250,6 +250,9 @@ response text: "${xhr.responseText}"`)
250250
return s
251251
}
252252
},
253+
goto: function (name, params) {
254+
this.$router.push({'name': name, params: params})
255+
}
253256
}
254257
})
255258
}

test/unit/specs/main.js

Lines changed: 26 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,8 @@ describe('main.js', done => {
1919
outer.appendChild(el)
2020

2121
const vm = socket('public_key', {
22-
element: '#foobar'
22+
element: '#foobar',
23+
url_root: '/'
2324
})
2425
vm.enquiry_form_info = 'foobar' // prevent get_enquiry making a GET request
2526
expect(vm.$el.parentNode.attributes['id'].value).to.equal('outer')
@@ -36,7 +37,7 @@ describe('main.js', done => {
3637
let el = document.createElement('div')
3738
el.setAttribute('id', 'socket')
3839
document.body.appendChild(el)
39-
const vm = socket('public_key')
40+
const vm = socket('public_key', {url_root: '/'})
4041
vm.enquiry_form_info = 'foobar' // prevent get_enquiry making a GET request
4142
vm.contractors = [{}]
4243
expect(vm.$el.querySelectorAll('.tcs-grid')).to.have.lengthOf(1)
@@ -48,7 +49,7 @@ describe('main.js', done => {
4849
let el = document.createElement('div')
4950
el.setAttribute('id', 'socket')
5051
document.body.appendChild(el)
51-
const vm = socket('public_key', {mode: 'enquiry'})
52+
const vm = socket('public_key', {mode: 'enquiry', url_root: '/'})
5253
vm.enquiry_form_info = 'foobar'
5354
vm.contractors = [{}]
5455
expect(vm.$el.querySelectorAll('.tcs-grid')).to.have.lengthOf(0)
@@ -60,13 +61,23 @@ describe('main.js', done => {
6061
let el = document.createElement('div')
6162
el.setAttribute('id', 'socket')
6263
document.body.appendChild(el)
63-
const vm = socket('public_key', {mode: 'enquiry-modal'})
64+
const vm = socket('public_key', {mode: 'enquiry-modal', url_root: '/'})
6465
vm.enquiry_form_info = 'foobar'
6566
vm.contractors = [{}]
6667
expect(vm.$el.querySelectorAll('.tcs-grid')).to.have.lengthOf(0)
6768
expect(vm.$el.querySelectorAll('.tcs-enquiry')).to.have.lengthOf(0)
6869
expect(vm.$el.querySelectorAll('.tcs-enquiry-button')).to.have.lengthOf(1)
6970
})
71+
72+
it('should use window.location.pathname for url_root', async () => {
73+
let el = document.createElement('div')
74+
el.setAttribute('id', 'socket')
75+
document.body.appendChild(el)
76+
const vm = socket('public_key')
77+
vm.enquiry_form_info = 'foobar'
78+
vm.contractors = [{}]
79+
expect(vm.config.url_root).to.equal('/context.html')
80+
})
7081
})
7182

7283
describe('main.js', () => {
@@ -84,7 +95,7 @@ describe('main.js', () => {
8495
el.setAttribute('id', 'socket')
8596
document.body.appendChild(el)
8697

87-
const vm = socket('public_key')
98+
const vm = socket('public_key', {url_root: '/'})
8899

89100
await sleep(50)
90101
expect(vm.error).to.equal(null)
@@ -108,7 +119,7 @@ describe('main.js', () => {
108119
document.body.appendChild(el)
109120

110121
let test_console = new TestConsole()
111-
const vm = socket('public_key', {console: test_console, v: 404})
122+
const vm = socket('public_key', {console: test_console, url_root: '/'})
112123

113124
await sleep(50)
114125
expect(vm.error).to.not.equal(null)
@@ -129,7 +140,11 @@ describe('main.js', () => {
129140
document.body.appendChild(el)
130141

131142
let test_console = new TestConsole()
132-
const vm = socket('the-public-key', {api_root: 'http://localhost:12345678', console: test_console})
143+
const vm = socket('the-public-key', {
144+
api_root: 'http://localhost:12345678',
145+
url_root: '/',
146+
console: test_console,
147+
})
133148

134149
await sleep(50)
135150
expect(vm.error).to.contain('Connection error')
@@ -154,7 +169,7 @@ describe('main.js', () => {
154169
el.setAttribute('id', 'socket')
155170
document.body.appendChild(el)
156171

157-
const vm = socket('public-key')
172+
const vm = socket('public-key', {url_root: '/'})
158173
vm.get_enquiry()
159174

160175
await sleep(50)
@@ -166,7 +181,7 @@ describe('main.js', () => {
166181
el.setAttribute('id', 'socket')
167182
document.body.appendChild(el)
168183

169-
const vm = socket('public-key', {contractor_enquiry_button: 'Speak to {contractor_name}'})
184+
const vm = socket('public-key', {contractor_enquiry_button: 'Speak to {contractor_name}', url_root: '/'})
170185
vm.enquiry_form_info = 'x' // prevent get_enquiry making a GET request
171186
let text = vm.get_text('skills_label')
172187
expect(text).to.equal('Skills')
@@ -179,7 +194,7 @@ describe('main.js', () => {
179194
el.setAttribute('id', 'socket')
180195
document.body.appendChild(el)
181196

182-
const vm = socket('public-key')
197+
const vm = socket('public-key', {url_root: '/'})
183198
expect(vm.contractors_extra).to.deep.equal({})
184199
let v = vm.get_details('/foobar', 'key')
185200
expect(v).to.equal(true)
@@ -212,7 +227,7 @@ describe('main.js', () => {
212227
el.setAttribute('id', 'socket')
213228
document.body.appendChild(el)
214229

215-
const vm = socket('public-key')
230+
const vm = socket('public-key', {url_root: '/'})
216231
vm.get_enquiry()
217232

218233
await sleep(50)

0 commit comments

Comments
 (0)