Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

New UI for task accordion #606

Merged
merged 13 commits into from
Nov 9, 2023
2 changes: 1 addition & 1 deletion __tests__/taskRequests/taskRequestDetails.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ describe('Tests the User Management User Listing Screen', () => {

beforeAll(async () => {
browser = await puppeteer.launch({
headless: true,
headless: 'new',
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @ardourApeX ,
I'm curious about why we changed the headless mode from true to new. Could you please provide some context

ignoreHTTPSErrors: true,
args: ['--incognito', '--disable-web-security'],
devtools: false,
Expand Down
192 changes: 173 additions & 19 deletions __tests__/user-details/task-duedate-hover.test.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
const puppeteer = require('puppeteer');
const {
userDetailsApi,
usersTasksInDev,
} = require('../../mock-data/task-card-date-hover/index'); //has user info
const {
superUserDetails,
Expand Down Expand Up @@ -49,6 +50,62 @@ describe('Tasks On User Management Page', () => {
},
body: JSON.stringify(superUserDetails), // Y contains the json of a superuser in the server which will grant us the access to view the page without locks
});
} else if (
url ===
'https://api.realdevsquad.com/tasks/?size=3&dev=true&assignee=ajeyakrishna'
) {
interceptedRequest.respond({
status: 200,
contentType: 'application/json',
headers: {
'Access-Control-Allow-Origin': '*',
'Access-Control-Allow-Methods': 'GET, POST, PUT, DELETE, OPTIONS',
'Access-Control-Allow-Headers': 'Content-Type, Authorization',
},
body: JSON.stringify(usersTasksInDev['initial']),
});
} else if (
url ===
'https://api.realdevsquad.com/tasks?dev=true&assignee=ajeyakrishna&size=3&next=vvTPGHAs9w36oY1UnV8r'
) {
interceptedRequest.respond({
status: 200,
contentType: 'application/json',
headers: {
'Access-Control-Allow-Origin': '*',
'Access-Control-Allow-Methods': 'GET, POST, PUT, DELETE, OPTIONS',
'Access-Control-Allow-Headers': 'Content-Type, Authorization',
},
body: JSON.stringify(usersTasksInDev['vvTPGHAs9w36oY1UnV8r']),
});
} else if (
url ===
'https://api.realdevsquad.com/tasks?dev=true&assignee=ajeyakrishna&size=3&next=i1LQOKkGhhpOxE6yEo3A'
) {
interceptedRequest.respond({
status: 200,
contentType: 'application/json',
headers: {
'Access-Control-Allow-Origin': '*',
'Access-Control-Allow-Methods': 'GET, POST, PUT, DELETE, OPTIONS',
'Access-Control-Allow-Headers': 'Content-Type, Authorization',
},
body: JSON.stringify(usersTasksInDev['i1LQOKkGhhpOxE6yEo3A']),
});
} else if (
url ===
'https://api.realdevsquad.com/tasks?dev=true&assignee=ajeyakrishna&size=3&next=OhNeSTj5J72PhrA4mtrr'
) {
interceptedRequest.respond({
status: 200,
contentType: 'application/json',
headers: {
'Access-Control-Allow-Origin': '*',
'Access-Control-Allow-Methods': 'GET, POST, PUT, DELETE, OPTIONS',
'Access-Control-Allow-Headers': 'Content-Type, Authorization',
},
body: JSON.stringify(usersTasksInDev['OhNeSTj5J72PhrA4mtrr']),
});
} else {
interceptedRequest.continue();
}
Expand All @@ -57,25 +114,6 @@ describe('Tasks On User Management Page', () => {
'http://localhost:8000/users/details/index.html?username=sunny-s',
);

await page.evaluate(async () => {
// We write the function with superUser as true

async function accessingUserData() {
const isSuperUser = true;
if (isSuperUser) {
await getUserTasks();
await getUserPrs();
await generateAcademicTabDetails();
toggleAccordionTabsVisibility();
} else {
lockAccordiansForNonSuperUser();
}
}

// Calling the function
await accessingUserData();
});

await page.waitForNetworkIdle();
});

Expand Down Expand Up @@ -141,4 +179,120 @@ describe('Tasks On User Management Page', () => {

await page.waitForTimeout(500); //waiting for a moment to check changes(very helpful when you turn headless into false)
});

it('Scroll of task should work in dev mode', async () => {
await page.goto(
'http://localhost:8000/users/details/index.html?username=ajeyakrishna&dev=true',
);
await page.waitForNetworkIdle();
const taskDiv = await page.$$('.accordion-tasks');
expect(taskDiv).toBeTruthy();
await taskDiv[0].click();

const userTasksDevDiv = await page.$('.user-tasks-dev');
expect(userTasksDevDiv).toBeTruthy();

await page.evaluate(() => {
window.scrollBy(0, window.document.body.scrollHeight);
});
await page.waitForNetworkIdle();

await page.evaluate(() => {
window.scrollBy(0, window.document.body.scrollHeight);
});
await page.waitForNetworkIdle();

await page.evaluate(() => {
window.scrollBy(0, window.document.body.scrollHeight);
});
await page.waitForNetworkIdle();

await page.evaluate(() => {
window.scrollBy(0, window.document.body.scrollHeight);
});
await page.waitForNetworkIdle();

let renderedTasks = await userTasksDevDiv.$$('.user-task');
expect(Array.from(renderedTasks).length).toBe(12);
});

it('New task card should have all the detail fields', async () => {
await page.goto(
'http://localhost:8000/users/details/index.html?username=ajeyakrishna&dev=true',
);
await page.waitForNetworkIdle();
const taskDiv = await page.$$('.accordion-tasks');
expect(taskDiv).toBeTruthy();
await taskDiv[0].click();

const userTasksDevDiv = await page.$('.user-tasks-dev');
expect(userTasksDevDiv).toBeTruthy();

let renderedTasks = await page.$$('.user-task');
let firstTask = await renderedTasks[0].$$('.task');
let firstTaskHTML = await page.evaluate(
(element) => element.innerHTML,
firstTask[0],
);

expect(firstTaskHTML).toContain('<div class="task-title">');
expect(firstTaskHTML).not.toContain('<progress');
expect(firstTaskHTML).toContain('<div class="detail-block eta">');
expect(firstTaskHTML).toContain('<div class="detail-block status">');
expect(firstTaskHTML).toContain('<div class="detail-block startedOn">');
expect(firstTaskHTML).toContain('<div class="detail-block priority">');
expect(firstTaskHTML).toContain('<div class="detail-block createdBy">');
expect(firstTaskHTML).toContain('<div class="detail-block type">');

let secondTask = await renderedTasks[1].$$('.task');
let secondTaskHTML = await page.evaluate(
(element) => element.innerHTML,
secondTask[0],
);

expect(secondTaskHTML).toContain('<div class="task-title">');
expect(secondTaskHTML).not.toContain('<progress');
expect(secondTaskHTML).toContain('<div class="detail-block eta">');
expect(secondTaskHTML).toContain('<div class="detail-block status">');
expect(secondTaskHTML).toContain('<div class="detail-block startedOn">');
expect(secondTaskHTML).toContain('<div class="detail-block priority">');
expect(secondTaskHTML).toContain('<div class="detail-block createdBy">');
expect(secondTaskHTML).toContain('<div class="detail-block type">');

let thirdTask = await renderedTasks[2].$$('.task');
let thirdTaskHTML = await page.evaluate(
(element) => element.innerHTML,
thirdTask[0],
);

expect(thirdTaskHTML).toContain('<div class="task-title">');
expect(thirdTaskHTML).not.toContain('<progress');
expect(thirdTaskHTML).toContain('<div class="detail-block eta">');
expect(thirdTaskHTML).toContain('<div class="detail-block status">');
expect(thirdTaskHTML).toContain('<div class="detail-block startedOn">');
expect(thirdTaskHTML).toContain('<div class="detail-block priority">');
expect(thirdTaskHTML).toContain('<div class="detail-block createdBy">');
expect(thirdTaskHTML).toContain('<div class="detail-block type">');

await page.evaluate(() => {
window.scrollBy(0, window.document.body.scrollHeight);
});
await page.waitForNetworkIdle();

renderedTasks = await page.$$('.user-task');
let fourthTask = await renderedTasks[3].$$('.task');
let fourthTaskHTML = await page.evaluate(
(element) => element.innerHTML,
fourthTask[0],
);

expect(fourthTaskHTML).toContain('<div class="task-title">');
expect(fourthTaskHTML).toContain('<progress class="green"');
expect(fourthTaskHTML).toContain('<div class="detail-block eta">');
expect(fourthTaskHTML).toContain('<div class="detail-block status">');
expect(fourthTaskHTML).toContain('<div class="detail-block startedOn">');
expect(fourthTaskHTML).toContain('<div class="detail-block priority">');
expect(fourthTaskHTML).toContain('<div class="detail-block createdBy">');
expect(fourthTaskHTML).toContain('<div class="detail-block type">');
});
});
32 changes: 0 additions & 32 deletions extension-requests/local-utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -205,38 +205,6 @@ function formDataToObject(formData) {
return result;
}

function dateDiff(date1, date2, formatter) {
if (date2 > date1) {
return dateDiff(date2, date1, formatter);
}

const timeDifference = new Date(date1).getTime() - new Date(date2).getTime();

const seconds = Math.floor(timeDifference / 1000);
const minutes = Math.floor(seconds / 60);
const hours = Math.floor(minutes / 60);
const days = Math.floor(hours / 24);
const months = Math.floor(days / 30);
const years = Math.floor(days / 365);

let res;
if (seconds < 60) {
res = `${seconds} ${seconds === 1 ? 'second' : 'seconds'}`;
} else if (minutes < 60) {
res = `${minutes} ${minutes === 1 ? 'minute' : 'minutes'}`;
} else if (hours < 24) {
res = `${hours} ${hours === 1 ? 'hour' : 'hours'}`;
} else if (days < 30) {
res = `${days} ${days === 1 ? 'day' : 'days'}`;
} else if (months < 12) {
res = `${months} ${months === 1 ? 'month' : 'months'}`;
} else {
res = `${years} ${years === 1 ? 'year' : 'years'}`;
}

return formatter ? formatter(res) : res;
}

const addSpinner = (container) => {
const spinner = createElement({
type: 'div',
Expand Down
2 changes: 1 addition & 1 deletion footerTest.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ const puppeteer = require('puppeteer');

let config = {
launchOptions: {
headless: true,
headless: 'new',
ignoreHTTPSErrors: true,
},
};
Expand Down
Loading