From 61dc459535ba47d9c59a8c7b257c0d3fdf909ace Mon Sep 17 00:00:00 2001 From: sunilk429 <160393886+sunilk429@users.noreply.github.com> Date: Tue, 24 Dec 2024 23:12:35 +0500 Subject: [PATCH] Feature: add skills field (#918) * featureUrl removed * removed feature/group * change class inputBox instead radioButton * task level section removed * unncessary object destruction under featureflag removed * status=available typo fixed * tests added for updated changes * Tests fixed * Added data-testid for testing,also added new tests * Test api updated to staging * refactored for readability * created a constants file * API_BASE_URL changed to stating for testing * Added data-testid for testing,also added new tests * Test api updated to staging * refactored for readability * added skills field * Tests for skills field added * restore accidently deleted css * fixed checkbox styling * fixed (Select aAll) typo and removed repeated code * Added new tests * update query selector to element id * mock skills added for testing * SKILL_TREE_BACKEND_BASE_URL imported from constants --- __tests__/tasks/task-dependency.test.js | 98 ++++++++- mock-data/constants.js | 3 + mock-data/skills/index.js | 7 + task/index.html | 47 +++++ task/script.js | 257 ++++++++++++++++++++++++ task/style.css | 148 +++++++++++++- 6 files changed, 554 insertions(+), 6 deletions(-) create mode 100644 mock-data/skills/index.js diff --git a/__tests__/tasks/task-dependency.test.js b/__tests__/tasks/task-dependency.test.js index 3043e26d..93a84b6f 100644 --- a/__tests__/tasks/task-dependency.test.js +++ b/__tests__/tasks/task-dependency.test.js @@ -2,9 +2,13 @@ const puppeteer = require('puppeteer'); const { tags } = require('../../mock-data/tags'); const { levels } = require('../../mock-data/levels'); const { users } = require('../../mock-data/users'); -const { STAGING_API_URL } = require('../../mock-data/constants'); +const { + STAGING_API_URL, + SKILL_TREE_BACKEND_BASE_URL, +} = require('../../mock-data/constants'); +const { skills } = require('../../mock-data/skills'); -describe('Input box', () => { +describe('Task Form', () => { let browser; let page; jest.setTimeout(60000); @@ -27,6 +31,7 @@ describe('Input box', () => { [`${STAGING_API_URL}/levels`]: levels, [`${STAGING_API_URL}/users`]: users, [`${STAGING_API_URL}/tags`]: tags, + [`${SKILL_TREE_BACKEND_BASE_URL}/skills`]: skills, }; if (mockResponses[url]) { @@ -136,7 +141,7 @@ describe('Input box', () => { // Dev Mode Tests describe('Dev Mode Behavior', () => { - beforeAll(async () => { + beforeEach(async () => { await page.goto('http://localhost:8000/task?dev=true'); await page.waitForNetworkIdle(); }); @@ -172,5 +177,92 @@ describe('Input box', () => { const dependsOnField = await page.$('[data-testid="dependsOn"]'); expect(dependsOnField).toBeTruthy(); }); + + it('should show skills multi-select component', async () => { + const skillsComponent = await page.$eval( + '[data-testid="skills"] .multi-select-container', + (el) => + window.getComputedStyle(el.closest('[data-testid="skills"]')).display, + ); + expect(skillsComponent).not.toBe('none'); + }); + + it('should initialize skills multi-select with options', async () => { + await page.waitForSelector('[data-testid="skills-multi-select"]'); + + // Click to open dropdown + await page.click('[data-testid="skills-select-button"]'); + + // Check if options are loaded + const options = await page.$$eval( + '[data-testid="option-label"]', + (elements) => elements.map((el) => el.textContent.trim()), + ); + + expect(options).toContain('(Select All)'); + expect(options).toContain('JavaScript'); + expect(options).toContain('React'); + expect(options).toContain('Node.js'); + }); + + it('should allow selecting and deselecting skills', async () => { + await page.waitForSelector('[data-testid="skills-multi-select"]'); + + // Open dropdown + await page.click('[data-testid="skills-select-button"]'); + + // Select JavaScript skill + await page.click('[data-value="1"]'); + + // Check if badge is created + const badge = await page.$eval( + '[data-testid="selected-items"] .badge .text', + (el) => el.textContent, + ); + expect(badge).toBe('JavaScript'); + + // Remove skill + await page.click('.badge .remove'); + + // Check if badge is removed + const badges = await page.$$('.badge'); + expect(badges.length).toBe(0); + }); + + it('should allow selecting all skills with (Select All)', async () => { + await page.waitForSelector('[data-testid="skills-multi-select"]'); + + // Open dropdown + await page.click('[data-testid="skills-select-button"]'); + + // Click (Select All) + await page.click('[data-testid="option"][data-value="select-all"]'); + + // Check if all skills are selected as badges + const badges = await page.$$eval( + '[data-testid="selected-items"] .badge .text', + (elements) => elements.map((el) => el.textContent.trim()), + ); + expect(badges).toEqual(['JavaScript', 'React', 'Node.js']); + }); + + it('should allow navigating and selecting options using the keyboard', async () => { + await page.waitForSelector('[data-testid="skills-multi-select"]'); + + // Open dropdown + await page.click('[data-testid="skills-select-button"]'); + + // Navigate and select an option + await page.keyboard.press('ArrowDown'); + await page.keyboard.press('ArrowDown'); + await page.keyboard.press('Enter'); + + // Verify badge is created + const badges = await page.$$eval( + '[data-testid="selected-items"] .badge .text', + (elements) => elements.map((el) => el.textContent.trim()), + ); + expect(badges).toContain('JavaScript'); + }); }); }); diff --git a/mock-data/constants.js b/mock-data/constants.js index 2b5b6238..c76fd0fb 100644 --- a/mock-data/constants.js +++ b/mock-data/constants.js @@ -1,7 +1,10 @@ const STAGING_API_URL = 'https://staging-api.realdevsquad.com'; const LOCAL_TEST_PAGE_URL = 'http://localhost:8000'; +const SKILL_TREE_BACKEND_BASE_URL = + 'https://services.realdevsquad.com/skilltree/v1'; module.exports = { STAGING_API_URL, LOCAL_TEST_PAGE_URL, + SKILL_TREE_BACKEND_BASE_URL, }; diff --git a/mock-data/skills/index.js b/mock-data/skills/index.js new file mode 100644 index 00000000..c01a627c --- /dev/null +++ b/mock-data/skills/index.js @@ -0,0 +1,7 @@ +const skills = [ + { id: 1, name: 'JavaScript' }, + { id: 2, name: 'React' }, + { id: 3, name: 'Node.js' }, +]; + +module.exports = { skills }; diff --git a/task/index.html b/task/index.html index b0dc59df..b31da4d3 100644 --- a/task/index.html +++ b/task/index.html @@ -101,6 +101,53 @@ /> +
+ +
+ +
+ +
+
+ (Select All) + +
+
+
+
+