Skip to content

Commit de8e0fc

Browse files
committed
Refactor catalogList tests: enhance makeWrapper function
1 parent 176e058 commit de8e0fc

File tree

1 file changed

+16
-42
lines changed
  • contentcuration/contentcuration/frontend/channelList/views/Channel/__tests__

1 file changed

+16
-42
lines changed

contentcuration/contentcuration/frontend/channelList/views/Channel/__tests__/catalogList.spec.js

Lines changed: 16 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,9 @@ function makeWrapper(overrides = {}) {
3838
online: overrides.offline ? false : true,
3939
},
4040
},
41+
getters: {
42+
loggedIn: () => true,
43+
},
4144
actions: {
4245
showSnackbar: jest.fn(),
4346
},
@@ -54,6 +57,7 @@ function makeWrapper(overrides = {}) {
5457
getChannels: state => ids => {
5558
return ids.map(id => state.channelsMap[id]).filter(Boolean);
5659
},
60+
getChannel: state => id => state.channelsMap[id],
5761
},
5862
actions: {
5963
getChannelListDetails: jest.fn(() => Promise.resolve(mockChannels)),
@@ -100,35 +104,6 @@ function makeWrapper(overrides = {}) {
100104
router,
101105
stubs: {
102106
CatalogFilters: true,
103-
ChannelItem: {
104-
props: ['channelId'],
105-
template: '<div :data-testid="`channel-${channelId}`">Channel Item</div>',
106-
},
107-
BottomBar: { template: '<div data-testid="toolbar"><slot /></div>' },
108-
Checkbox: {
109-
props: ['value', 'label', 'indeterminate'],
110-
data() {
111-
return {
112-
isChecked: this.value,
113-
};
114-
},
115-
watch: {
116-
value(newVal) {
117-
this.isChecked = newVal;
118-
},
119-
},
120-
template: `
121-
<label>
122-
<input
123-
type="checkbox"
124-
:checked="isChecked"
125-
:data-testid="label ? 'select-all-checkbox' : 'checkbox'"
126-
@change="$emit('input', $event.target.checked)"
127-
/>
128-
<span v-if="label">{{ label }}</span>
129-
</label>
130-
`,
131-
},
132107
},
133108
mocks: {
134109
$tr: (key, params) => {
@@ -193,13 +168,9 @@ describe('CatalogList', () => {
193168
makeWrapper();
194169
await waitFor(() => screen.getByText('2 results found'));
195170

196-
const checkboxes = screen.queryAllByTestId('checkbox');
197-
if (checkboxes.length > 0) {
198-
checkboxes.forEach(checkbox => {
199-
expect(checkbox.closest('label')).toHaveStyle('display: none');
200-
});
201-
}
202-
expect(screen.queryByTestId('toolbar')).not.toBeInTheDocument();
171+
// Toolbar should not be visible initially (appears only in selection mode)
172+
expect(screen.queryByText('Select all')).not.toBeInTheDocument();
173+
expect(screen.queryByText('Cancel')).not.toBeInTheDocument();
203174
});
204175

205176
it('should enter selection mode when user clicks select button', async () => {
@@ -211,7 +182,7 @@ describe('CatalogList', () => {
211182

212183
await waitFor(() => {
213184
expect(screen.getByText('Select all')).toBeInTheDocument();
214-
expect(screen.getByTestId('toolbar')).toBeInTheDocument();
185+
expect(screen.getByText('Cancel')).toBeInTheDocument();
215186
});
216187
});
217188

@@ -234,12 +205,13 @@ describe('CatalogList', () => {
234205
// Enter selection mode
235206
await waitFor(() => screen.getByText('Download a summary of selected channels'));
236207
await user.click(screen.getByText('Download a summary of selected channels'));
237-
await waitFor(() => screen.getByTestId('toolbar'));
208+
await waitFor(() => screen.getByText('Cancel'));
238209

239210
await user.click(screen.getByText('Cancel'));
240211

241212
await waitFor(() => {
242-
expect(screen.queryByTestId('toolbar')).not.toBeInTheDocument();
213+
expect(screen.queryByText('Cancel')).not.toBeInTheDocument();
214+
expect(screen.queryByText('Select all')).not.toBeInTheDocument();
243215
});
244216
});
245217
});
@@ -253,7 +225,8 @@ describe('CatalogList', () => {
253225
await user.click(screen.getByText('Download a summary of selected channels'));
254226

255227
await waitFor(() => {
256-
expect(screen.getByTestId('toolbar')).toBeInTheDocument();
228+
expect(screen.getByText('Select all')).toBeInTheDocument();
229+
expect(screen.getByText('2 channels selected')).toBeInTheDocument();
257230
});
258231
});
259232

@@ -265,7 +238,7 @@ describe('CatalogList', () => {
265238
await user.click(screen.getByText('Download a summary of selected channels'));
266239

267240
await waitFor(() => {
268-
expect(screen.getByTestId('select-all-checkbox')).toBeInTheDocument();
241+
expect(screen.getByText('Select all')).toBeInTheDocument();
269242
});
270243
});
271244
});
@@ -321,7 +294,8 @@ describe('CatalogList', () => {
321294
await user.click(screen.getByText('Download a summary of selected channels'));
322295

323296
await waitFor(() => {
324-
expect(screen.getByTestId('toolbar')).toBeInTheDocument();
297+
expect(screen.getByText('Select all')).toBeInTheDocument();
298+
expect(screen.getByText('Cancel')).toBeInTheDocument();
325299
});
326300
});
327301
});

0 commit comments

Comments
 (0)