Skip to content

Commit 387c664

Browse files
committed
Merge branch 'dev' into main
2 parents f73c662 + 5a8158d commit 387c664

23 files changed

+1624
-744
lines changed

index.html

+17
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,23 @@
4444

4545
<!-- Google Tag Manager tag (gtm.js) - Google Tag Manager -->
4646
<script>(function(w,d,s,l,i){w[l]=w[l]||[];w[l].push({'gtm.start': new Date().getTime(),event:'gtm.js'});var f=d.getElementsByTagName(s)[0], j=d.createElement(s),dl=l!='dataLayer'?'&l='+l:'';j.async=true;j.src= 'https://www.googletagmanager.com/gtm.js?id='+i+dl;f.parentNode.insertBefore(j,f); })(window,document,'script','dataLayer','GTM-KWWTRTX');</script>
47+
48+
<!-- Google rich results card -->
49+
<script type="application/ld+json">
50+
{
51+
"@context": "https://schema.org",
52+
"@type": "Organization",
53+
"name": "Vite Ma Dose !",
54+
"alternateName": "Vite Ma Dose de Vaccin !",
55+
"url": "https://vitemadose.covidtracker.fr/",
56+
"logo": "https://vitemadose.covidtracker.fr/assets/images/svg/vmd-logo-landscape.svg",
57+
"sameAs": [
58+
"https://www.facebook.com/vitemadose/",
59+
"https://twitter.com/ViteMaDose_off",
60+
"https://fr.wikipedia.org/wiki/Guillaume_Rozier"
61+
]
62+
}
63+
</script>
4764
</head>
4865
<body>
4966
<iframe src="https://www.googletagmanager.com/ns.html?id=GTM-KWWTRTX" height="0" width="0" style="display:none;visibility:hidden"></iframe>

jest.config.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
module.exports = {
22
preset: 'ts-jest/presets/js-with-babel',
33
testEnvironment: 'jsdom',
4-
setupFilesAfterEnv: ["@testing-library/jest-dom/extend-expect"],
4+
setupFilesAfterEnv: ["@testing-library/jest-dom/extend-expect", "jest-extended"],
55
moduleNameMapper: {
66
"\\.(css|less|sass|scss)$": "<rootDir>/test-utils/styleMock.ts",
77
},

package-lock.json

+368-44
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

+7-4
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,9 @@
1111
"types"
1212
],
1313
"scripts": {
14-
"dev": "vite",
15-
"test": "jest",
1614
"tdd": "jest --watchAll --notify",
15+
"test": "jest",
16+
"dev": "vite",
1717
"build": "tsc && vite build",
1818
"build-dev": "tsc && vite --base dev/ build"
1919
},
@@ -35,13 +35,16 @@
3535
"@vitejs/plugin-legacy": "1.3.3",
3636
"autoprefixer": "10.2.5",
3737
"jest": "26.6.3",
38+
"jest-extended": "0.11.5",
3839
"sass": "1.32.8",
39-
"testing-library__dom": "^7.29.4-beta.1",
40-
"ts-jest": "^26.5.5",
40+
"testing-library__dom": "7.29.4-beta.1",
41+
"ts-jest": "26.5.5",
4142
"typescript": "4.2.3",
43+
"typescript-memoize": "1.0.1",
4244
"vite": "2.1.5"
4345
},
4446
"dependencies": {
47+
"@types/jest": "^26.0.23",
4548
"@types/smoothscroll-polyfill": "0.3.1",
4649
"bootstrap": "5.0.0-beta3",
4750
"chart.js": "2.9.4",

src/components/graphs/vmd-stats-by-date-centres-graph.component.ts

+2
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,8 @@ export class VmdStatsByDateCentresGraphComponent extends VmdGraphBaseComponent<S
3131
]
3232
},
3333
options: {
34+
responsive: true,
35+
maintainAspectRatio: false,
3436
scales:{
3537
xAxes: [{
3638
stacked: true,

src/components/graphs/vmd-stats-by-date-creneaux-graph.component.ts

+1
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ export class VmdStatsByDateCreneauxGraphComponent extends VmdGraphBaseComponent<
2727
},
2828
options: {
2929
responsive: true,
30+
maintainAspectRatio: false,
3031
scales:{
3132
xAxes: [{
3233
ticks:{

src/components/vmd-commune-or-departement-selector.component.scss

+8-1
Original file line numberDiff line numberDiff line change
@@ -111,14 +111,21 @@ label,
111111
box-shadow: rgb(0 0 0 / 8%) 0px 1px 2px inset;
112112
span {
113113
white-space: nowrap;
114-
padding: 6px;
114+
padding: 6px 10px;
115115
border-radius: 5px;
116116
background-color: transparent;
117117
animation: fade-in 200ms ease-in;
118118
color: white;
119119
font-weight: bold;
120120
}
121121
}
122+
.spinner-border {
123+
position: absolute;
124+
left: calc(100% + .25em);
125+
top: .75em;
126+
width: 1.5em;
127+
height: 1.5em;
128+
}
122129

123130
@keyframes fade-in {
124131
from {
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,198 @@
1+
import '@testing-library/jest-dom'
2+
import { html } from 'lit-html'
3+
import { screen } from "testing-library__dom";
4+
import userEvent from "@testing-library/user-event"
5+
import { fixture } from "@open-wc/testing-helpers";
6+
import './vmd-commune-or-departement-selector.component'
7+
8+
import { Commune, Departement } from '../state/State'
9+
import { delay } from '../utils/Schedulers'
10+
11+
const départementCalvados: Departement = {
12+
code_departement: '14',
13+
nom_departement: 'Calvados',
14+
code_region: 28,
15+
nom_region: 'Normandie'
16+
}
17+
18+
const communeDeauville: Commune = {
19+
code: "14220",
20+
codePostal: "14800",
21+
nom: "Deauville",
22+
codeDepartement: "14",
23+
longitude: 0.0772,
24+
latitude: 49.3531
25+
}
26+
27+
describe('<vmd-commune-or-departement-selector />', () => {
28+
let onCommuneSelected = jest.fn()
29+
let onDepartementSelected = jest.fn()
30+
let suggest = jest.fn(() => Promise.resolve([] as any[]))
31+
const placeholder = "Commune, Code postal, Département..."
32+
beforeEach(() => {
33+
onCommuneSelected.mockClear()
34+
onDepartementSelected.mockClear()
35+
suggest.mockClear()
36+
window.scroll = jest.fn()
37+
suggest.mockImplementation(async () => ([
38+
départementCalvados,
39+
communeDeauville
40+
]))
41+
})
42+
describe('when a value is given', () => {
43+
describe('and is a département', () => {
44+
beforeEach(async () => {
45+
await fixture(html`
46+
<vmd-commune-or-departement-selector
47+
@on-commune-selected="${onCommuneSelected}"
48+
@on-departement-selected="${onDepartementSelected}"
49+
.suggest="${suggest}"
50+
.value="${départementCalvados}"
51+
/>
52+
`)
53+
})
54+
55+
it('displays the name into the input', async () => {
56+
// Then
57+
const input = screen.getByPlaceholderText(placeholder)
58+
expect(input).toHaveValue('14 - Calvados')
59+
})
60+
})
61+
describe('and is a commune', () => {
62+
beforeEach(async () => {
63+
await fixture(html`
64+
<vmd-commune-or-departement-selector
65+
@on-commune-selected="${onCommuneSelected}"
66+
@on-departement-selected="${onDepartementSelected}"
67+
.suggest="${suggest}"
68+
.value="${communeDeauville}"
69+
/>
70+
`)
71+
})
72+
73+
it('displays the name into the input', async () => {
74+
// Then
75+
const input = screen.getByPlaceholderText(placeholder)
76+
expect(input).toHaveValue('14800 - Deauville')
77+
})
78+
})
79+
describe('and the focuses the input', () => {
80+
it('selects all the content', async () => {
81+
// Given
82+
await fixture(html`
83+
<vmd-commune-or-departement-selector
84+
@on-commune-selected="${onCommuneSelected}"
85+
@on-departement-selected="${onDepartementSelected}"
86+
.suggest="${suggest}"
87+
.value="${communeDeauville}"
88+
/>
89+
`)
90+
const input = screen.getByPlaceholderText(placeholder) as HTMLInputElement
91+
// When
92+
await userEvent.click(input)
93+
await cooldown()
94+
// Then
95+
const selectedText = input.value.substring(input.selectionStart!, input.selectionEnd!)
96+
expect(selectedText).toEqual(input.value)
97+
})
98+
})
99+
})
100+
describe('when no value is given and something typed', () => {
101+
const value = undefined
102+
beforeEach(async () => {
103+
await fixture(html`
104+
<vmd-commune-or-departement-selector
105+
@on-commune-selected="${onCommuneSelected}"
106+
@on-departement-selected="${onDepartementSelected}"
107+
.suggest="${suggest}"
108+
.value="${value}"
109+
/>
110+
`)
111+
})
112+
it('shows suggestions from suggest() attribute', async () => {
113+
// Given
114+
const input = screen.getByPlaceholderText(placeholder)
115+
// When
116+
await userEvent.type(input, 'Cal')
117+
// Then
118+
expect(suggest).toHaveBeenCalledWith('Cal')
119+
expect(await screen.findByRole('listbox')).toBeDefined()
120+
const suggestions = await screen.findAllByRole('option')
121+
expect(suggestions).toHaveLength(2)
122+
expect(suggestions[0]).toHaveTextContent('14 - Calvados')
123+
expect(suggestions[1]).toHaveTextContent('14800 - Deauville')
124+
})
125+
126+
describe('when pressing {enter}', () => {
127+
it('selects the first suggestion', async () => {
128+
// Given
129+
const input = screen.getByPlaceholderText(placeholder)
130+
// When
131+
await userEvent.type(input, 'Cal{enter}', { delay: 20 })
132+
// Then
133+
expect(onDepartementSelected).toHaveBeenCalledTimes(1)
134+
})
135+
describe('after pressing arrow down once', () => {
136+
it('selects the second suggestion', async () => {
137+
// Given
138+
const input = screen.getByPlaceholderText(placeholder)
139+
// When
140+
await userEvent.type(input, 'Cal{arrowdown}{enter}', { delay: 20 })
141+
// Then
142+
expect(onCommuneSelected).toHaveBeenCalledTimes(1)
143+
})
144+
})
145+
})
146+
147+
describe('when a suggestion is clicked', () => {
148+
describe('and is a département', () => {
149+
beforeEach(async () => {
150+
// Given
151+
const input = screen.getByPlaceholderText(placeholder)
152+
// When
153+
await userEvent.type(input, 'Cal')
154+
const [ suggestionCalvados ] = await screen.findAllByRole('option')
155+
await userEvent.click(suggestionCalvados)
156+
})
157+
it("emits 'on-departement-selected'", async () => {
158+
// Then
159+
expect(onCommuneSelected).toHaveBeenCalledTimes(0)
160+
expect(onDepartementSelected).toHaveBeenCalledTimes(1)
161+
expect(onDepartementSelected.mock.calls[0][0].detail).toEqual({
162+
departement: départementCalvados
163+
})
164+
})
165+
it("hides the suggestions", async () => {
166+
// Then
167+
expect(screen.queryByRole('listbox')).toEqual(null)
168+
expect(await screen.queryAllByRole('option')).toHaveLength(0)
169+
})
170+
})
171+
describe('and is a commune', () => {
172+
beforeEach(async () => {
173+
// Given
174+
const input = screen.getByPlaceholderText(placeholder)
175+
// When
176+
await userEvent.type(input, 'Cal')
177+
const [ _, suggestionDeauville ] = await screen.findAllByRole('option')
178+
await userEvent.click(suggestionDeauville)
179+
})
180+
it("emits 'on-commune-selected'", async () => {
181+
// Then
182+
expect(onCommuneSelected).toHaveBeenCalledTimes(1)
183+
expect(onDepartementSelected).toHaveBeenCalledTimes(0)
184+
expect(onCommuneSelected.mock.calls[0][0].detail).toEqual({
185+
commune: communeDeauville
186+
})
187+
})
188+
it("hides the suggestions", async () => {
189+
// Then
190+
expect(screen.queryByRole('listbox')).toEqual(null)
191+
expect(await screen.queryAllByRole('option')).toHaveLength(0)
192+
})
193+
})
194+
})
195+
})
196+
})
197+
198+
const cooldown = () => delay(100)

0 commit comments

Comments
 (0)