From d1726ed1778329b474611eb3b622e004661a1531 Mon Sep 17 00:00:00 2001 From: Prashant Kumar <80661803+prashant67690@users.noreply.github.com> Date: Fri, 27 Sep 2024 19:23:14 +0530 Subject: [PATCH] Feature/infinite user loading (#854) * added the infinite user loading feature * fixed the bugs in the loading * altered the API_BASE_URL to original one * added the infinite user loading feature * fixed the bugs in the loading * altered the API_BASE_URL to original one * updated the loader property * updated the test for the loading feature --------- Co-authored-by: Vinit khandal <111434418+vinit717@users.noreply.github.com> --- .../users/user-management-home-screen.test.js | 32 ++--- users/constants.js | 1 + users/index.html | 2 + users/script.js | 132 +++++++++--------- users/style.css | 17 ++- 5 files changed, 95 insertions(+), 89 deletions(-) diff --git a/__tests__/users/user-management-home-screen.test.js b/__tests__/users/user-management-home-screen.test.js index fdadc710..6f1abff1 100644 --- a/__tests__/users/user-management-home-screen.test.js +++ b/__tests__/users/user-management-home-screen.test.js @@ -116,32 +116,24 @@ describe('Tests the User Management User Listing Screen', () => { expect(userCard.length).toBeGreaterThan(0); }); - it('checks the next and previous button functionality', async () => { + it('checks infinite scroll functionality to load more users', async () => { await page.goto('http://localhost:8000/users'); await page.waitForNetworkIdle(); - // 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); + const userList = await page.$('#user-list'); + let initialUserCount = await userList.$$eval('li', (items) => items.length); + expect(initialUserCount).toBeGreaterThan(0); - // Click the "next" button and wait for the page to load - await nextBtn.click(); + // Scroll to the bottom of the page to trigger infinite scroll + await page.evaluate(() => { + window.scrollTo(0, document.body.scrollHeight); + }); 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(); - - const prevBtn = await page.$('#prevButton'); - const isPrevButtonDisabled = await page.evaluate( - (button) => button.disabled, - prevBtn, + 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 () => { diff --git a/users/constants.js b/users/constants.js index 8c247612..f3ac5b2d 100644 --- a/users/constants.js +++ b/users/constants.js @@ -2,6 +2,7 @@ const RDS_API_USERS = `${API_BASE_URL}/users`; const RDS_API_SKILLS = `${API_BASE_URL}/tags`; const USER_LIST_ELEMENT = 'user-list'; const LOADER_ELEMENT = 'loader'; +const USER_LOADER_ELEMENT = 'loader_tag'; const TILE_VIEW_BTN = 'tile-view-btn'; const TABLE_VIEW_BTN = 'table-view-btn'; const USER_SEARCH_ELEMENT = 'user-search'; diff --git a/users/index.html b/users/index.html index 42e22909..5bae7582 100644 --- a/users/index.html +++ b/users/index.html @@ -69,7 +69,9 @@

Skills

+
+