Skip to content

Commit 513f54b

Browse files
Jan Jaap van DeursenMaurits RidderMauritsRboris-arkenaar
authored
Release/v1.65.0 (#1842)
* Prevent breaking app when browser (cookie/local/session) storage is disabled * Prevent error when incident location is null * Adds array flatMap polyfill * Improves incident-list type * Change core-js polyfill to local polyfill * Notify userwhen login fails * (Chore) Empty ref fix * (Chore) AbortController sub * [SIG-4035] Convert categories model to TS * Converts category model selectors to TS * Fixes tests * Corrects mock implementation for incident detail * Changes type * Corrects type errors * Removes debugger statement * Fixes another round of types * Adds App mode ADR * (Chore) cleanup same-area spec * Removes flakiness from test; disables unreliable e2e test * Removes commented line * Fixes incident type to prevent type errors * Removes faker package * [SIG-3824] End status styling * Adds global css class for incident status styling * Fixes type error * Fixes test * Creates separate Status component * Removes outdated test cases * - adds data-testid attributes to elements for better QA targeting - removes style-specific integration tests; not the responsibility of the e2e-tests * Adds api url where msw request handler is used * Fixes unit test errors * (Chore) Improve tsconfig (#1830) Makes sure that only TS files are included in the list of files to parse by the compiler * [SIG-3281] Show number of chars for textarea (#1829) * Adds separate AddNote components Corrects types Moves components to different scope * Fixes types for register ref * Corrects Select prop type * Adds complete coverage for AddNote component * Adds SelectLoader component * Prefers defaultValue over value when instantiating TextArea component * Allows for configurable field name in getError for note. * Deletes temp files * Replaces register prop with onChange handler * Replaces register prop with onChange handler for IncidentSplitRadioInput component * Refactors addNote error function so that it is no longer a higher order function * Renders IncidentSplitFormIncident tests in context provider * Makes sure incident detail AddNote component calls error function correctly * Upgrades react-hook-form to latest stable * Adjusts IncidentReplyContainer components to work with the new version of react-hook-form * Removes generic AddNote component to top level components folder * Converts StatusForm related imports to TS and corrects types accordingly * Corrects types for Status and context * Increases default test timeout because of slow tests in FilterForm * Removes memo from internal FilterForm components * Makes sure value updates are reflected by the textarea element * Uses form context provider for incident split form * Corrects condition in category selectors * Ensures correct types for IncidentDetail components * Ensures correct type usage * Moves default texts styled components into their own file * Removes empty test case * Corrects Coordinates type * Ensures cleanup after each test case for useFetchReporter hook * Removes unused file * (Chore) Improve page rendering speed (#1831) * (Chore) Improve page rendering speed Sets the `contain` CSS property on several elements to improve the in-page rendering. See https://css-tricks.com/almanac/properties/c/contain/ for reference. * Adds one more contain rule * Update PDOK WMTS service endpoint (#1832) * [FE#92] Asset selector (#1820) * Copy container selector * Make the asset select usable * Make the language configurable * Make the wfs endpoint more flexible * Remove obsolete context * Add fallback icon config * Update unit tests * Use single curly brace in endpoint * Remove memo * Fix typing * Sync/master develop (#1838) * Release/v1.63.0 (#1828) * Prevent breaking app when browser (cookie/local/session) storage is disabled * Prevent error when incident location is null * Adds array flatMap polyfill * Improves incident-list type * Change core-js polyfill to local polyfill * Notify userwhen login fails * (Chore) Empty ref fix * (Chore) AbortController sub * [SIG-4035] Convert categories model to TS * Converts category model selectors to TS * Fixes tests * Corrects mock implementation for incident detail * Changes type * Corrects type errors * Removes debugger statement * Fixes another round of types * Adds App mode ADR * (Chore) cleanup same-area spec * Removes flakiness from test; disables unreliable e2e test * Removes commented line * Fixes incident type to prevent type errors * Removes faker package * [SIG-3824] End status styling * Adds global css class for incident status styling * Fixes type error * Fixes test * Creates separate Status component * Removes outdated test cases * - adds data-testid attributes to elements for better QA targeting - removes style-specific integration tests; not the responsibility of the e2e-tests * Adds api url where msw request handler is used * Fixes unit test errors Co-authored-by: Maurits Ridder <maurits.ridder@amsterdam.nl> Co-authored-by: Maurits <10672773+MauritsR@users.noreply.github.com> * Update PDOK WMTS service endpoint (#1832) * Reverts conversion to object * Increments node version * Reverts packages update Co-authored-by: Maurits <10672773+MauritsR@users.noreply.github.com> Co-authored-by: Maurits Ridder <maurits.ridder@amsterdam.nl> Co-authored-by: Boris Arkenaar <boris@arkenaar.com> * Reverts package lock changes Co-authored-by: Maurits Ridder <maurits.ridder@amsterdam.nl> Co-authored-by: Maurits <10672773+MauritsR@users.noreply.github.com> Co-authored-by: Boris Arkenaar <boris@arkenaar.com>
1 parent af9c629 commit 513f54b

File tree

136 files changed

+4978
-1359
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

136 files changed

+4978
-1359
lines changed

e2e-tests/cypress/support/signal.d.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ declare namespace signal {
1616

1717
export interface Geometrie {
1818
type: string;
19-
coordinates: number[];
19+
coordinates: [number, number];
2020
}
2121

2222
export interface Address {

jest.config.js

+1
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ module.exports = {
3838
'<rootDir>/internals/testing/test-bundler.ts',
3939
'<rootDir>/internals/testing/jest-setup-msw.ts',
4040
],
41+
testTimeout: 10000,
4142
testEnvironment: 'jsdom',
4243
transform: {
4344
'^.+\\.(j|t)s(x?)$': [

package-lock.json

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

package.json

+3-3
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,6 @@
4747
"@datapunt/leaflet-geojson-bbox-layer": "0.1.1",
4848
"@datapunt/matomo-tracker-js": "^0.5.1",
4949
"@sentry/browser": "^6.8.0",
50-
"@types/mini-css-extract-plugin": "^2.3.0",
5150
"classnames": "^2.2.6",
5251
"connected-react-router": "^6.9.1",
5352
"date-fns": "^2.19.0",
@@ -65,7 +64,7 @@
6564
"react-albus": "^2.0.0",
6665
"react-datepicker": "^3.6.0",
6766
"react-dom": "^17.0.2",
68-
"react-hook-form": "^6.15.5",
67+
"react-hook-form": "^7.17.5",
6968
"react-markdown": "^6.0.2",
7069
"react-media": "^1.10.0",
7170
"react-reactive-form": "1.0.27",
@@ -106,6 +105,7 @@
106105
"@types/leaflet": "^1.7.0",
107106
"@types/leaflet.markercluster": "^1.4.4",
108107
"@types/lodash": "^4.14.168",
108+
"@types/mini-css-extract-plugin": "^2.3.0",
109109
"@types/node": "^16.9.0",
110110
"@types/react": "^17.0.5",
111111
"@types/react-datepicker": "^3.1.8",
@@ -184,7 +184,7 @@
184184
"svg-url-loader": "^7.1.1",
185185
"ts-jest": "^27.0.3",
186186
"ts-loader": "^9.2.3",
187-
"typescript": "^4.3.5",
187+
"typescript": "^4.4.4",
188188
"typescript-plugin-styled-components": "^1.6.0",
189189
"url-loader": "^4.1.1",
190190
"webpack": "^5.28.0",
+201
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,201 @@
1+
// SPDX-License-Identifier: MPL-2.0
2+
// Copyright (C) 2018 - 2021 Gemeente Amsterdam
3+
import { createRef } from 'react'
4+
import { render, fireEvent, screen } from '@testing-library/react'
5+
import userEvent from '@testing-library/user-event'
6+
7+
import { withAppContext } from 'test/utils'
8+
9+
import AddNote, { getAddNoteError } from '.'
10+
11+
const ref = createRef<HTMLTextAreaElement>()
12+
13+
describe('getNoteError', () => {
14+
it('returns a max length error', () => {
15+
const maxContentLength = 42
16+
expect(getAddNoteError({ maxContentLength, text: ' ' })).toEqual(
17+
'De notitie mag niet leeg zijn'
18+
)
19+
expect(
20+
getAddNoteError({
21+
maxContentLength,
22+
text: Array(maxContentLength + 2).join('.'),
23+
})
24+
).toEqual(
25+
`Je hebt meer dan de maximale ${maxContentLength} tekens ingevoerd.`
26+
)
27+
expect(
28+
getAddNoteError({ maxContentLength, text: 'Hic sunt dracones' })
29+
).toEqual('')
30+
31+
expect(
32+
getAddNoteError({
33+
maxContentLength,
34+
text: ' ',
35+
shouldContainAtLeastOneChar: false,
36+
})
37+
).toEqual('')
38+
})
39+
})
40+
41+
describe('AddNote', () => {
42+
it('shows the form ', () => {
43+
render(withAppContext(<AddNote />))
44+
45+
expect(screen.getByTestId('addNoteNewNoteButton')).toBeInTheDocument()
46+
expect(
47+
screen.queryByTestId('addNoteSaveNoteButton')
48+
).not.toBeInTheDocument()
49+
50+
userEvent.click(screen.getByTestId('addNoteNewNoteButton'))
51+
52+
expect(screen.getByTestId('addNoteSaveNoteButton')).toBeInTheDocument()
53+
expect(screen.queryByTestId('addNoteNewNoteButton')).not.toBeInTheDocument()
54+
expect(screen.getByTestId('addNoteCancelNoteButton')).toBeInTheDocument()
55+
56+
userEvent.click(screen.getByTestId('addNoteCancelNoteButton'))
57+
58+
expect(
59+
screen.queryByTestId('addNoteSaveNoteButton')
60+
).not.toBeInTheDocument()
61+
expect(
62+
screen.queryByTestId('addNoteCancelNoteButton')
63+
).not.toBeInTheDocument()
64+
expect(screen.queryByTestId('addNoteNewNoteButton')).toBeInTheDocument()
65+
})
66+
67+
it('focuses the textarea', () => {
68+
const { unmount, rerender } = render(withAppContext(<AddNote />))
69+
70+
// no ref, no focus
71+
userEvent.click(screen.getByTestId('addNoteNewNoteButton'))
72+
expect(screen.getByRole('textbox')).not.toHaveFocus()
73+
74+
unmount()
75+
76+
// not standalone, no focus
77+
rerender(withAppContext(<AddNote ref={ref} isStandalone={false} />))
78+
expect(screen.getByRole('textbox')).not.toHaveFocus()
79+
80+
unmount()
81+
82+
// standalone, setting focus on render
83+
rerender(withAppContext(<AddNote ref={ref} />))
84+
userEvent.click(screen.getByTestId('addNoteNewNoteButton'))
85+
expect(screen.getByRole('textbox')).toHaveFocus()
86+
})
87+
88+
it('calls onChange', () => {
89+
const onChange = jest.fn()
90+
91+
render(withAppContext(<AddNote onChange={onChange} />))
92+
93+
expect(onChange).not.toHaveBeenCalled()
94+
95+
userEvent.click(screen.getByTestId('addNoteNewNoteButton'))
96+
97+
userEvent.type(screen.getByRole('textbox'), 'Here be text')
98+
99+
expect(onChange).toHaveBeenCalledTimes(12)
100+
expect(onChange).toHaveBeenLastCalledWith(
101+
expect.objectContaining({
102+
target: expect.objectContaining({ value: 'Here be text' }),
103+
})
104+
)
105+
106+
// nothing should happen; onSubmit isn't passed as a prop
107+
userEvent.click(screen.getByTestId('addNoteSaveNoteButton'))
108+
109+
expect(onChange).toHaveBeenCalledTimes(12)
110+
})
111+
112+
it('calls onSubmit', () => {
113+
const onSubmit = jest.fn()
114+
115+
const { rerender } = render(withAppContext(<AddNote onSubmit={onSubmit} />))
116+
117+
userEvent.click(screen.getByTestId('addNoteNewNoteButton'))
118+
userEvent.type(screen.getByRole('textbox'), 'Here be text 2')
119+
120+
expect(onSubmit).not.toHaveBeenCalled()
121+
122+
userEvent.click(screen.getByTestId('addNoteSaveNoteButton'))
123+
124+
expect(onSubmit).toHaveBeenCalledTimes(1)
125+
expect(onSubmit).toHaveBeenCalledWith(
126+
expect.anything(),
127+
// the field's value will not be passed, because there is no ref to attach it to
128+
undefined
129+
)
130+
131+
rerender(withAppContext(<AddNote onSubmit={onSubmit} ref={ref} />))
132+
133+
userEvent.clear(screen.getByRole('textbox'))
134+
userEvent.type(screen.getByRole('textbox'), 'Here be text 2')
135+
userEvent.click(screen.getByTestId('addNoteSaveNoteButton'))
136+
137+
expect(onSubmit).toHaveBeenCalledTimes(2)
138+
expect(onSubmit).toHaveBeenLastCalledWith(
139+
expect.anything(),
140+
'Here be text 2'
141+
)
142+
})
143+
144+
it('hides the form after submit', () => {
145+
const submitWillNotHide = jest.fn(() => false)
146+
147+
const { rerender } = render(
148+
withAppContext(<AddNote onSubmit={submitWillNotHide} />)
149+
)
150+
151+
userEvent.click(screen.getByTestId('addNoteNewNoteButton'))
152+
userEvent.type(screen.getByRole('textbox'), 'Here be text 3')
153+
userEvent.click(screen.getByTestId('addNoteSaveNoteButton'))
154+
155+
expect(submitWillNotHide).toHaveBeenCalledTimes(1)
156+
157+
expect(screen.getByRole('textbox')).toBeInTheDocument()
158+
159+
const submitWillHide = jest.fn(() => true)
160+
161+
rerender(withAppContext(<AddNote onSubmit={submitWillHide} />))
162+
163+
userEvent.click(screen.getByTestId('addNoteSaveNoteButton'))
164+
165+
expect(submitWillHide).toHaveBeenCalledTimes(1)
166+
167+
expect(screen.queryByRole('textbox')).not.toBeInTheDocument()
168+
})
169+
170+
it('clears the textarea', () => {
171+
render(withAppContext(<AddNote />))
172+
173+
const value = 'Here be a note'
174+
175+
userEvent.click(screen.getByTestId('addNoteNewNoteButton'))
176+
177+
const addNoteTextArea = screen.getByRole('textbox') as HTMLTextAreaElement
178+
179+
userEvent.type(addNoteTextArea, value)
180+
181+
expect(screen.getByRole('textbox')).not.toBeEmptyDOMElement()
182+
183+
fireEvent.click(screen.getByTestId('addNoteCancelNoteButton')) // unmounts the component
184+
userEvent.click(screen.getByTestId('addNoteNewNoteButton'))
185+
186+
expect(screen.getByRole('textbox')).toBeEmptyDOMElement()
187+
})
188+
189+
it('renders the inline version', () => {
190+
render(withAppContext(<AddNote isStandalone={false} />))
191+
192+
expect(screen.getByTestId('addNoteText')).toBeInTheDocument()
193+
expect(screen.queryByTestId('addNoteNewNoteButton')).not.toBeInTheDocument()
194+
expect(
195+
screen.queryByTestId('addNoteSaveNoteButton')
196+
).not.toBeInTheDocument()
197+
expect(
198+
screen.queryByTestId('addNoteCancelNoteButton')
199+
).not.toBeInTheDocument()
200+
})
201+
})

0 commit comments

Comments
 (0)