Skip to content

Commit 34507d2

Browse files
authored
FIX: Share group using URL (#643)
* added option to share the group using url * test: add test for changes * test: fix test
1 parent 4cee8ac commit 34507d2

File tree

2 files changed

+30
-0
lines changed

2 files changed

+30
-0
lines changed

__tests__/groups/group.test.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -339,4 +339,14 @@ describe('Discord Groups Page', () => {
339339
expect.arrayContaining(['DSA', 'DSA-Coding-Group']),
340340
);
341341
});
342+
343+
test('should select the group from URL and have active-group class', async () => {
344+
await page.goto('http://localhost:8000/groups?DSA');
345+
const activeGroup = await page.$('.active-group');
346+
const groupName = await page.evaluate(
347+
(element) => element.innerText,
348+
activeGroup,
349+
);
350+
expect(groupName).toMatch('DSA');
351+
});
342352
});

groups/script.js

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,9 @@ groupRoles?.addEventListener('click', function (event) {
154154
});
155155
const groupListItem = event.target?.closest('li');
156156
if (groupListItem) {
157+
const groupName = `${groupListItem.querySelector('p').textContent}`;
158+
const newURL = `${window.location.pathname}?${groupName}`;
159+
window.history.pushState({}, '', newURL);
157160
groupListItem.classList.add('active-group');
158161
memberAddRoleBody.roleid = groupListItem.id;
159162
if (IsUserVerified) {
@@ -349,3 +352,20 @@ createGroupButton.addEventListener('click', async () => {
349352
location.reload();
350353
});
351354
});
355+
356+
/**
357+
* TO SELECT A GROUP ROLE
358+
*/
359+
360+
if (searchValue) {
361+
const groupName = searchValue;
362+
const paragraphs = document.querySelectorAll('p');
363+
364+
const groupElement = Array.from(paragraphs).find((paragraph) =>
365+
paragraph.textContent.includes(groupName),
366+
);
367+
368+
if (groupElement) {
369+
groupElement.parentElement.click();
370+
}
371+
}

0 commit comments

Comments
 (0)