Skip to content

Commit 6a8768a

Browse files
authored
Merge pull request #759 from Real-Dev-Squad/develop
Sync Dev To Main
2 parents d990188 + cb74366 commit 6a8768a

File tree

19 files changed

+707
-1941
lines changed

19 files changed

+707
-1941
lines changed

__tests__/groups/group.test.js

Lines changed: 56 additions & 247 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,6 @@ const PAGE_URL = 'http://localhost:8000';
88
describe('Discord Groups Page', () => {
99
let browser;
1010
let page;
11-
let createGroup;
12-
let createGroupBtn;
13-
let alertMessage;
1411
jest.setTimeout(60000);
1512

1613
beforeAll(async () => {
@@ -149,285 +146,97 @@ describe('Discord Groups Page', () => {
149146
expect(pageTitle).toBe('Discord Groups | Real Dev Squad');
150147
});
151148

152-
test('Add role button should be disabled for unverified users', async () => {
153-
const isButtonDisabled = await page.$eval(
154-
'.btn-add-role',
155-
(button) => button.disabled,
156-
);
157-
expect(isButtonDisabled).toBe(true);
158-
});
149+
test('Should display cards', async () => {
150+
await page.waitForSelector('.card');
151+
const cards = await page.$$('.card');
159152

160-
test('User not verified message should be visible for unverified users', async () => {
161-
const isMessageVisible = await page.$eval(
162-
'.not-verified-tag',
163-
(message) => !message.classList.contains('hidden'),
164-
);
165-
expect(isMessageVisible).toBe(false);
153+
expect(cards.length).toBeGreaterThan(0);
166154
});
167155

168-
test('Group list should contain the correct number of items', async () => {
169-
const groupListLength = await page.$$eval(
170-
'.group-role',
171-
(list) => list.length,
156+
test('Should display card details', async () => {
157+
const card = await page.$('.card');
158+
const groupTitle = await card.$eval('.card__title', (el) => el.textContent);
159+
const groupDescription = await card.$eval(
160+
'.card__description',
161+
(el) => el.textContent,
172162
);
173-
expect(groupListLength).toBe(3);
174-
});
163+
const groupCount = await card.$eval('.card__count', (el) => el.textContent);
175164

176-
test('Should not display an error message if the role name contains "group"', async () => {
177-
createGroup = await page.$('.create-groups-tab');
178-
await createGroup.click();
179-
await page.type('.new-group-input', 'demo-role');
180-
181-
createGroupBtn = await page.$('#create-button');
182-
await createGroupBtn.click();
183-
184-
await page.waitForNetworkIdle();
185-
await expect(alertMessage).toContain('Group created successfully');
165+
expect(groupTitle).toBeTruthy();
166+
expect(groupDescription).toBeTruthy();
167+
expect(groupCount).toBeTruthy();
186168
});
187169

188-
test('Should show add button as user not part of the group', async () => {
189-
const group = await page.$('.group-role');
190-
await group.click();
170+
test('Should display card with a button with text "Add me" or "Remove me"', async () => {
171+
const card = await page.$('.card');
172+
const buttonText = await card.$eval('.card__btn', (el) => el.textContent);
191173

192-
// Wait for the btn-add-role and click it
193-
const addRoleBtn = await page.$('.btn-add-role');
194-
await addRoleBtn.click();
195-
196-
// Now, check the text content of the button
197-
const buttonText = await addRoleBtn.evaluate((node) => node.textContent);
198-
expect(buttonText).toBe('Add me to this group');
174+
expect(buttonText).toMatch(/Add me|Remove me/);
199175
});
200176

201-
test('Should show remove button as user is part of the group', async () => {
202-
await page.$$eval('.group-role', (elements) => {
203-
elements[1].click();
204-
});
205-
// Wait for the btn-add-role and click it
206-
const addRoleBtn = await page.$('.btn-add-role');
207-
await addRoleBtn.click();
177+
test('Should display search bar', async () => {
178+
const searchEl = await page.$('.search');
208179

209-
// Now, check the text content of the button
210-
const buttonText = await addRoleBtn.evaluate((node) => node.textContent);
211-
expect(buttonText).toBe('Remove me from this group');
180+
expect(searchEl).toBeTruthy();
212181
});
213182

214-
test('Should show role deleted', async () => {
215-
await page.$$eval('.group-role', (elements) => {
216-
elements[1].click();
217-
});
218-
// Wait for the btn-add-role and click it
219-
const addRoleBtn = await page.$('.btn-add-role');
220-
await addRoleBtn.click();
221-
222-
await page.waitForNetworkIdle();
223-
const toast = await page.$('.toaster-container');
224-
expect(toast).toBeTruthy();
225-
});
183+
test('Should display group creation button', async () => {
184+
const createGroupBtn = await page.$('.create-group');
226185

227-
test('Should display an error message if the role name contains "group"', async () => {
228-
createGroup = await page.$('.create-groups-tab');
229-
await createGroup.click();
230-
await page.type('.new-group-input', 'mygroup');
231-
createGroupBtn = await page.$('#create-button');
232-
await createGroupBtn.click();
233-
await expect(alertMessage).toContain("Roles cannot contain 'group'.");
186+
expect(createGroupBtn).toBeTruthy();
234187
});
235188

236-
test('Filter groups based on search input', async () => {
237-
const searchInput = await page.$('#search-groups');
238-
await searchInput.type('DSA');
189+
test('Should display group creation modal on group creation button click', async () => {
190+
const createGroupBtn = await page.$('.create-group');
239191

240-
const filteredGroupNames = await page.$$eval('.group-role', (elements) => {
241-
return elements
242-
.map((element) => element.querySelector('.group-name').textContent)
243-
.filter((name) => name.includes('DSA'));
244-
});
245-
246-
expect(filteredGroupNames).toEqual(
247-
expect.arrayContaining(['DSA', 'DSA-Coding-Group']),
192+
await createGroupBtn.click();
193+
const groupCreationModal = await page.waitForSelector(
194+
'.group-creation-modal',
248195
);
249-
});
250-
251-
test('should display a message no results found if group not exists', async () => {
252-
const searchInput = await page.$('#search-groups');
253-
254-
await searchInput.type('dummy');
255-
256-
await page.waitForNetworkIdle();
257-
258-
const noResultFoundHeading = await page.$('#no-results-message');
259-
const noResultFoundHeadingText = await (
260-
await noResultFoundHeading.getProperty('innerText')
261-
).jsonValue();
262196

263-
expect(noResultFoundHeadingText).toEqual('No results found.');
197+
expect(groupCreationModal).toBeTruthy();
264198
});
265199

266-
test('should not have group keyword in group list', async () => {
267-
const renderedGroupNames = await page.$$eval('.group-name', (elements) => {
268-
return elements.map((element) => element.innerText);
269-
});
270-
renderedGroupNames.forEach((groupName) =>
271-
expect(/^group.*/.test(groupName)).toBe(false),
200+
test('Should display group creation modal with input fields', async () => {
201+
const groupCreationModal = await page.$('.group-creation-modal');
202+
const groupTitle = await groupCreationModal.$(
203+
`.input__field[name="title"]`,
272204
);
273-
});
205+
const submitBtn = await groupCreationModal.$('.submit__button');
274206

275-
test('should show count beside groupname', async () => {
276-
const memberCounts = await page.$$eval('.group-name', (elements) => {
277-
return elements.map((element) =>
278-
element.getAttribute('data-member-count'),
279-
);
280-
});
281-
expect(memberCounts).toEqual(['3', '200', '0']);
207+
expect(groupTitle).toBeTruthy();
208+
expect(submitBtn).toBeTruthy();
282209
});
283210

284-
test("should show proper group creator's image", async () => {
285-
const creatorImageSrcAndAltText = await page.$$eval(
286-
'.created-by--avatar',
287-
(elements) => {
288-
return elements.map((element) => [
289-
element.getAttribute('src'),
290-
element.getAttribute('alt'),
291-
]);
292-
},
211+
test('Should group creation modal have clear button to clear title', async () => {
212+
const groupCreationModal = await page.$('.group-creation-modal');
213+
const groupTitle = await groupCreationModal.$(
214+
`.input__field[name="title"]`,
293215
);
294-
const expectedImageSrcAndAltText = discordGroups.groups.map((group) => [
295-
group.image,
296-
"group's creator image",
297-
]);
298-
expect(creatorImageSrcAndAltText).toEqual(expectedImageSrcAndAltText);
299-
});
216+
const clearBtn = await groupCreationModal.$('#clear-input');
300217

301-
test("should show proper group creator's name", async () => {
302-
const createdByLines = await page.$$eval('.created-by', (elements) => {
303-
return elements.map((element) => element.innerText);
304-
});
305-
const expectedCreatedByLines = discordGroups.groups.map(
306-
(group) => `created by ${group.firstName} ${group.lastName}`,
307-
);
308-
expect(expectedCreatedByLines).toEqual(createdByLines);
309-
});
218+
await groupTitle.type('Test Group');
219+
await clearBtn.click();
310220

311-
test('should update the URL when input field has changed', async () => {
312-
manageGroup = await page.$('.manage-groups-tab');
313-
await manageGroup.click();
314-
const searchInput = await page.$('#search-groups');
315-
await searchInput.type('DSA');
316-
await new Promise((resolve) => setTimeout(resolve, 1000)); //wait for debouncer
317-
const url = await page.url();
318-
const searchParams = decodeURIComponent(url.split('?')[1]);
319-
expect(searchParams).toMatch('DSA');
320-
});
321-
322-
test('should update input field and filter group list with search value in URL', async () => {
323-
await page.goto(`${PAGE_URL}/groups/?dev=true&DSA`);
324-
manageGroup = await page.$('.manage-groups-tab');
325-
await manageGroup.click();
326-
const searchInput = await page.$('#search-groups');
327-
const inputValue = await page.evaluate(
328-
(element) => element.value,
329-
searchInput,
330-
);
331-
expect(inputValue).toMatch('DSA');
332-
333-
const filteredGroupNames = await page.$$eval('.group-role', (elements) => {
334-
return elements
335-
.map((element) => element.querySelector('.group-name').textContent)
336-
.filter((name) => name.includes('DSA'));
337-
});
221+
const titleValue = await groupTitle.evaluate((el) => el.value);
338222

339-
expect(filteredGroupNames).toEqual(
340-
expect.arrayContaining(['DSA', 'DSA-Coding-Group']),
341-
);
223+
expect(titleValue).toBe('');
342224
});
343225

344-
test('should select the group from URL and have active-group class', async () => {
345-
await page.goto(`${PAGE_URL}/groups?DSA`);
346-
const activeGroup = await page.$('.active-group');
347-
const groupName = await page.evaluate(
348-
(element) => element.innerText,
349-
activeGroup,
350-
);
351-
expect(groupName).toMatch('DSA');
352-
});
353-
test('On click on "Popular within dev" will result group with most member at the top', async () => {
354-
await page.goto(`${PAGE_URL}/groups?dev=true`);
355-
await page.waitForNetworkIdle();
356-
357-
const groupsBeforeSort = await page.$$eval('.group-name', (elements) => {
358-
return elements.map((element) =>
359-
element.getAttribute('data-member-count'),
360-
);
361-
});
362-
await page.$$eval('#dropdown_main', (el) => {
363-
el[0].click();
364-
});
226+
test('Should display group creation modal with close button', async () => {
227+
const groupCreationModal = await page.$('.group-creation-modal');
228+
const closeBtn = await groupCreationModal.$('#close-button');
365229

366-
await page.$$eval('[data-list="1"]', (el) => {
367-
el[0].click();
368-
});
369-
const groupsAfterSort = await page.$$eval('.group-name', (elements) => {
370-
return elements.map((element) =>
371-
element.getAttribute('data-member-count'),
372-
);
373-
});
374-
const manualSortedGroup = groupsBeforeSort.sort((a, b) => b - a);
375-
expect(groupsAfterSort).toEqual(manualSortedGroup);
230+
expect(closeBtn).toBeTruthy();
376231
});
377-
test('On click on "Recently created" will result in latest created group at the top', async () => {
378-
await page.goto(`${PAGE_URL}/groups?dev=true`);
379-
await page.waitForNetworkIdle();
380232

381-
const groupNameCreateDateLookup = {};
382-
discordGroups.groups.forEach((group) => {
383-
const grpName = group.rolename.split('-').slice(1).join('-');
384-
groupNameCreateDateLookup[grpName] = group.date._seconds;
385-
});
386-
const groupsBeforeSort = await page.$$eval('.group-name', (elements) => {
387-
return elements.map((element) => element.innerText);
388-
});
233+
test('Should close group creation modal on close button click', async () => {
234+
const groupCreationModal = await page.$('.group-creation-modal');
235+
const closeBtn = await groupCreationModal.$('#close-button');
389236

390-
await page.$$eval('#dropdown_main', (el) => {
391-
el[0].click();
392-
});
393-
await page.$$eval('[data-list="2"]', (el) => {
394-
el[0].click();
395-
});
396-
const groupAfterSort = await page.$$eval('.group-name', (elements) => {
397-
return elements.map((element) => element.innerText);
398-
});
399-
const manualSortedGroup = groupsBeforeSort.sort(
400-
(a, b) => groupNameCreateDateLookup[b] - groupNameCreateDateLookup[a],
401-
);
402-
expect(groupAfterSort).toEqual(manualSortedGroup);
403-
});
404-
test('On click on "Recently used" will result in recently used group at the top', async () => {
405-
await page.goto(`${PAGE_URL}/groups?dev=true`);
406-
await page.waitForNetworkIdle();
237+
await closeBtn.click();
238+
const groupCreationModalClosed = await page.$('.group-creation-modal');
407239

408-
const groupNameCreateDateLookup = {};
409-
discordGroups.groups.forEach((group) => {
410-
const grpName = group.rolename.split('-').slice(1).join('-');
411-
groupNameCreateDateLookup[grpName] = group.lastUsedOn
412-
? group.lastUsedOn._seconds
413-
: 0;
414-
});
415-
const groupsBeforeSort = await page.$$eval('.group-name', (elements) => {
416-
return elements.map((element) => element.innerText);
417-
});
418-
419-
await page.$$eval('#dropdown_main', (el) => {
420-
el[0].click();
421-
});
422-
await page.$$eval('[data-list="3"]', (el) => {
423-
el[0].click();
424-
});
425-
const groupAfterSort = await page.$$eval('.group-name', (elements) => {
426-
return elements.map((element) => element.innerText);
427-
});
428-
const manualSortedGroup = groupsBeforeSort.sort(
429-
(a, b) => groupNameCreateDateLookup[b] - groupNameCreateDateLookup[a],
430-
);
431-
expect(groupAfterSort).toEqual(manualSortedGroup);
240+
expect(groupCreationModalClosed).toBeFalsy();
432241
});
433242
});

0 commit comments

Comments
 (0)