Skip to content

Commit 1203969

Browse files
committed
Fixed a couple of broken (or brittle) tests
1 parent 3a86a24 commit 1203969

File tree

13 files changed

+113
-74
lines changed

13 files changed

+113
-74
lines changed

web-ui/src/components/notes/Note.jsx

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,8 @@ const Notes = props => {
5151
res.payload && res.payload.data && res.payload.data.length > 0
5252
? res.payload.data[0]
5353
: null;
54+
console.log(JSON.stringify(res));
55+
console.log(currentNote);
5456
if (currentNote) {
5557
setNote(currentNote);
5658
} else if (currentUserId === pdlId) {
@@ -100,7 +102,7 @@ const Notes = props => {
100102
}
101103

102104
setNote(note => {
103-
const newNote = { ...note, description: content };
105+
const newNote = { ...note, description: content };
104106
updateNote(newNote, csrf);
105107
return newNote;
106108
});
@@ -124,6 +126,8 @@ const Notes = props => {
124126
</div>
125127
</div>
126128
) : (
129+
<>
130+
<div style={{display:"none"}} data-testid="tiny-mce-checkin-notes" />
127131
<Editor
128132
apiKey="246ojmsp6c7qtnr9aoivktvi3mi5t7ywuf0vevn6wllfcn9e"
129133
id="tiny-mce-checkin-notes"
@@ -147,6 +151,7 @@ const Notes = props => {
147151
import.meta.env.VITE_APP_API_URL + '/js/tinymce/tinymce.min.js'
148152
}
149153
/>
154+
</>
150155
)}
151156
</CardContent>
152157
</Card>

web-ui/src/components/notes/Note.test.jsx

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ import Notes from './Note';
33
import { AppContextProvider } from '../../context/AppContext';
44
import { createMemoryHistory } from 'history';
55
import { Router } from 'react-router-dom';
6+
import { setupServer } from 'msw/node';
7+
import { http, HttpResponse } from 'msw';
68

79
const mockMemberId = '912834091823';
810
const mockCheckinId = '837465917381';
@@ -29,6 +31,7 @@ const checkin = {
2931

3032
const initialState = {
3133
state: {
34+
csrf: 'fake-csrf',
3235
userProfile: {
3336
name: 'holmes',
3437
memberProfile: {
@@ -54,8 +57,25 @@ const initialState = {
5457
}
5558
};
5659

57-
it('renders correctly', () => {
58-
snapshot(
60+
const notes = [
61+
{
62+
id: 'note-1',
63+
description: 'Some kind of note...'
64+
}
65+
];
66+
67+
const server = setupServer(
68+
http.get(`http://localhost:8080/services/checkin-notes?checkinid=${checkin.id}`, () => {
69+
return HttpResponse.json(notes);
70+
}),
71+
);
72+
73+
beforeAll(() => server.listen({ onUnhandledRequest(request, print) {} }));
74+
afterEach(() => server.resetHandlers());
75+
afterAll(() => server.close());
76+
77+
it('renders correctly', async () => {
78+
await waitForSnapshot('tiny-mce-checkin-notes',
5979
<Router history={history}>
6080
<AppContextProvider value={initialState}>
6181
<Notes

web-ui/src/components/notes/__snapshots__/Note.test.jsx.snap

Lines changed: 7 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -38,29 +38,13 @@ exports[`renders correctly 1`] = `
3838
class="MuiCardContent-root css-1lt5qva-MuiCardContent-root"
3939
>
4040
<div
41-
class="container"
42-
>
43-
<div
44-
class="skeleton"
45-
>
46-
<span
47-
class="MuiSkeleton-root MuiSkeleton-text MuiSkeleton-pulse css-kkcbhd-MuiSkeleton-root"
48-
style="height: 2rem;"
49-
/>
50-
<span
51-
class="MuiSkeleton-root MuiSkeleton-text MuiSkeleton-pulse css-kkcbhd-MuiSkeleton-root"
52-
style="height: 2rem;"
53-
/>
54-
<span
55-
class="MuiSkeleton-root MuiSkeleton-text MuiSkeleton-pulse css-kkcbhd-MuiSkeleton-root"
56-
style="height: 2rem;"
57-
/>
58-
<span
59-
class="MuiSkeleton-root MuiSkeleton-text MuiSkeleton-pulse css-kkcbhd-MuiSkeleton-root"
60-
style="height: 2rem;"
61-
/>
62-
</div>
63-
</div>
41+
data-testid="tiny-mce-checkin-notes"
42+
style="display: none;"
43+
/>
44+
<textarea
45+
id="tiny-mce-checkin-notes"
46+
style="visibility: hidden;"
47+
/>
6448
</div>
6549
</div>
6650
</div>

web-ui/src/components/private-note/PrivateNote.jsx

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,8 @@ const PrivateNote = () => {
162162
</div>
163163
</div>
164164
) : (
165+
<>
166+
<div style={{ display: "none" }} data-testid="tiny-mce-checkin-private-notes" />
165167
<Editor
166168
apiKey="246ojmsp6c7qtnr9aoivktvi3mi5t7ywuf0vevn6wllfcn9e"
167169
id="tiny-mce-checkin-private-notes"
@@ -185,11 +187,12 @@ const PrivateNote = () => {
185187
import.meta.env.VITE_APP_API_URL + '/js/tinymce/tinymce.min.js'
186188
}
187189
/>
188-
)}
189-
</CardContent>
190-
</Card>
191-
)
192-
);
193-
};
190+
</>
191+
)}
192+
</CardContent>
193+
</Card>
194+
)
195+
);
196+
};
194197

195-
export default PrivateNote;
198+
export default PrivateNote;

web-ui/src/components/private-note/PrivateNote.test.jsx

Lines changed: 35 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,12 @@ import PrivateNote from './PrivateNote';
33
import { AppContextProvider } from '../../context/AppContext';
44
import { createMemoryHistory } from 'history';
55
import { Router } from 'react-router-dom';
6+
import { setupServer } from 'msw/node';
7+
import { http, HttpResponse } from 'msw';
68

79
const mockMemberId = '912834091823';
810
const mockCheckinId = '837465917381';
11+
const mockUserId = '8714123864231';
912

1013
const history = createMemoryHistory(
1114
`/checkins/${mockMemberId}/${mockCheckinId}`
@@ -29,19 +32,15 @@ const checkin = {
2932

3033
const initialState = {
3134
state: {
35+
csrf: 'fake-csrf',
3236
userProfile: {
33-
name: 'holmes',
34-
memberProfile: {
35-
id: mockMemberId,
36-
pdlId: '',
37-
title: 'Tester',
38-
workEmail: '[email protected]'
39-
},
40-
role: ['MEMBER'],
37+
name: 'joe pdl',
38+
id: mockUserId,
39+
role: ['PDL'],
4140
permissions: [
4241
{
4342
id: 1,
44-
permission: 'CAN_ADMINISTER_CHECKIN_DOCUMENTS',
43+
permission: 'CAN_VIEW_PRIVATE_NOTE',
4544
description: ''
4645
}
4746
],
@@ -52,17 +51,41 @@ const initialState = {
5251
{
5352
name: 'holmes',
5453
id: mockMemberId,
55-
pdlId: '',
54+
pdlId: mockUserId,
5655
title: 'Tester',
5756
workEmail: '[email protected]'
57+
},
58+
{
59+
name: 'joe pdl',
60+
id: mockUserId,
61+
pdlId: '',
62+
title: 'Tester',
63+
workEmail: '[email protected]'
5864
}
5965
],
6066
checkins: [checkin]
6167
}
6268
};
6369

64-
it('renders correctly', () => {
65-
snapshot(
70+
const notes = [
71+
{
72+
id: 'note-1',
73+
description: 'Some kind of note...'
74+
}
75+
];
76+
77+
const server = setupServer(
78+
http.get(`http://localhost:8080/services/private-notes?checkinid=${checkin.id}`, () => {
79+
return HttpResponse.json(notes);
80+
}),
81+
);
82+
83+
beforeAll(() => server.listen({ onUnhandledRequest(request, print) {} }));
84+
afterEach(() => server.resetHandlers());
85+
afterAll(() => server.close());
86+
87+
it('renders correctly', async () => {
88+
await waitForSnapshot('tiny-mce-checkin-private-notes',
6689
<Router history={history}>
6790
<AppContextProvider value={initialState}>
6891
<PrivateNote

web-ui/src/components/private-note/__snapshots__/PrivateNote.test.jsx.snap

Lines changed: 7 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -38,29 +38,13 @@ exports[`renders correctly 1`] = `
3838
class="MuiCardContent-root css-1lt5qva-MuiCardContent-root"
3939
>
4040
<div
41-
class="container"
42-
>
43-
<div
44-
class="skeleton"
45-
>
46-
<span
47-
class="MuiSkeleton-root MuiSkeleton-text MuiSkeleton-pulse css-kkcbhd-MuiSkeleton-root"
48-
style="height: 2rem;"
49-
/>
50-
<span
51-
class="MuiSkeleton-root MuiSkeleton-text MuiSkeleton-pulse css-kkcbhd-MuiSkeleton-root"
52-
style="height: 2rem;"
53-
/>
54-
<span
55-
class="MuiSkeleton-root MuiSkeleton-text MuiSkeleton-pulse css-kkcbhd-MuiSkeleton-root"
56-
style="height: 2rem;"
57-
/>
58-
<span
59-
class="MuiSkeleton-root MuiSkeleton-text MuiSkeleton-pulse css-kkcbhd-MuiSkeleton-root"
60-
style="height: 2rem;"
61-
/>
62-
</div>
63-
</div>
41+
data-testid="tiny-mce-checkin-private-notes"
42+
style="display: none;"
43+
/>
44+
<textarea
45+
id="tiny-mce-checkin-private-notes"
46+
style="visibility: hidden;"
47+
/>
6448
</div>
6549
</div>
6650
</div>

web-ui/src/context/reducer.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -170,9 +170,9 @@ export const reducer = (state, action) => {
170170
state.teams = action.payload;
171171
//sort by name
172172
state.teams.sort((a, b) => a.name.localeCompare(b.name));
173-
break;
173+
breadk;
174174
case UPDATE_TEAMS_LOADING:
175-
state.loading = { ...state.loading, teams: !state.loading.teams };
175+
state.loading = { ...state.loading, teams: !state?.loading?.teams };
176176
break;
177177
case UPDATE_PEOPLE_LOADING:
178178
state.loading = { ...state.loading, memberProfiles: action.payload };

web-ui/src/pages/CheckinsPage.test.jsx

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,10 +70,20 @@ const mockuments = [
7070
}
7171
];
7272

73+
const notes = [
74+
{
75+
id: 'note-1',
76+
description: 'Some kind of note...'
77+
}
78+
];
79+
7380
const server = setupServer(
7481
http.get('http://localhost:8080/services/document/1', () => {
7582
return HttpResponse.json(mockuments);
76-
})
83+
}),
84+
http.get(`http://localhost:8080/services/checkin-notes?checkinid=${mockCheckinId}`, () => {
85+
return HttpResponse.json(notes);
86+
}),
7787
);
7888

7989
beforeAll(() => server.listen({ onUnhandledRequest(request, print) {} }));
@@ -99,7 +109,7 @@ global.requestAnimationFrame = function (callback) {
99109

100110
it('renders correctly', async () => {
101111
await waitForSnapshot(
102-
'mockument-2',
112+
'tiny-mce-checkin-notes',
103113
<LocalizationProvider dateAdapter={AdapterDateFns}>
104114
<Router history={history}>
105115
<AppContextProvider value={initialState}>

web-ui/src/pages/FeedbackSubmitPage.jsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,7 @@ const FeedbackSubmitPage = () => {
170170
return (
171171
<Root data-testid={requestQuery} className="feedback-submit-page">
172172
{requestCanceled ? (
173-
<Typography className={classes.announcement} variant="h3">
173+
<Typography data-testid={requestQuery+"-canceled"} className={classes.announcement} variant="h3">
174174
This feedback request has been canceled.
175175
</Typography>
176176
) : tabs || requestSubmitted || selfReviewRequest ? (

web-ui/src/pages/FeedbackSubmitPage.test.jsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ it('renders correctly - submitted', async () => {
8282

8383
it('renders correctly - canceled', async () => {
8484
await waitForSnapshot(
85-
'canceled-request-id',
85+
'canceled-request-id-canceled',
8686
<AppContextProvider value={userStateWithPermission}>
8787
<MemoryRouter
8888
initialEntries={[

0 commit comments

Comments
 (0)