Skip to content

Commit 313c6ea

Browse files
Merge pull request #862 from Real-Dev-Squad/develop
Dev to main sync
2 parents cd154b3 + 1fa763f commit 313c6ea

File tree

5 files changed

+133
-41
lines changed

5 files changed

+133
-41
lines changed

__tests__/applications/applications.test.js

Lines changed: 44 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,23 @@ describe('Applications page', () => {
8686
'Access-Control-Allow-Headers': 'Content-Type, Authorization',
8787
},
8888
});
89+
} else if (
90+
request.url() ===
91+
`${API_BASE_URL}/applications?size=6&status=accepted&dev=true`
92+
) {
93+
request.respond({
94+
status: 200,
95+
contentType: 'application/json',
96+
body: JSON.stringify({
97+
applications: acceptedApplications,
98+
totalCount: acceptedApplications.length,
99+
}),
100+
headers: {
101+
'Access-Control-Allow-Origin': '*',
102+
'Access-Control-Allow-Methods': 'GET, POST, PUT, DELETE, OPTIONS',
103+
'Access-Control-Allow-Headers': 'Content-Type, Authorization',
104+
},
105+
});
89106
} else {
90107
request.continue();
91108
}
@@ -112,6 +129,21 @@ describe('Applications page', () => {
112129
expect(applicationCards.length).toBe(6);
113130
});
114131

132+
it('should render the initial UI elements under dev flag === true', async function () {
133+
await page.goto(`${SITE_URL}/applications?dev=true`);
134+
const title = await page.$('.header h1');
135+
const filterButton = await page.$('.filter-button');
136+
const applicationCards = await page.$$('.application-card');
137+
expect(title).toBeTruthy();
138+
expect(filterButton).toBeTruthy();
139+
expect(applicationCards).toBeTruthy();
140+
expect(applicationCards.length).toBe(6);
141+
for (const card of applicationCards) {
142+
const viewDetailsButton = await card.$('.view-details-button');
143+
expect(viewDetailsButton).toBeFalsy();
144+
}
145+
});
146+
115147
it('should load and render the accepted application requests when accept is selected from filter, and after clearing the filter it should again show all the applications', async function () {
116148
await page.click('.filter-button');
117149

@@ -135,25 +167,18 @@ describe('Applications page', () => {
135167
).toBe(true, 'status query param is not removed from url');
136168
});
137169

138-
it('should load and render accepted application and check the applied filter label,render all applications when the applied filter is removed', async function () {
139-
await page.goto(`${SITE_URL}/applications/?dev=true`);
140-
await page.waitForNetworkIdle();
141-
await page.click('#filter-button-new');
142-
await page.click('.filter-dropdown div[data-filter="accepted"]');
143-
applicationCards = await page.$$('.application-card');
144-
expect(applicationCards.length).toBe(4);
145-
const filterLabelElement = page.$('.filter-label .filter-text');
146-
expect(filterLabelElement).toBeTruthy();
147-
await page.click('.filter-remove');
170+
it('should load and render the accepted application requests when accept filter is selected from filter under dev flag === true along with the total count of the accepted applications', async function () {
171+
await page.goto(`${SITE_URL}/applications?dev=true`);
172+
await page.click('.filter-button');
173+
174+
await page.$eval('input[name="status"][value="accepted"]', (radio) =>
175+
radio.click(),
176+
);
177+
await page.click('.apply-filter-button');
148178
await page.waitForNetworkIdle();
149-
applicationCards = await page.$$('.application-card');
150-
const urlAfterClearingStatusFilter = new URL(page.url());
151-
expect(
152-
urlAfterClearingStatusFilter.searchParams.get('status') === null,
153-
).toBe(true, 'status query param is not removed from url');
154-
expect(applicationCards.length).toBe(6);
179+
const totalCountElement = await page.$$('total_count');
180+
expect(totalCountElement).toBeTruthy(); // Assert that the element exists
155181
});
156-
157182
it('should load more applications on going to the bottom of the page', async function () {
158183
let applicationCards = await page.$$('.application-card');
159184
expect(applicationCards.length).toBe(6);
@@ -185,7 +210,7 @@ describe('Applications page', () => {
185210
expect(urlAfterOpeningModal.searchParams.get('id') !== null).toBe(true);
186211
});
187212

188-
it('under feature flag should open application details modal for application, when user click on view details on any card', async function () {
213+
it('under feature flag should open application details modal for application, when user click on card', async function () {
189214
await page.goto(`${SITE_URL}/applications/?dev=true`);
190215
await page.waitForNetworkIdle();
191216
const applicationDetailsModal = await page.$('.application-details');
@@ -194,7 +219,7 @@ describe('Applications page', () => {
194219
el.classList.contains('hidden'),
195220
),
196221
).toBe(true);
197-
await page.click('.view-details-button');
222+
await page.click('.application-details');
198223
expect(
199224
await applicationDetailsModal.evaluate((el) =>
200225
el.classList.contains('hidden'),

applications/index.html

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ <h1>RDS Join Applications</h1>
4949
<span class="filter-remove">&#x2715;</span>
5050
</div>
5151
</div>
52+
<h2 class="total_count hidden"></h2>
5253
<p class="no_applications_found hidden">No applications Found!</p>
5354
<div
5455
class="filter-modal hidden"

applications/script.js

Lines changed: 66 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ let isDataLoading = false;
1111
const loader = document.querySelector('.loader');
1212
const filterModal = document.querySelector('.filter-modal');
1313
const backDrop = document.querySelector('.backdrop');
14+
const totalCountElement = document.querySelector('.total_count');
1415
const backDropBlur = document.querySelector('.backdrop-blur');
1516
const applicationDetailsModal = document.querySelector('.application-details');
1617
const mainContainer = document.querySelector('.container');
@@ -95,7 +96,9 @@ function changeFilter() {
9596
if (!isDev) {
9697
filterModal.classList.add('hidden');
9798
backDrop.style.display = 'none';
99+
totalCountElement.classList.add('hidden');
98100
} else {
101+
totalCountElement.classList.add('hidden');
99102
status = 'all';
100103
}
101104
applicationContainer.innerHTML = '';
@@ -294,7 +297,7 @@ function removeQueryParamInUrl(queryParamKey) {
294297
window.history.replaceState(window.history.state, '', updatedUrl);
295298
}
296299

297-
function createApplicationCard({ application }) {
300+
function createApplicationCard({ application, dev }) {
298301
const applicationCard = createElement({
299302
type: 'div',
300303
attributes: { class: 'application-card' },
@@ -333,45 +336,68 @@ function createApplicationCard({ application }) {
333336
innerText: application.intro.introduction.slice(0, 200),
334337
});
335338

336-
const viewDetailsButton = createElement({
337-
type: 'button',
338-
attributes: { class: 'view-details-button' },
339-
innerText: 'View Details',
340-
});
341-
342-
viewDetailsButton.addEventListener('click', () => {
343-
addQueryParamInUrl('id', application.id);
344-
openApplicationDetails(application);
345-
});
346-
347339
applicationCard.appendChild(userInfoContainer);
348340
applicationCard.appendChild(introductionText);
349-
applicationCard.appendChild(viewDetailsButton);
341+
342+
if (dev) {
343+
applicationCard.style.cursor = 'pointer';
344+
applicationCard.addEventListener('click', () => {
345+
addQueryParamInUrl('id', application.id);
346+
openApplicationDetails(application);
347+
});
348+
} else {
349+
const viewDetailsButton = createElement({
350+
type: 'button',
351+
attributes: { class: 'view-details-button' },
352+
innerText: 'View Details',
353+
});
354+
355+
viewDetailsButton.addEventListener('click', () => {
356+
addQueryParamInUrl('id', application.id);
357+
openApplicationDetails(application);
358+
});
359+
applicationCard.appendChild(viewDetailsButton);
360+
}
350361

351362
return applicationCard;
352363
}
353364

354-
async function renderApplicationCards(next, status, isInitialRender) {
365+
function updateTotalCount(total, status) {
366+
if (total > 0) {
367+
totalCountElement.textContent = `Total ${status} applications: ${total}`;
368+
totalCountElement.classList.remove('hidden');
369+
}
370+
}
371+
372+
async function renderApplicationCards(next, status, isInitialRender, dev) {
355373
noApplicationFoundText.classList.add('hidden');
356374
changeLoaderVisibility({ hide: false });
357375
isDataLoading = true;
358376
const data = await getApplications({
359377
applicationStatus: status,
360378
next,
379+
dev,
361380
});
362381
isDataLoading = false;
363382
changeLoaderVisibility({ hide: true });
364383
const applications = data.applications;
384+
const totalSelectedCount = data.totalCount;
385+
365386
nextLink = data.next;
366387
if (isDev && status != 'all') {
367388
showAppliedFilter(status);
368389
}
369390
if (isInitialRender) filterButton.classList.remove('hidden');
391+
392+
if (dev) {
393+
updateTotalCount(totalSelectedCount, status);
394+
}
370395
if (!applications.length)
371396
return noApplicationFoundText.classList.remove('hidden');
372397
applications.forEach((application) => {
373398
const applicationCard = createApplicationCard({
374399
application,
400+
dev,
375401
});
376402
applicationContainer.appendChild(applicationCard);
377403
});
@@ -422,7 +448,13 @@ async function renderApplicationById(id) {
422448
if (applicationId) {
423449
await renderApplicationById(applicationId);
424450
}
425-
await renderApplicationCards('', status, true, applicationId);
451+
452+
if (isDev) {
453+
await renderApplicationCards('', status, true, isDev);
454+
} else {
455+
await renderApplicationCards('', status, true, applicationId);
456+
}
457+
426458
addIntersectionObserver();
427459

428460
changeLoaderVisibility({ hide: true });
@@ -433,7 +465,12 @@ const intersectionObserver = new IntersectionObserver(async (entries) => {
433465
return;
434466
}
435467
if (entries[0].isIntersecting && !isDataLoading) {
436-
await renderApplicationCards(nextLink);
468+
const dev = urlParams.get('dev');
469+
if (dev) {
470+
await renderApplicationCards(nextLink, status, true, dev);
471+
} else {
472+
await renderApplicationCards(nextLink);
473+
}
437474
}
438475
});
439476

@@ -450,7 +487,7 @@ if (isDev) {
450487
filterOptions.forEach((option) => {
451488
option.addEventListener('click', () => {
452489
const filter = option.getAttribute('data-filter');
453-
applyFilter(filter);
490+
applyFilter(filter, isDev);
454491
});
455492
});
456493
} else {
@@ -473,7 +510,14 @@ if (isDev) {
473510
addQueryParamInUrl('status', selectedStatus);
474511
changeFilter();
475512
status = selectedStatus;
476-
renderApplicationCards(nextLink, status);
513+
const urlParams = new URLSearchParams(window.location.search);
514+
const dev = urlParams.get('dev');
515+
516+
if (dev) {
517+
renderApplicationCards(nextLink, status, false, dev);
518+
} else {
519+
renderApplicationCards(nextLink, status);
520+
}
477521
});
478522

479523
clearButton.addEventListener('click', clearFilter);
@@ -487,15 +531,15 @@ function showAppliedFilter(filterApplied) {
487531
}
488532
}
489533

490-
function applyFilter(filter) {
534+
function applyFilter(filter, isDev) {
491535
if (filter.length > 0) {
492536
if (!filterLabel.classList.contains('hidden')) {
493537
filterLabel.classList.add('hidden');
494538
}
495539
addQueryParamInUrl('status', filter);
496540
changeFilter();
497541
status = filter;
498-
renderApplicationCards(nextLink, status);
542+
renderApplicationCards(nextLink, status, false, isDev);
499543
filterDropdown.style.display = 'none';
500544
}
501545
}
@@ -505,7 +549,8 @@ filterRemove.addEventListener('click', () => {
505549
filterText.textContent = '';
506550
removeQueryParamInUrl('status');
507551
changeFilter();
508-
renderApplicationCards(nextLink, status);
552+
const dev = urlParams.get('dev');
553+
renderApplicationCards(nextLink, status, false, dev);
509554
});
510555

511556
backDrop.addEventListener('click', () => {

applications/style.css

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -210,6 +210,19 @@ body {
210210
color: var(--white);
211211
}
212212

213+
.total_count {
214+
padding: 24px;
215+
width: 58%;
216+
max-width: 800px;
217+
box-sizing: border-box;
218+
text-align: center;
219+
font-size: 1.5rem;
220+
}
221+
222+
.total_count.hidden {
223+
display: none;
224+
}
225+
213226
.filters-container {
214227
display: flex;
215228
flex-direction: column;

applications/utils.js

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,14 +13,22 @@ function createElement({ type, attributes = {}, innerText }) {
1313
return element;
1414
}
1515

16-
async function getApplications({ applicationStatus, size = 6, next = '' }) {
16+
async function getApplications({
17+
applicationStatus,
18+
size = 6,
19+
next = '',
20+
dev = false,
21+
}) {
1722
let url;
1823

1924
if (next) url = `${BASE_URL}${next}`;
2025
else if (applicationStatus === 'all') {
2126
url = `${BASE_URL}/applications?size=${size}`;
2227
} else {
2328
url = `${BASE_URL}/applications?size=${size}&status=${applicationStatus}`;
29+
if (dev) {
30+
url += '&dev=true';
31+
}
2432
}
2533

2634
try {

0 commit comments

Comments
 (0)