Skip to content

Commit

Permalink
Merge branch 'fix/ci-test' of https://github.com/Real-Dev-Squad/websi…
Browse files Browse the repository at this point in the history
…te-dashboard into fix/ci-test
  • Loading branch information
vinit717 committed Oct 12, 2024
2 parents 1323695 + 92148ad commit c72d183
Show file tree
Hide file tree
Showing 14 changed files with 265 additions and 139 deletions.
23 changes: 23 additions & 0 deletions __tests__/applications/applications.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,23 @@ describe('Applications page', () => {
'Access-Control-Allow-Headers': 'Content-Type, Authorization',
},
});
} else if (
request.url() ===
`${API_BASE_URL}/applications?size=6&status=pending&dev=true`
) {
request.respond({
status: 200,
contentType: 'application/json',
body: JSON.stringify({
applications: acceptedApplications,
totalCount: acceptedApplications.length,
}),
headers: {
'Access-Control-Allow-Origin': '*',
'Access-Control-Allow-Methods': 'GET, POST, PUT, DELETE, OPTIONS',
'Access-Control-Allow-Headers': 'Content-Type, Authorization',
},
});
} else {
request.continue();
}
Expand All @@ -129,6 +146,12 @@ describe('Applications page', () => {
expect(applicationCards.length).toBe(6);
});

it('should render the index of pending applications under dev flag === true', async function () {
await page.goto(`${SITE_URL}/applications?dev=true&status=pending`);
const indexOfApplication = await page.$$('[data-testid="user-index"]');
expect(indexOfApplication).toBeTruthy();
});

it('should render the initial UI elements under dev flag === true', async function () {
await page.goto(`${SITE_URL}/applications?dev=true`);
const title = await page.$('.header h1');
Expand Down
48 changes: 27 additions & 21 deletions __tests__/users/user-management-home-screen.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -108,40 +108,46 @@ describe('Tests the User Management User Listing Screen', () => {
expect(liList.length).toBeGreaterThan(0);
});

it('checks the search functionality to display queried user', async () => {
it('Checks the search functionality to display queried user', async () => {
await page.type('input[id="user-search"]', 'randhir');
await page.waitForNetworkIdle();
const userList = await page.$('#user-list');
const userCard = await userList.$$('li');
expect(userCard.length).toBeGreaterThan(0);
});

it('checks the next and previous button functionality', async () => {
await page.goto('http://localhost:8000/users');
await page.waitForNetworkIdle();
it('Checks for empty string input once the user removes their input', async () => {
// Find the user list and the user cards
const userList = await page.$('#head_list');
let userCard = await userList.$$('li');

// Get the "next" button and check if it is enabled
const nextBtn = await page.$('#nextButton');
const isNextButtonDisabled = await page.evaluate(
(button) => button.disabled,
nextBtn,
);
expect(isNextButtonDisabled).toBe(false);
await page.click('input[id="user-search"]');
await page.keyboard.down('Control'); // On Mac, use 'Meta' instead of 'Control'
await page.keyboard.press('A');
await page.keyboard.up('Control');
await page.keyboard.press('Backspace');

// Click the "next" button and wait for the page to load
await nextBtn.click();
await page.waitForNetworkIdle();

// Check that the "next" button is still present and the "previous" button is not disabled
const updatedNextButton = await page.$('#nextButton');
expect(updatedNextButton).toBeTruthy();
userCard = await userList.$$('li');

expect(userCard.length).toBeGreaterThan(0);
});

const prevBtn = await page.$('#prevButton');
const isPrevButtonDisabled = await page.evaluate(
(button) => button.disabled,
prevBtn,
it('checks infinite scroll functionality to load more users', async () => {
await page.goto('http://localhost:8000/users');
await page.waitForNetworkIdle();
const userList = await page.$('#user-list');
let initialUserCount = await userList.$$eval('li', (items) => items.length);
expect(initialUserCount).toBeGreaterThan(0);
await page.evaluate(() => {
window.scrollTo(0, document.body.scrollHeight);
});
const updatedUserCount = await userList.$$eval(
'li',
(items) => items.length,
);
expect(isPrevButtonDisabled).toBe(false);
expect(updatedUserCount).toBeGreaterThanOrEqual(initialUserCount);
});

it('Clicking on filter button should display filter modal', async () => {
Expand Down
55 changes: 46 additions & 9 deletions applications/script.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ import {
} from './utils.js';
let nextLink;
let isDataLoading = false;
let totalApplicationCount = 0;
let currentApplicationIndex = 0;
const loader = document.querySelector('.loader');
const filterModal = document.querySelector('.filter-modal');
const backDrop = document.querySelector('.backdrop');
Expand Down Expand Up @@ -38,6 +40,7 @@ const applicationDetailsActionsContainer = document.querySelector(
);
const urlParams = new URLSearchParams(window.location.search);
const isDev = urlParams.get('dev') === 'true';
let isApplicationPending = urlParams.get('status') === 'pending';
const filterButton = isDev
? document.getElementById('filter-button-new')
: document.getElementById('filter-button');
Expand Down Expand Up @@ -100,6 +103,7 @@ function changeFilter() {
} else {
totalCountElement.classList.add('hidden');
status = 'all';
totalApplicationCount = 0;
}
applicationContainer.innerHTML = '';
}
Expand Down Expand Up @@ -297,7 +301,7 @@ function removeQueryParamInUrl(queryParamKey) {
window.history.replaceState(window.history.state, '', updatedUrl);
}

function createApplicationCard({ application, dev }) {
function createApplicationCard({ application, dev, index }) {
const applicationCard = createElement({
type: 'div',
attributes: { class: 'application-card' },
Expand All @@ -314,6 +318,29 @@ function createApplicationCard({ application, dev }) {
innerText: application.biodata.firstName,
});

if (dev && isApplicationPending) {
const usernameTextAndIndex = createElement({
type: 'div',
attributes: { class: 'user-text-index' },
});

const userIndex = createElement({
type: 'input',
attributes: {
type: 'number',
value: `${index}`,
readonly: '',
class: 'user-index',
'data-testid': 'user-index',
},
});
usernameTextAndIndex.appendChild(usernameText);
usernameTextAndIndex.appendChild(userIndex);
userInfoContainer.appendChild(usernameTextAndIndex);
} else {
userInfoContainer.appendChild(usernameText);
}

const companyNameText = createElement({
type: 'p',
attributes: { class: 'company-name hide-overflow' },
Expand All @@ -326,7 +353,6 @@ function createApplicationCard({ application, dev }) {
innerText: `Skills: ${application.professional.skills}`,
});

userInfoContainer.appendChild(usernameText);
userInfoContainer.appendChild(companyNameText);
userInfoContainer.appendChild(skillsText);

Expand Down Expand Up @@ -382,7 +408,10 @@ async function renderApplicationCards(next, status, isInitialRender, dev) {
changeLoaderVisibility({ hide: true });
const applications = data.applications;
const totalSelectedCount = data.totalCount;

if (isInitialRender) {
totalApplicationCount = data.totalCount;
currentApplicationIndex = totalApplicationCount;
}
nextLink = data.next;
if (isDev && status != 'all') {
showAppliedFilter(status);
Expand All @@ -394,12 +423,19 @@ async function renderApplicationCards(next, status, isInitialRender, dev) {
}
if (!applications.length)
return noApplicationFoundText.classList.remove('hidden');
applications.forEach((application) => {

if (isInitialRender || !next) {
applicationContainer.innerHTML = '';
currentApplicationIndex = totalSelectedCount;
}
applications.forEach((application, index) => {
const applicationCard = createApplicationCard({
application,
dev,
index: currentApplicationIndex,
});
applicationContainer.appendChild(applicationCard);
currentApplicationIndex--;
});
}

Expand Down Expand Up @@ -448,7 +484,8 @@ async function renderApplicationById(id) {
if (applicationId) {
await renderApplicationById(applicationId);
}

totalApplicationCount = 0;
currentApplicationIndex = 0;
if (isDev) {
await renderApplicationCards('', status, true, isDev);
} else {
Expand All @@ -467,7 +504,7 @@ const intersectionObserver = new IntersectionObserver(async (entries) => {
if (entries[0].isIntersecting && !isDataLoading) {
const dev = urlParams.get('dev');
if (dev) {
await renderApplicationCards(nextLink, status, true, dev);
await renderApplicationCards(nextLink, status, false, dev);
} else {
await renderApplicationCards(nextLink);
}
Expand Down Expand Up @@ -514,7 +551,7 @@ if (isDev) {
const dev = urlParams.get('dev');

if (dev) {
renderApplicationCards(nextLink, status, false, dev);
renderApplicationCards(nextLink, status, true, dev);
} else {
renderApplicationCards(nextLink, status);
}
Expand All @@ -539,7 +576,7 @@ function applyFilter(filter, isDev) {
addQueryParamInUrl('status', filter);
changeFilter();
status = filter;
renderApplicationCards(nextLink, status, false, isDev);
renderApplicationCards('', status, false, isDev);
filterDropdown.style.display = 'none';
}
}
Expand All @@ -550,7 +587,7 @@ filterRemove.addEventListener('click', () => {
removeQueryParamInUrl('status');
changeFilter();
const dev = urlParams.get('dev');
renderApplicationCards(nextLink, status, false, dev);
renderApplicationCards(nextLink, status, true, dev);
});

backDrop.addEventListener('click', () => {
Expand Down
13 changes: 13 additions & 0 deletions applications/style.css
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,19 @@
--color-red-variant1: #f43030;
}

.user-text-index {
display: flex;
justify-content: space-between;
}

.user-index {
width: 60px;
border: none;
font-style: normal;
font-size: 20px;
font-weight: 700;
}

body {
font-family: 'Roboto', sans-serif;
margin: 0;
Expand Down
2 changes: 1 addition & 1 deletion online-members/online-members.css
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
}

.task-container {
overflow: scroll;
overflow: auto;
display: none;
padding-top: 10px;
max-height: 85vh;
Expand Down
2 changes: 1 addition & 1 deletion online-members/script.js
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ async function generateUserTaskData(username) {
return;
}

showLoadingSpinner(`${TASKS_CONTAINER_ID}`);
showLoadingSpinner(`#${TASKS_CONTAINER_ID}`);

isTaskDataBeingFetched = true;

Expand Down
4 changes: 4 additions & 0 deletions profile-diff-details/assets/default-profile.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 2 additions & 2 deletions profile-diff-details/script.js
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ async function setUser(profileDiff) {
type: 'img',
attributes: {
class: 'user_image',
src: user.picture.url,
src: user.picture?.url || 'assets/default-profile.svg',
height: '71px',
width: '71px',
},
Expand All @@ -135,7 +135,7 @@ async function setUser(profileDiff) {
class: 'user_name',
},
});
username.innerHTML = `${user.first_name} ${user.last_name}`;
username.innerHTML = `${user.first_name || ''} ${user.last_name || ''}`;
CONTAINER.appendChild(username);

const expandControlContainer = createElement({
Expand Down
Loading

0 comments on commit c72d183

Please sign in to comment.