-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathtest.ts
executable file
·145 lines (131 loc) · 4.43 KB
/
test.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
// #!/usr/bin/env babel-node
// -*- coding: utf-8 -*-
'use strict'
/* !
region header
Copyright Torben Sickert (info["~at~"]torben.website) 16.12.2012
License
-------
This library written by Torben Sickert stand under a creative commons
naming 3.0 unported license.
See https://creativecommons.org/licenses/by/3.0/deed.de
endregion
*/
// region imports
import {beforeAll, describe, expect, test} from '@jest/globals'
import {
$Global, extend, globalContext, NOOP, RecursivePartial
} from 'clientnode'
import nodeFetch from 'node-fetch'
import api, {StoreLocator} from './index'
import {Configuration} from './type'
// endregion
// region prepare environment
globalContext.fetch = nodeFetch as unknown as typeof fetch
;(globalContext as $Global & {google: typeof google}).google = {
maps: {
ControlPosition: {TOP_LEFT: 0},
event: {addListener: NOOP},
InfoWindow: class {
open: () => void = NOOP
setContent: () => void = NOOP
},
LatLng: class {
lat = () => 1
lng = () => 1
},
LatLngBounds: class {
contains: () => true = () => true
},
Map: class {
controls: Array<Array<number>> = [[]]
getCenter = (): Record<string, never> => ({})
panBy: () => void = NOOP
panTo: () => void = NOOP
},
Marker: class {
setAnimation: () => void = NOOP
},
mockup: true,
places: {
PlacesService: class {
textSearch = (
options: object, callback: (words: Array<string>) => void
) => {
callback([])
}
},
SearchBox: NOOP
}
}
} as unknown as typeof google
const defaultConfiguration: RecursivePartial<Configuration> = {
applicationInterface: {
key: 'AIzaSyBAoKgqF4XaDblkRP4-94BITpUKzB767LQ'
},
ipToLocationApplicationInterface: {
key: '11a62990a1424e894da6eec464a747e6'
},
marker: {
// Is not loadable without browser environment.
cluster: null
},
search: {},
// Automatically generated store with option: "stores: bounds"
stores: [{
address: 'Elgendorfer Str. 57, 56410 Montabaur, Deutschland',
eMailAddress: '[email protected]',
latitude: 50.4356,
longitude: 7.81226,
name: '1 & 1 Telecom GmbH',
phoneNumber: '+49 721 9600'
}]
}
extend(true, StoreLocator.defaultConfiguration, defaultConfiguration)
const name = 'test-store-locator'
api.register(name)
// endregion
// region tests
describe('api', () => {
test('api definitions', () => {
expect(api).toBeDefined()
expect(api).toHaveProperty('component', StoreLocator)
expect(document.createElement(name)).toBeInstanceOf(StoreLocator)
})
})
describe('StoreLocator', (): void => {
beforeAll((): Promise<void> => StoreLocator.applicationInterfaceLoad)
// region tests
test('custom element definition', () => {
const storeLocator: StoreLocator =
document.createElement(name) as StoreLocator
document.body.appendChild(storeLocator)
expect(storeLocator).toBeDefined()
})
test('attribute configuration', () => {
const storeLocator: StoreLocator =
document.createElement(name) as StoreLocator
document.body.appendChild(storeLocator)
storeLocator.setAttribute('configuration', '{value: 2}')
expect(storeLocator).toHaveProperty('configuration.value', 2)
expect(storeLocator).toHaveProperty('resolvedConfiguration.value', 2)
})
test('search results', async (): Promise<void> => {
const storeLocator = document.createElement(name) as StoreLocator
document.body.appendChild(storeLocator)
await new Promise((resolve: (value: unknown) => void) => {
storeLocator.addEventListener('loaded', resolve)
})
expect(Array.from(storeLocator.querySelectorAll('div')).length)
.toBeGreaterThan(0)
const inputDomNode =
storeLocator.querySelector('input') as HTMLInputElement
expect(inputDomNode).toBeDefined()
inputDomNode.value = 'a'
inputDomNode.dispatchEvent(new KeyboardEvent('keyup', {key: 'a'}))
expect(storeLocator.querySelector('.store-locator-search-results'))
.toBeDefined()
})
// endregion
})
// endregion