@fmidev/smartmet-alert-client 4.2.7 → 4.7.0-alpha.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/.eslintignore +2 -14
- package/.github/workflows/test.yaml +26 -0
- package/.nvmrc +1 -0
- package/dist/index.dark.html +1 -1
- package/dist/index.en.html +1 -1
- package/dist/index.fi.html +1 -1
- package/dist/index.html +5 -0
- package/dist/index.js +105 -135
- package/dist/index.mjs +112 -135
- package/dist/index.sv.html +1 -1
- package/dist/locale-en-DCEKDw5G.js +8 -0
- package/dist/locale-fi-DPiOM1rB.js +8 -0
- package/dist/locale-sv-B0FlbgEF.js +8 -0
- package/dist/vendor-Cfkkvdz7.js +21 -0
- package/dist/vue/index.mjs +15245 -0
- package/dist/vue/style.css +1 -0
- package/dist/xml-parser-BiNO9kc-.js +13 -0
- package/package.json +61 -25
- package/public/index.dark.html +1 -1
- package/public/index.en.html +1 -1
- package/public/index.fi.html +1 -1
- package/public/index.sv.html +1 -1
- package/src/AlertClientVue.vue +170 -0
- package/src/App.vue +58 -176
- package/src/assets/img/ui/arrow-down.svg +4 -14
- package/src/assets/img/ui/arrow-up.svg +4 -14
- package/src/assets/img/ui/clear.svg +7 -21
- package/src/assets/img/ui/close.svg +4 -15
- package/src/assets/img/ui/toggle-selected.svg +12 -0
- package/src/assets/img/ui/toggle-unselected.svg +12 -0
- package/src/assets/img/warning/cold-weather.svg +3 -6
- package/src/assets/img/warning/flood-level-3.svg +4 -7
- package/src/assets/img/warning/forest-fire-weather.svg +2 -6
- package/src/assets/img/warning/grass-fire-weather.svg +2 -6
- package/src/assets/img/warning/hot-weather.svg +3 -6
- package/src/assets/img/warning/pedestrian-safety.svg +3 -7
- package/src/assets/img/warning/rain.svg +2 -7
- package/src/assets/img/warning/sea-icing.svg +2 -6
- package/src/assets/img/warning/sea-thunder-storm.svg +2 -5
- package/src/assets/img/warning/sea-water-height-high-water.svg +3 -8
- package/src/assets/img/warning/sea-water-height-shallow-water.svg +3 -7
- package/src/assets/img/warning/sea-wave-height.svg +4 -7
- package/src/assets/img/warning/sea-wind-legend.svg +2 -5
- package/src/assets/img/warning/sea-wind.svg +2 -5
- package/src/assets/img/warning/several.svg +2 -5
- package/src/assets/img/warning/thunder-storm.svg +2 -5
- package/src/assets/img/warning/traffic-weather.svg +2 -6
- package/src/assets/img/warning/uv-note.svg +2 -6
- package/src/assets/img/warning/wind.svg +2 -5
- package/src/components/AlertClient.vue +42 -20
- package/src/components/CollapsiblePanel.vue +284 -0
- package/src/components/DayLarge.vue +40 -32
- package/src/components/DaySmall.vue +17 -7
- package/src/components/Days.vue +77 -52
- package/src/components/DescriptionWarning.vue +26 -8
- package/src/components/GrayScaleToggle.vue +42 -35
- package/src/components/Legend.vue +36 -240
- package/src/components/MapLarge.vue +55 -50
- package/src/components/MapSmall.vue +48 -29
- package/src/components/PopupRow.vue +6 -3
- package/src/components/Region.vue +162 -53
- package/src/components/RegionWarning.vue +33 -11
- package/src/components/Regions.vue +59 -29
- package/src/components/Warning.vue +53 -49
- package/src/components/Warnings.vue +54 -16
- package/src/locales/en.json +21 -4
- package/src/locales/fi.json +23 -6
- package/src/locales/sv.json +20 -3
- package/src/main.js +1 -0
- package/src/mixins/alertClientCore.js +210 -0
- package/src/mixins/config.js +263 -257
- package/src/mixins/utils.js +46 -15
- package/src/plugins/index.js +1 -1
- package/src/scss/_utilities.scss +193 -0
- package/src/scss/backgrounds.scss +2 -0
- package/src/scss/colors.scss +5 -3
- package/src/scss/constants.scss +3 -2
- package/src/scss/themes/dark-gray.scss +3 -3
- package/src/scss/themes/dark.scss +1 -1
- package/src/scss/themes/light-gray.scss +5 -5
- package/src/scss/themes/light.scss +3 -3
- package/src/scss/warningImages.scss +9 -5
- package/src/vue.js +41 -0
- package/svgo.config.js +45 -0
- package/tests/README.md +430 -0
- package/tests/fixtures/mockWarningData.js +135 -0
- package/tests/integration/warning-flow.spec.js +452 -0
- package/tests/setup.js +41 -0
- package/tests/unit/components/AlertClient.spec.js +734 -0
- package/tests/unit/components/DayLarge.spec.js +281 -0
- package/tests/unit/components/DaySmall.spec.js +278 -0
- package/tests/unit/components/Days.spec.js +565 -0
- package/tests/unit/components/DescriptionWarning.spec.js +432 -0
- package/tests/unit/components/GrayScaleToggle.spec.js +311 -0
- package/tests/unit/components/Legend.spec.js +223 -0
- package/tests/unit/components/MapLarge.spec.js +276 -0
- package/tests/unit/components/MapSmall.spec.js +226 -0
- package/tests/unit/components/PopupRow.spec.js +261 -0
- package/tests/unit/components/Region.spec.js +430 -0
- package/tests/unit/components/RegionWarning.snapshot.spec.js +73 -0
- package/tests/unit/components/RegionWarning.spec.js +408 -0
- package/tests/unit/components/Regions.spec.js +335 -0
- package/tests/unit/components/Warning.snapshot.spec.js +107 -0
- package/tests/unit/components/Warning.spec.js +472 -0
- package/tests/unit/components/Warnings.spec.js +329 -0
- package/tests/unit/components/__snapshots__/RegionWarning.snapshot.spec.js.snap +21 -0
- package/tests/unit/components/__snapshots__/Warning.snapshot.spec.js.snap +199 -0
- package/tests/unit/mixins/config.spec.js +269 -0
- package/tests/unit/mixins/i18n.spec.js +115 -0
- package/tests/unit/mixins/keycodes.spec.js +37 -0
- package/tests/unit/mixins/utils.spec.js +624 -0
- package/vite.config.js +96 -26
- package/vitest.config.js +40 -0
- package/dist/index.mjs.map +0 -1
- package/dist/index.relative.html +0 -19
- package/dist/index.start.html +0 -20
- package/playwright.config.ts +0 -18
- package/public/index.relative.html +0 -19
- package/public/index.start.html +0 -20
- package/src/assets/img/ui/toggle-selected-blue.svg +0 -4
- package/src/assets/img/ui/toggle-selected-dark.svg +0 -4
- package/src/assets/img/ui/toggle-selected-light.svg +0 -4
- package/src/assets/img/ui/toggle-unselected-dark.svg +0 -4
- package/src/assets/img/ui/toggle-unselected-light.svg +0 -4
- package/src/mixins/panzoom.js +0 -900
- package/test/snapshot.test.ts +0 -126
- package/vitest.config.ts +0 -6
|
@@ -0,0 +1,269 @@
|
|
|
1
|
+
import { describe, it, expect } from 'vitest'
|
|
2
|
+
import { mount } from '@vue/test-utils'
|
|
3
|
+
import config from '@/mixins/config'
|
|
4
|
+
|
|
5
|
+
const TestComponent = {
|
|
6
|
+
mixins: [config],
|
|
7
|
+
template: '<div></div>',
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
describe('config mixin', () => {
|
|
11
|
+
let wrapper
|
|
12
|
+
|
|
13
|
+
beforeEach(() => {
|
|
14
|
+
wrapper = mount(TestComponent)
|
|
15
|
+
})
|
|
16
|
+
|
|
17
|
+
describe('Configuration constants', () => {
|
|
18
|
+
it('should define timezone', () => {
|
|
19
|
+
expect(wrapper.vm.timeZone).toBe('Europe/Helsinki')
|
|
20
|
+
})
|
|
21
|
+
|
|
22
|
+
it('should define date format locale', () => {
|
|
23
|
+
expect(wrapper.vm.dateTimeFormatLocale).toBe('fi-FI')
|
|
24
|
+
})
|
|
25
|
+
|
|
26
|
+
it('should define pan limits', () => {
|
|
27
|
+
expect(wrapper.vm.panLimits).toEqual({ x: 175, y: 275 })
|
|
28
|
+
})
|
|
29
|
+
|
|
30
|
+
it('should define coverage criterion', () => {
|
|
31
|
+
expect(wrapper.vm.coverageCriterion).toBe(0.2)
|
|
32
|
+
})
|
|
33
|
+
|
|
34
|
+
it('should define max merged weight', () => {
|
|
35
|
+
expect(wrapper.vm.maxMergedWeight).toBe(7)
|
|
36
|
+
})
|
|
37
|
+
|
|
38
|
+
it('should define max update delays', () => {
|
|
39
|
+
expect(wrapper.vm.maxUpdateDelay).toHaveProperty('weather_update_time')
|
|
40
|
+
expect(wrapper.vm.maxUpdateDelay).toHaveProperty('flood_update_time')
|
|
41
|
+
expect(wrapper.vm.maxUpdateDelay.weather_update_time).toBe(
|
|
42
|
+
12 * 60 * 60 * 1000
|
|
43
|
+
)
|
|
44
|
+
})
|
|
45
|
+
})
|
|
46
|
+
|
|
47
|
+
describe('Warning types map', () => {
|
|
48
|
+
it('should have warningTypes map', () => {
|
|
49
|
+
expect(wrapper.vm.warningTypes).toBeInstanceOf(Map)
|
|
50
|
+
})
|
|
51
|
+
|
|
52
|
+
it('should map land warning types', () => {
|
|
53
|
+
const landTypes = [
|
|
54
|
+
'thunderStorm',
|
|
55
|
+
'wind',
|
|
56
|
+
'rain',
|
|
57
|
+
'trafficWeather',
|
|
58
|
+
'pedestrianSafety',
|
|
59
|
+
'forestFireWeather',
|
|
60
|
+
'grassFireWeather',
|
|
61
|
+
'hotWeather',
|
|
62
|
+
'coldWeather',
|
|
63
|
+
'uvNote',
|
|
64
|
+
'floodLevel',
|
|
65
|
+
]
|
|
66
|
+
|
|
67
|
+
landTypes.forEach((type) => {
|
|
68
|
+
expect(wrapper.vm.warningTypes.get(type)).toBe('land')
|
|
69
|
+
})
|
|
70
|
+
})
|
|
71
|
+
|
|
72
|
+
it('should map sea warning types', () => {
|
|
73
|
+
const seaTypes = [
|
|
74
|
+
'seaWind',
|
|
75
|
+
'seaThunderStorm',
|
|
76
|
+
'seaWaterHeightHighWater',
|
|
77
|
+
'seaWaterHeightShallowWater',
|
|
78
|
+
'seaWaveHeight',
|
|
79
|
+
'seaIcing',
|
|
80
|
+
]
|
|
81
|
+
|
|
82
|
+
seaTypes.forEach((type) => {
|
|
83
|
+
expect(wrapper.vm.warningTypes.get(type)).toBe('sea')
|
|
84
|
+
})
|
|
85
|
+
})
|
|
86
|
+
})
|
|
87
|
+
|
|
88
|
+
describe('Region IDs', () => {
|
|
89
|
+
it('should have regionIds array', () => {
|
|
90
|
+
expect(Array.isArray(wrapper.vm.regionIds)).toBe(true)
|
|
91
|
+
expect(wrapper.vm.regionIds.length).toBeGreaterThan(0)
|
|
92
|
+
})
|
|
93
|
+
|
|
94
|
+
it('should include county regions', () => {
|
|
95
|
+
expect(wrapper.vm.regionIds).toContain('county.1')
|
|
96
|
+
expect(wrapper.vm.regionIds).toContain('county.2')
|
|
97
|
+
})
|
|
98
|
+
|
|
99
|
+
it('should include sea regions', () => {
|
|
100
|
+
expect(wrapper.vm.regionIds).toContain('sea_region.B1N')
|
|
101
|
+
expect(wrapper.vm.regionIds).toContain('sea_region.B2')
|
|
102
|
+
})
|
|
103
|
+
|
|
104
|
+
it('should include municipality regions', () => {
|
|
105
|
+
expect(wrapper.vm.regionIds).toContain('municipality.615')
|
|
106
|
+
})
|
|
107
|
+
})
|
|
108
|
+
|
|
109
|
+
describe('Geometries', () => {
|
|
110
|
+
it('should have geometries object', () => {
|
|
111
|
+
expect(wrapper.vm.geometries).toBeDefined()
|
|
112
|
+
expect(wrapper.vm.geometries).toHaveProperty('2021')
|
|
113
|
+
})
|
|
114
|
+
|
|
115
|
+
it('should have geometry data for counties', () => {
|
|
116
|
+
const county1 = wrapper.vm.geometries[2021]['county.1']
|
|
117
|
+
|
|
118
|
+
expect(county1).toBeDefined()
|
|
119
|
+
expect(county1).toHaveProperty('name')
|
|
120
|
+
expect(county1).toHaveProperty('type')
|
|
121
|
+
expect(county1).toHaveProperty('weight')
|
|
122
|
+
expect(county1).toHaveProperty('center')
|
|
123
|
+
expect(county1).toHaveProperty('pathLarge')
|
|
124
|
+
expect(county1).toHaveProperty('pathSmall')
|
|
125
|
+
})
|
|
126
|
+
|
|
127
|
+
it('should mark land regions correctly', () => {
|
|
128
|
+
const county = wrapper.vm.geometries[2021]['county.1']
|
|
129
|
+
expect(county.type).toBe('land')
|
|
130
|
+
})
|
|
131
|
+
|
|
132
|
+
it('should mark sea regions correctly', () => {
|
|
133
|
+
const seaRegion = wrapper.vm.geometries[2021]['sea_region.B1N']
|
|
134
|
+
expect(seaRegion.type).toBe('sea')
|
|
135
|
+
})
|
|
136
|
+
|
|
137
|
+
it('should have borders data', () => {
|
|
138
|
+
const borders = wrapper.vm.geometries[2021].borders
|
|
139
|
+
|
|
140
|
+
expect(borders).toBeDefined()
|
|
141
|
+
expect(borders).toHaveProperty('land')
|
|
142
|
+
expect(borders).toHaveProperty('sea')
|
|
143
|
+
expect(borders.land).toHaveProperty('pathLarge')
|
|
144
|
+
expect(borders.sea).toHaveProperty('pathLarge')
|
|
145
|
+
})
|
|
146
|
+
|
|
147
|
+
it('should include parent-child relationships', () => {
|
|
148
|
+
const municipality = wrapper.vm.geometries[2021]['municipality.615']
|
|
149
|
+
|
|
150
|
+
expect(municipality).toBeDefined()
|
|
151
|
+
expect(municipality).toHaveProperty('parent')
|
|
152
|
+
expect(municipality.parent).toBe('county.17')
|
|
153
|
+
})
|
|
154
|
+
})
|
|
155
|
+
|
|
156
|
+
describe('Colors configuration', () => {
|
|
157
|
+
it('should have colors for all themes', () => {
|
|
158
|
+
expect(wrapper.vm.colors).toHaveProperty('light-theme')
|
|
159
|
+
expect(wrapper.vm.colors).toHaveProperty('dark-theme')
|
|
160
|
+
expect(wrapper.vm.colors).toHaveProperty('light-gray-theme')
|
|
161
|
+
expect(wrapper.vm.colors).toHaveProperty('dark-gray-theme')
|
|
162
|
+
})
|
|
163
|
+
|
|
164
|
+
it('should define severity levels colors', () => {
|
|
165
|
+
const lightTheme = wrapper.vm.colors['light-theme']
|
|
166
|
+
|
|
167
|
+
expect(lightTheme.levels).toHaveLength(5)
|
|
168
|
+
expect(lightTheme).toHaveProperty('sea')
|
|
169
|
+
expect(lightTheme).toHaveProperty('missing')
|
|
170
|
+
expect(lightTheme).toHaveProperty('stroke')
|
|
171
|
+
})
|
|
172
|
+
|
|
173
|
+
it('should have different colors for gray themes', () => {
|
|
174
|
+
const lightTheme = wrapper.vm.colors['light-theme']
|
|
175
|
+
const grayTheme = wrapper.vm.colors['light-gray-theme']
|
|
176
|
+
|
|
177
|
+
expect(lightTheme.levels).not.toEqual(grayTheme.levels)
|
|
178
|
+
})
|
|
179
|
+
})
|
|
180
|
+
|
|
181
|
+
describe('Warning icon method', () => {
|
|
182
|
+
it('should generate wind icon with direction', () => {
|
|
183
|
+
const warning = {
|
|
184
|
+
type: 'wind',
|
|
185
|
+
direction: 90,
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
const icon = wrapper.vm.warningIcon(warning)
|
|
189
|
+
|
|
190
|
+
expect(icon).toHaveProperty('aspectRatio')
|
|
191
|
+
expect(icon).toHaveProperty('geom')
|
|
192
|
+
expect(icon.geom).toContain('wind-symbol')
|
|
193
|
+
})
|
|
194
|
+
|
|
195
|
+
it('should generate thunder storm icon', () => {
|
|
196
|
+
const warning = {
|
|
197
|
+
type: 'thunderStorm',
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
const icon = wrapper.vm.warningIcon(warning)
|
|
201
|
+
|
|
202
|
+
expect(icon.geom).toContain('thunder-symbol')
|
|
203
|
+
})
|
|
204
|
+
|
|
205
|
+
it('should generate rain icon', () => {
|
|
206
|
+
const warning = {
|
|
207
|
+
type: 'rain',
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
const icon = wrapper.vm.warningIcon(warning)
|
|
211
|
+
|
|
212
|
+
expect(icon.geom).toContain('rain-symbol')
|
|
213
|
+
})
|
|
214
|
+
|
|
215
|
+
it('should generate traffic weather icon', () => {
|
|
216
|
+
const warning = {
|
|
217
|
+
type: 'trafficWeather',
|
|
218
|
+
}
|
|
219
|
+
|
|
220
|
+
const icon = wrapper.vm.warningIcon(warning)
|
|
221
|
+
|
|
222
|
+
expect(icon.geom).toContain('traffic-symbol')
|
|
223
|
+
})
|
|
224
|
+
|
|
225
|
+
it('should generate sea wind icon with text', () => {
|
|
226
|
+
const warning = {
|
|
227
|
+
type: 'seaWind',
|
|
228
|
+
direction: 180,
|
|
229
|
+
text: '15',
|
|
230
|
+
}
|
|
231
|
+
|
|
232
|
+
const icon = wrapper.vm.warningIcon(warning)
|
|
233
|
+
|
|
234
|
+
expect(icon.geom).toContain('seawind-symbol')
|
|
235
|
+
expect(icon.geom).toContain('15')
|
|
236
|
+
})
|
|
237
|
+
|
|
238
|
+
it('should generate flood icon based on severity', () => {
|
|
239
|
+
const warning = {
|
|
240
|
+
type: 'floodLevel',
|
|
241
|
+
severity: 3,
|
|
242
|
+
}
|
|
243
|
+
|
|
244
|
+
const icon = wrapper.vm.warningIcon(warning)
|
|
245
|
+
|
|
246
|
+
expect(icon.geom).toContain('flood-level-3')
|
|
247
|
+
})
|
|
248
|
+
|
|
249
|
+
it('should generate multiple warnings icon', () => {
|
|
250
|
+
const warning = {
|
|
251
|
+
type: 'multiple',
|
|
252
|
+
}
|
|
253
|
+
|
|
254
|
+
const icon = wrapper.vm.warningIcon(warning)
|
|
255
|
+
|
|
256
|
+
expect(icon.geom).toContain('multiple-symbol')
|
|
257
|
+
})
|
|
258
|
+
|
|
259
|
+
it('should set scale for specific warning types', () => {
|
|
260
|
+
const warning = {
|
|
261
|
+
type: 'hotWeather',
|
|
262
|
+
}
|
|
263
|
+
|
|
264
|
+
const icon = wrapper.vm.warningIcon(warning)
|
|
265
|
+
|
|
266
|
+
expect(icon.scale).toBe(1.2)
|
|
267
|
+
})
|
|
268
|
+
})
|
|
269
|
+
})
|
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
import { describe, it, expect } from 'vitest'
|
|
2
|
+
import { mount } from '@vue/test-utils'
|
|
3
|
+
import i18n from '@/mixins/i18n'
|
|
4
|
+
|
|
5
|
+
const TestComponent = {
|
|
6
|
+
mixins: [i18n],
|
|
7
|
+
template: '<div>{{ t("noWarnings") }}</div>',
|
|
8
|
+
props: {
|
|
9
|
+
language: {
|
|
10
|
+
type: String,
|
|
11
|
+
default: 'fi',
|
|
12
|
+
},
|
|
13
|
+
},
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
describe('i18n mixin', () => {
|
|
17
|
+
describe('t() method', () => {
|
|
18
|
+
it('should return Finnish translation', () => {
|
|
19
|
+
const wrapper = mount(TestComponent, {
|
|
20
|
+
props: { language: 'fi' },
|
|
21
|
+
})
|
|
22
|
+
|
|
23
|
+
const result = wrapper.vm.t('noWarnings')
|
|
24
|
+
expect(result).toBeTruthy()
|
|
25
|
+
expect(typeof result).toBe('string')
|
|
26
|
+
})
|
|
27
|
+
|
|
28
|
+
it('should return English translation', () => {
|
|
29
|
+
const wrapper = mount(TestComponent, {
|
|
30
|
+
props: { language: 'en' },
|
|
31
|
+
})
|
|
32
|
+
|
|
33
|
+
const result = wrapper.vm.t('noWarnings')
|
|
34
|
+
expect(result).toBeTruthy()
|
|
35
|
+
expect(typeof result).toBe('string')
|
|
36
|
+
})
|
|
37
|
+
|
|
38
|
+
it('should return Swedish translation', () => {
|
|
39
|
+
const wrapper = mount(TestComponent, {
|
|
40
|
+
props: { language: 'sv' },
|
|
41
|
+
})
|
|
42
|
+
|
|
43
|
+
const result = wrapper.vm.t('noWarnings')
|
|
44
|
+
expect(result).toBeTruthy()
|
|
45
|
+
expect(typeof result).toBe('string')
|
|
46
|
+
})
|
|
47
|
+
|
|
48
|
+
it('should return empty string for unknown language', () => {
|
|
49
|
+
const wrapper = mount(TestComponent, {
|
|
50
|
+
props: { language: 'de' },
|
|
51
|
+
})
|
|
52
|
+
|
|
53
|
+
const result = wrapper.vm.t('noWarnings')
|
|
54
|
+
expect(result).toBe('')
|
|
55
|
+
})
|
|
56
|
+
|
|
57
|
+
it('should return empty string for null key', () => {
|
|
58
|
+
const wrapper = mount(TestComponent, {
|
|
59
|
+
props: { language: 'fi' },
|
|
60
|
+
})
|
|
61
|
+
|
|
62
|
+
const result = wrapper.vm.t(null)
|
|
63
|
+
expect(result).toBe('')
|
|
64
|
+
})
|
|
65
|
+
|
|
66
|
+
it('should return empty string for undefined key', () => {
|
|
67
|
+
const wrapper = mount(TestComponent, {
|
|
68
|
+
props: { language: 'fi' },
|
|
69
|
+
})
|
|
70
|
+
|
|
71
|
+
const result = wrapper.vm.t(undefined)
|
|
72
|
+
expect(result).toBe('')
|
|
73
|
+
})
|
|
74
|
+
|
|
75
|
+
it('should return empty string for non-existent key', () => {
|
|
76
|
+
const wrapper = mount(TestComponent, {
|
|
77
|
+
props: { language: 'fi' },
|
|
78
|
+
})
|
|
79
|
+
|
|
80
|
+
const result = wrapper.vm.t('nonExistentKey12345')
|
|
81
|
+
expect(result).toBe('')
|
|
82
|
+
})
|
|
83
|
+
|
|
84
|
+
it('should sanitize HTML in translations', () => {
|
|
85
|
+
const wrapper = mount(TestComponent, {
|
|
86
|
+
props: { language: 'fi' },
|
|
87
|
+
})
|
|
88
|
+
|
|
89
|
+
// Assuming translations don't contain scripts
|
|
90
|
+
const result = wrapper.vm.t('noWarnings')
|
|
91
|
+
expect(result).not.toContain('<script>')
|
|
92
|
+
expect(result).not.toContain('javascript:')
|
|
93
|
+
})
|
|
94
|
+
|
|
95
|
+
it('should handle all common translation keys', () => {
|
|
96
|
+
const wrapper = mount(TestComponent, {
|
|
97
|
+
props: { language: 'fi' },
|
|
98
|
+
})
|
|
99
|
+
|
|
100
|
+
const commonKeys = [
|
|
101
|
+
'noWarnings',
|
|
102
|
+
'validWarnings',
|
|
103
|
+
'toContent',
|
|
104
|
+
'supportedBrowsers',
|
|
105
|
+
'floodLink',
|
|
106
|
+
'floodLinkText',
|
|
107
|
+
]
|
|
108
|
+
|
|
109
|
+
commonKeys.forEach((key) => {
|
|
110
|
+
const result = wrapper.vm.t(key)
|
|
111
|
+
expect(typeof result).toBe('string')
|
|
112
|
+
})
|
|
113
|
+
})
|
|
114
|
+
})
|
|
115
|
+
})
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { describe, it, expect } from 'vitest'
|
|
2
|
+
import { mount } from '@vue/test-utils'
|
|
3
|
+
import keycodes from '@/mixins/keycodes'
|
|
4
|
+
|
|
5
|
+
const TestComponent = {
|
|
6
|
+
mixins: [keycodes],
|
|
7
|
+
template: '<div></div>',
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
describe('keycodes mixin', () => {
|
|
11
|
+
it('should define KEY_CODE_END', () => {
|
|
12
|
+
const wrapper = mount(TestComponent)
|
|
13
|
+
expect(wrapper.vm.KEY_CODE_END).toBe(35)
|
|
14
|
+
})
|
|
15
|
+
|
|
16
|
+
it('should define KEY_CODE_HOME', () => {
|
|
17
|
+
const wrapper = mount(TestComponent)
|
|
18
|
+
expect(wrapper.vm.KEY_CODE_HOME).toBe(36)
|
|
19
|
+
})
|
|
20
|
+
|
|
21
|
+
it('should define KEY_CODE_LEFT', () => {
|
|
22
|
+
const wrapper = mount(TestComponent)
|
|
23
|
+
expect(wrapper.vm.KEY_CODE_LEFT).toBe(37)
|
|
24
|
+
})
|
|
25
|
+
|
|
26
|
+
it('should define KEY_CODE_RIGHT', () => {
|
|
27
|
+
const wrapper = mount(TestComponent)
|
|
28
|
+
expect(wrapper.vm.KEY_CODE_RIGHT).toBe(39)
|
|
29
|
+
})
|
|
30
|
+
|
|
31
|
+
it('should have all arrow key codes', () => {
|
|
32
|
+
const wrapper = mount(TestComponent)
|
|
33
|
+
|
|
34
|
+
expect(wrapper.vm.KEY_CODE_LEFT).toBeLessThan(wrapper.vm.KEY_CODE_RIGHT)
|
|
35
|
+
expect(wrapper.vm.KEY_CODE_HOME).toBeLessThan(wrapper.vm.KEY_CODE_RIGHT)
|
|
36
|
+
})
|
|
37
|
+
})
|