Skip to content

Commit

Permalink
FIX: remove duplicate usernames (#423)
Browse files Browse the repository at this point in the history
* FEATURE: added query param

* TEST: add test for query param in standuo page

* FIX: fix name of the standup days

* FIX: fix query format

* TEST: fix test error

* FIX(CSS): fix the style of sidebar and tooltip

* TEST: add test for multiple username and duplicate username

* FIX: fix to remove duplicate useraname

* FIX: remove consoles
  • Loading branch information
sahsisunny authored Jul 23, 2023
1 parent b899a72 commit 4b73966
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 9 deletions.
24 changes: 24 additions & 0 deletions __tests__/standup/standup.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -91,4 +91,28 @@ describe('Standup Page', () => {
const updatedUrl = page.url();
expect(updatedUrl).toContain('q=user:sunny');
});

it('should update the URL with the query parameter when the user writes multiple names', async () => {
const userInput = await page.$('#user-search-input');
const searchButton = await page.$('#search-button');
await userInput.click({ clickCount: 3 });
await userInput.press('Backspace');
await userInput.type('sunny,pratiyush');
await searchButton.click();
await page.waitForTimeout(1000);
const updatedUrl = page.url();
expect(updatedUrl).toContain('q=user:sunny+user:pratiyush');
});

it('should update the URL with the query parameter when the user writes duplicate names', async () => {
const userInput = await page.$('#user-search-input');
const searchButton = await page.$('#search-button');
await userInput.click({ clickCount: 3 });
await userInput.press('Backspace');
await userInput.type('sunny,sunny,pratiyush');
await searchButton.click();
await page.waitForTimeout(1000);
const updatedUrl = page.url();
expect(updatedUrl).toContain('q=user:sunny+user:pratiyush');
});
});
20 changes: 11 additions & 9 deletions standup/script.js
Original file line number Diff line number Diff line change
Expand Up @@ -219,15 +219,18 @@ async function searchButtonHandler() {
const usernames = searchInput.value
.split(',')
.map((username) => username.trim());
const formattedUsernames = usernames.map((username) => `user:${username}`);
const uniqueUsernames = [...new Set(usernames)];
const formattedUsernames = uniqueUsernames.map(
(username) => `user:${username}`,
);
const queryString = formattedUsernames.join('+');

const newUrl = `${window.location.origin}${window.location.pathname}?q=${queryString}`;
window.history.pushState({ path: newUrl }, '', newUrl);

tableBodyElement.innerHTML = '';

for (const username of usernames) {
for (const username of uniqueUsernames) {
tableContainerElement.appendChild(loaderElement);
const userData = await fetchUserData(username);
if (userData) {
Expand All @@ -245,12 +248,6 @@ async function searchButtonHandler() {
tableContainerElement.removeChild(loaderElement);
}

function handleEnterKeyPress(event) {
if (event.key === 'Enter') {
searchButtonHandler();
}
}

function getUsernames() {
const queryData = new URL(
decodeURIComponent(window.location.href),
Expand All @@ -262,9 +259,14 @@ function getUsernames() {
}

function setUsernames(usernames) {
searchInput.value = usernames.join(', ');
searchInput.value = [...new Set(usernames)].join(', ');
}

function handleEnterKeyPress(event) {
if (event.key === 'Enter') {
searchButtonHandler();
}
}
setUsernames(getUsernames());
setupTable();

Expand Down

0 comments on commit 4b73966

Please sign in to comment.