Skip to content
This repository was archived by the owner on Feb 10, 2025. It is now read-only.

Commit c9d55b8

Browse files
committed
add: data testids
1 parent 3dafec1 commit c9d55b8

8 files changed

Lines changed: 114 additions & 77 deletions

File tree

apps/admin-ui/src/component/RichTextInput.tsx

Lines changed: 16 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -7,19 +7,6 @@ import "react-quill/dist/quill.snow.css";
77
import styled from "styled-components";
88
import { HorisontalFlex } from "../styles/layout";
99

10-
type Props = {
11-
required?: boolean;
12-
disabled?: boolean;
13-
label?: string;
14-
value: string;
15-
id: string;
16-
onChange: (v: string) => void;
17-
errorText?: string;
18-
tooltipText?: string;
19-
style?: React.CSSProperties;
20-
className?: string;
21-
};
22-
2310
const Container = styled.div<{ $disabled: boolean }>`
2411
.ql-toolbar {
2512
border: none !important;
@@ -81,7 +68,18 @@ const modules = {
8168
toolbar: [["bold"], ["link"]],
8269
};
8370

84-
const RichTextInput = ({
71+
type Props = {
72+
required?: boolean;
73+
disabled?: boolean;
74+
label?: string;
75+
value: string;
76+
id: string;
77+
onChange: (v: string) => void;
78+
errorText?: string;
79+
tooltipText?: string;
80+
} & React.HTMLAttributes<HTMLDivElement>;
81+
82+
function RichTextInput({
8583
value,
8684
required = false,
8785
disabled = false,
@@ -90,16 +88,10 @@ const RichTextInput = ({
9088
errorText,
9189
tooltipText,
9290
onChange,
93-
style,
94-
className,
95-
}: Props): JSX.Element => {
91+
...rest
92+
}: Props): JSX.Element {
9693
return (
97-
<Container
98-
style={style}
99-
className={className}
100-
$disabled={disabled}
101-
id={`${id}-container`}
102-
>
94+
<Container {...rest} $disabled={disabled} id={`${id}-container`}>
10395
<HorisontalFlex style={{ justifyContent: "space-between" }}>
10496
<Label htmlFor={id}>
10597
{label} {required ? <Asterix>*</Asterix> : null}
@@ -124,6 +116,6 @@ const RichTextInput = ({
124116
)}
125117
</Container>
126118
);
127-
};
119+
}
128120

129121
export default RichTextInput;

apps/admin-ui/src/component/my-units/UnitCalendar.tsx

Lines changed: 42 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -199,7 +199,7 @@ const Container = styled.div<{ $height: number }>`
199199
height: ${({ $height }) => $height}px;
200200
`;
201201

202-
const Cells = ({
202+
function Cells({
203203
cols,
204204
reservationUnitPk,
205205
date,
@@ -211,7 +211,7 @@ const Cells = ({
211211
date: Date;
212212
setModalContent: (content: JSX.Element | null, isHds?: boolean) => void;
213213
onComplete: () => void;
214-
}) => {
214+
}) {
215215
const now = new Date();
216216

217217
const isPast = (index: number) => {
@@ -234,14 +234,21 @@ const Cells = ({
234234
);
235235
};
236236

237+
const testId = `UnitCalendar__RowCalendar--cells-${reservationUnitPk}`;
238+
const cellTestId = `UnitCalendar__RowCalendar--cell-${reservationUnitPk}`;
237239
return (
238-
<CellContent $numCols={cols}>
240+
<CellContent $numCols={cols} data-testid={testId}>
239241
{Array.from(Array(cols).keys()).map((i) => (
240-
<Cell key={i} onClick={onClick(i)} $isPast={isPast(i)} />
242+
<Cell
243+
key={i}
244+
onClick={onClick(i)}
245+
$isPast={isPast(i)}
246+
data-testid={`${cellTestId}-${i}`}
247+
/>
241248
))}
242249
</CellContent>
243250
);
244-
};
251+
}
245252
const PreBuffer = ({
246253
event,
247254
hourPercent,
@@ -274,7 +281,7 @@ const PreBuffer = ({
274281
return null;
275282
};
276283

277-
const PostBuffer = ({
284+
function PostBuffer({
278285
event,
279286
hourPercent,
280287
right,
@@ -284,27 +291,28 @@ const PostBuffer = ({
284291
hourPercent: number;
285292
right: string;
286293
style?: CSSProperties;
287-
}): JSX.Element | null => {
294+
}): JSX.Element | null {
288295
const buffer = event.event?.bufferTimeAfter;
289296
const { t } = useTranslation();
290297

291-
if (buffer) {
292-
const width = `calc(${(hourPercent * buffer) / 3600}% - 1px)`;
293-
return (
294-
<div
295-
style={{
296-
...POST_PAUSE.style,
297-
...style,
298-
left: right,
299-
width,
300-
}}
301-
title={t("MyUnits.Calendar.legend.pause")}
302-
key={`${event.event?.pk}-post`}
303-
/>
304-
);
298+
if (buffer == null) {
299+
return null;
305300
}
306-
return null;
307-
};
301+
302+
const width = `calc(${(hourPercent * buffer) / 3600}% - 1px)`;
303+
return (
304+
<div
305+
style={{
306+
...POST_PAUSE.style,
307+
...style,
308+
left: right,
309+
width,
310+
}}
311+
title={t("MyUnits.Calendar.legend.pause")}
312+
key={`${event.event?.pk}-post`}
313+
/>
314+
);
315+
}
308316

309317
function getEventTitle({
310318
reservation: { title, event },
@@ -342,7 +350,7 @@ const EventContainer = styled.div`
342350
left: 0;
343351
`;
344352

345-
const Events = ({
353+
function Events({
346354
firstHour,
347355
events,
348356
eventStyleGetter,
@@ -352,10 +360,10 @@ const Events = ({
352360
events: CalendarEventType[];
353361
eventStyleGetter: EventStyleGetter;
354362
numHours: number;
355-
}) => {
363+
}) {
356364
const { t } = useTranslation();
357365
return (
358-
<EventContainer>
366+
<EventContainer data-testid="UnitCalendar__RowCalendar--events">
359367
{events.map((e) => {
360368
const title = getEventTitle({ reservation: e, t });
361369
const startDate = new Date(e.start);
@@ -377,6 +385,7 @@ const Events = ({
377385
100 / numHours
378386
}% + 1px)`;
379387

388+
const testId = `UnitCalendar__RowCalendar--event-${e.event?.pk}`;
380389
return (
381390
<Fragment key={`${title}-${startDate.toISOString()}`}>
382391
<PreBuffer
@@ -395,7 +404,10 @@ const Events = ({
395404
zIndex: 5,
396405
}}
397406
>
398-
<EventContent style={{ ...eventStyleGetter(e).style }}>
407+
<EventContent
408+
style={{ ...eventStyleGetter(e).style }}
409+
data-testid={testId}
410+
>
399411
<p>{title}</p>
400412
{/* NOTE don't set position on Popup it breaks responsiveness */}
401413
<Popup trigger={EventTriggerButton}>
@@ -414,16 +426,16 @@ const Events = ({
414426
})}
415427
</EventContainer>
416428
);
417-
};
429+
}
418430

419-
const sortByDraftStatusAndTitle = (resources: Resource[]) => {
431+
function sortByDraftStatusAndTitle(resources: Resource[]) {
420432
return resources.sort((a, b) => {
421433
const draftComparison: number = Number(a.isDraft) - Number(b.isDraft);
422434
const titleComparison = sortByName(a.title, b.title);
423435

424436
return draftComparison || titleComparison;
425437
});
426-
};
438+
}
427439

428440
function UnitCalendar({ date, resources, refetch }: Props): JSX.Element {
429441
const calendarRef = useRef<HTMLDivElement>(null);

apps/admin-ui/src/component/my-units/create-reservation/CreateReservationModal.tsx

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,7 @@ const CollisionWarning = ({
144144
) : null;
145145
};
146146

147-
const ActionContainer = ({
147+
function ActionContainer({
148148
form,
149149
reservationUnit,
150150
onCancel,
@@ -154,7 +154,7 @@ const ActionContainer = ({
154154
reservationUnit: ReservationUnitType;
155155
onCancel: () => void;
156156
onSubmit: (values: FormValueType) => void;
157-
}) => {
157+
}) {
158158
const { t } = useTranslation();
159159
const {
160160
handleSubmit,
@@ -168,7 +168,13 @@ const ActionContainer = ({
168168
return (
169169
<ActionButtons>
170170
<CollisionWarning form={form} reservationUnit={reservationUnit} />
171-
<Button size="small" variant="secondary" onClick={onCancel} theme="black">
171+
<Button
172+
size="small"
173+
variant="secondary"
174+
onClick={onCancel}
175+
theme="black"
176+
data-testid="CreateReservationModal__cancel-reservation"
177+
>
172178
{t("common.cancel")}
173179
</Button>
174180
<Button
@@ -178,12 +184,13 @@ const ActionContainer = ({
178184
onClick={() => {
179185
handleSubmit(onSubmit)();
180186
}}
187+
data-testid="CreateReservationModal__accept-reservation"
181188
>
182189
{t("ReservationDialog.accept")}
183190
</Button>
184191
</ActionButtons>
185192
);
186-
};
193+
}
187194

188195
const DialogContent = ({
189196
onClose,

apps/admin-ui/src/component/notifications/page.tsx

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ import ControlledDateInput from "../my-units/components/ControlledDateInput";
5050
import ControlledTimeInput from "../my-units/components/ControlledTimeInput";
5151
import { base64encode } from "common/src/helpers";
5252

53-
const RichTextInput = dynamic(() => import("app/component/RichTextInput"), {
53+
const RichTextInput = dynamic(() => import("@/component/RichTextInput"), {
5454
ssr: false,
5555
});
5656

@@ -494,6 +494,7 @@ const NotificationForm = ({
494494
label={t("headings.name")}
495495
style={{ gridColumn: "1 / -1" }}
496496
errorText={translateError(errors.name?.message)}
497+
data-testid="Notification__Page--name-input"
497498
/>
498499
<Controller
499500
control={control}
@@ -555,6 +556,7 @@ const NotificationForm = ({
555556
: undefined
556557
}
557558
required
559+
data-testid="Notification__Page--message-fi-input"
558560
/>
559561
)}
560562
/>
@@ -568,6 +570,7 @@ const NotificationForm = ({
568570
style={{ gridColumn: "1 / -1" }}
569571
onChange={(val) => onChange(val)}
570572
value={value}
573+
data-testid="Notification__Page--message-en-input"
571574
/>
572575
)}
573576
/>
@@ -581,6 +584,7 @@ const NotificationForm = ({
581584
style={{ gridColumn: "1 / -1" }}
582585
onChange={(val) => onChange(val)}
583586
value={value}
587+
data-testid="Notification__Page--message-sv-input"
584588
/>
585589
)}
586590
/>
@@ -591,6 +595,7 @@ const NotificationForm = ({
591595
size="large"
592596
to=".."
593597
style={{ marginRight: "auto" }}
598+
data-testid="Notification__Page--cancel-button"
594599
>
595600
{t("form.cancel")}
596601
</ButtonLikeLink>
@@ -602,12 +607,17 @@ const NotificationForm = ({
602607
setValue("isDraft", true);
603608
handleSubmit(onSubmit)();
604609
}}
610+
data-testid="Notification__Page--save-draft-button"
605611
>
606612
{t("form.saveDraft")}
607613
</Button>
608614
</InnerButtons>
609615
<div>
610-
<Button style={{ marginLeft: "auto" }} type="submit">
616+
<Button
617+
style={{ marginLeft: "auto" }}
618+
type="submit"
619+
data-testid="Notification__Page--publish-button"
620+
>
611621
{t("form.save")}
612622
</Button>
613623
</div>

apps/admin-ui/src/component/reservations/requested/RequestedReservation.tsx

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ import { useRecurringReservations, useReservationData } from "./hooks";
4242
import ApprovalButtonsRecurring from "./ApprovalButtonsRecurring";
4343
import ReservationTitleSection from "./ReservationTitleSection";
4444
import { base64encode } from "common/src/helpers";
45+
import { fontMedium } from "common";
4546

4647
type ReservationType = NonNullable<ReservationQuery["reservation"]>;
4748

@@ -66,20 +67,31 @@ const Summary = styled(ApplicationDatas)`
6667
}
6768
`;
6869

69-
const ApplicationProp = ({
70+
const PropValue = styled.span`
71+
white-space: pre-wrap;
72+
${fontMedium}
73+
`;
74+
function ApplicationProp({
7075
label,
7176
data,
7277
wide,
7378
}: {
7479
label: string;
7580
data?: Maybe<string> | number;
7681
wide?: boolean;
77-
}) =>
78-
data ? (
82+
}) {
83+
if (data == null) {
84+
return null;
85+
}
86+
return (
7987
<div style={{ gridColumn: wide ? "1 / -1" : "" }}>
80-
{label}: <strong style={{ whiteSpace: "pre-wrap" }}>{data}</strong>
88+
{label}:{" "}
89+
<PropValue data-testid={`reservation__summary--${label}`}>
90+
{data}
91+
</PropValue>
8192
</div>
82-
) : null;
93+
);
94+
}
8395

8496
// Need to set max-width otherwise word-break doesn't work, different max-width because of the side menu.
8597
const KVPair = styled.div<{ $wide?: boolean }>`

0 commit comments

Comments
 (0)