From 42391838fdc22984e208a5c26a4f943dcb8e1912 Mon Sep 17 00:00:00 2001 From: Shubham Sharma Date: Wed, 13 Mar 2024 21:27:20 +0530 Subject: [PATCH 1/9] modified task status flow according to Task card improvements #554 --- app/controllers/tasks.js | 94 +++++++++++++++++++--- tests/integration/components/tasks-test.js | 75 +++++++++++++++++ 2 files changed, 157 insertions(+), 12 deletions(-) diff --git a/app/controllers/tasks.js b/app/controllers/tasks.js index bdcfbe04..276aadbf 100644 --- a/app/controllers/tasks.js +++ b/app/controllers/tasks.js @@ -42,7 +42,7 @@ export default class TasksController extends Controller { @tracked showTasks = false; @tracked showFetchButton = this.isShowFetchButton() && !this.alreadyFetched; alreadyFetched = localStorage.getItem('already-fetched'); - + resetCurrentTask = null; get isDevMode() { return this.featureFlag.isDevMode; } @@ -97,16 +97,23 @@ export default class TasksController extends Controller { const requestBody = { ...object }; const taskCompletionPercentage = object.percentCompleted; if (taskCompletionPercentage) { - if (taskCompletionPercentage === TASK_PERCENTAGE.completedPercentage) { - this.isDevMode === true - ? (requestBody.status = 'DONE') - : (requestBody.status = 'COMPLETED'); + if ( + taskCompletionPercentage === TASK_PERCENTAGE.completedPercentage && + !this.dev + ) { + requestBody.status = 'COMPLETED'; } requestBody.percentCompleted = parseInt(taskCompletionPercentage); } return requestBody; } - + getTaskById(taskId) { + const indexOfSelectedTask = this.allTasks.findIndex( + (task) => task.id === taskId + ); + const selectedTask = this.allTasks[indexOfSelectedTask]; + return selectedTask; + } @action goBack() { this.showModal = false; this.onTaskChange('percentCompleted', '75'); @@ -143,9 +150,12 @@ export default class TasksController extends Controller { delete this.taskFields[prop]; } this.taskFields[key] = value; + if (this.resetCurrentTask) { + this.resetCurrentTask(); + } } - @action async updateTask(taskId, error) { + @action async updateTask(taskId) { this.disabled = true; this.buttonRequired = false; const taskData = this.taskFields; @@ -195,7 +205,9 @@ export default class TasksController extends Controller { toastNotificationTimeoutOptions ); this.disabled = false; - error(); + if (this.resetCurrentTask) { + this.resetCurrentTask(); + } } } catch (err) { this.toast.error( @@ -204,7 +216,9 @@ export default class TasksController extends Controller { toastNotificationTimeoutOptions ); console.error('Error : ', err); - error(); + if (this.resetCurrentTask) { + this.resetCurrentTask(); + } } finally { this.disabled = false; } @@ -263,15 +277,71 @@ export default class TasksController extends Controller { } } - @action async handleUpdateTask(taskId, error) { + @action async handleUpdateTask(taskId, resetCurrentTask) { + this.resetCurrentTask = resetCurrentTask; const taskData = this.taskFields; - if (taskData.percentCompleted === TASK_PERCENTAGE.completedPercentage) { + const currentTask = this.getTaskById(taskId); + const isCurrentTaskStatusInProgress = + currentTask.status === this.TASK_KEYS.IN_PROGRESS; + const isCurrentTaskStatusBlock = + currentTask.status === this.TASK_KEYS.BLOCKED; + const isNewTaskStatusInProgress = + taskData.status === this.TASK_KEYS.IN_PROGRESS; + const isNewTaskStatusBlock = taskData.status === this.TASK_KEYS.BLOCKED; + const isCurrProgress100 = + parseInt(currentTask.percentCompleted || 0) === 100; + const isCurrProgress0 = parseInt(currentTask.percentCompleted || 0) === 0; + + if (this.dev && taskData.status) { + if ( + isNewTaskStatusInProgress && + !isCurrentTaskStatusBlock && + !isCurrProgress0 + ) { + this.message = 'Proceeding further will make task progress 0%.'; + this.showModal = true; + this.buttonRequired = true; + this.tempTaskId = taskId; + this.taskFields.percentCompleted = 0; + + return; + } + if ( + isCurrentTaskStatusInProgress && + !isNewTaskStatusBlock && + !isCurrProgress100 + ) { + this.message = 'Proceeding further will make task progress 100%.'; + this.showModal = true; + this.buttonRequired = true; + this.tempTaskId = taskId; + this.taskFields.percentCompleted = 100; + return; + } + if ( + isCurrentTaskStatusBlock && + !isNewTaskStatusInProgress && + !isCurrProgress100 + ) { + this.message = `The progress of current task is ${currentTask.percentCompleted}%. Proceeding further will make task progress 100%.`; + this.showModal = true; + this.buttonRequired = true; + this.tempTaskId = taskId; + this.taskFields.percentCompleted = 100; + return; + } + } + + if ( + taskData.percentCompleted === TASK_PERCENTAGE.completedPercentage && + !this.dev + ) { this.message = TASK_MESSAGES.MARK_DONE; this.showModal = true; this.buttonRequired = true; this.tempTaskId = taskId; } else { - return this.updateTask(taskId, error); + return this.updateTask(taskId); } } } diff --git a/tests/integration/components/tasks-test.js b/tests/integration/components/tasks-test.js index 9a76cd46..001763cc 100644 --- a/tests/integration/components/tasks-test.js +++ b/tests/integration/components/tasks-test.js @@ -80,4 +80,79 @@ module('Integration | Component | tasks', function (hooks) { ); assert.dom('[data-test-task-spinner]').doesNotExist(); }); + test('changing the task status from any status other than BLOCKED to IN_PROGRESS inform proceeding further will make progress 0', async function (assert) { + tasks[0].status = 'SMOKE_TESTING'; + this.set('dev', true); + const ctrl = this.owner.lookup('controller:tasks'); + + // before action + assert.equal(ctrl.showModal, false); + assert.equal(ctrl.message, ''); + + ctrl.allTasks = tasks; + ctrl.dev = true; + ctrl.taskFields = { + status: 'IN_PROGRESS', + }; + + //action + ctrl.send('handleUpdateTask', tasks[0].id, () => {}); + + //after action + assert.equal(ctrl.showModal, true); + assert.equal( + ctrl.message, + 'Proceeding further will make task progress 0%.' + ); + }); + test('changing the task status from IN_PROGRESS to any status other than BLOCKED inform proceeding further will make progress 100', async function (assert) { + tasks[0].status = 'IN_PROGRESS'; + this.set('dev', true); + const ctrl = this.owner.lookup('controller:tasks'); + + // before action + assert.equal(ctrl.showModal, false); + assert.equal(ctrl.message, ''); + + ctrl.allTasks = tasks; + ctrl.dev = true; + ctrl.taskFields = { + status: 'SMOKE_TESTING', + }; + + // action + ctrl.send('handleUpdateTask', tasks[0].id, () => {}); + + // after action + assert.equal(ctrl.showModal, true); + assert.equal( + ctrl.message, + 'Proceeding further will make task progress 100%.' + ); + }); + test('changing the task status from BLOCKED to any status other than IN_PROGRESS when percentCompleted is less than 100, inform the user proceeding further will make progress 100', async function (assert) { + tasks[0].status = 'BLOCKED'; + this.set('dev', true); + const ctrl = this.owner.lookup('controller:tasks'); + + // before action + assert.equal(ctrl.showModal, false); + assert.equal(ctrl.message, ''); + + ctrl.allTasks = tasks; + ctrl.dev = true; + ctrl.taskFields = { + status: 'SMOKE_TESTING', + }; + + // action + ctrl.send('handleUpdateTask', tasks[0].id, () => {}); + + // after action + assert.equal(ctrl.showModal, true); + assert.equal( + ctrl.message, + `The progress of current task is ${tasks[0].percentCompleted}%. Proceeding further will make task progress 100%.` + ); + }); }); From 50e89ff6e993c321ea25157c1db17f89feb6a725 Mon Sep 17 00:00:00 2001 From: Shubham Sharma Date: Sun, 17 Mar 2024 11:43:08 +0530 Subject: [PATCH 2/9] Created showTaskChangeInfoModal function to open modal, removed if cdn and converted into switch case --- app/constants/tasks.js | 2 ++ app/controllers/tasks.js | 66 ++++++++++++++++++---------------------- 2 files changed, 32 insertions(+), 36 deletions(-) diff --git a/app/constants/tasks.js b/app/constants/tasks.js index 289e64bf..ad56ef42 100644 --- a/app/constants/tasks.js +++ b/app/constants/tasks.js @@ -141,6 +141,8 @@ export const TASK_MESSAGES = { MARK_DONE: 'This task will be marked as Done', UPDATE_TASK: 'Updating task', FIND_TASK: 'Finding new task for you!', + CHANGE_TO_100_PROGRESS: 'Proceeding further will make task progress 100%.', + CHANGE_TO_0_PROGRESS: 'Proceeding further will make task progress 0%.', }; export const TASK_PERCENTAGE = { diff --git a/app/controllers/tasks.js b/app/controllers/tasks.js index 276aadbf..8b982dd9 100644 --- a/app/controllers/tasks.js +++ b/app/controllers/tasks.js @@ -276,13 +276,15 @@ export default class TasksController extends Controller { ); } } - + showTaskChangeInfoModal(msg) { + this.message = msg; + this.showModal = true; + this.buttonRequired = true; + } @action async handleUpdateTask(taskId, resetCurrentTask) { this.resetCurrentTask = resetCurrentTask; const taskData = this.taskFields; const currentTask = this.getTaskById(taskId); - const isCurrentTaskStatusInProgress = - currentTask.status === this.TASK_KEYS.IN_PROGRESS; const isCurrentTaskStatusBlock = currentTask.status === this.TASK_KEYS.BLOCKED; const isNewTaskStatusInProgress = @@ -291,55 +293,47 @@ export default class TasksController extends Controller { const isCurrProgress100 = parseInt(currentTask.percentCompleted || 0) === 100; const isCurrProgress0 = parseInt(currentTask.percentCompleted || 0) === 0; - + this.tempTaskId = taskId; if (this.dev && taskData.status) { + if (!isCurrProgress100) { + switch (currentTask.status) { + case this.TASK_KEYS.IN_PROGRESS: + if (!isNewTaskStatusBlock) { + this.showTaskChangeInfoModal( + TASK_MESSAGES.CHANGE_TO_100_PROGRESS + ); + this.taskFields.percentCompleted = 100; + } + return; + case this.TASK_KEYS.BLOCKED: + if (!isNewTaskStatusInProgress) { + this.showTaskChangeInfoModal( + `The progress of current task is ${currentTask.percentCompleted}%. ${TASK_MESSAGES.CHANGE_TO_100_PROGRESS}` + ); + this.taskFields.percentCompleted = 100; + } + return; + default: + break; + } + } if ( isNewTaskStatusInProgress && !isCurrentTaskStatusBlock && !isCurrProgress0 ) { - this.message = 'Proceeding further will make task progress 0%.'; - this.showModal = true; - this.buttonRequired = true; - this.tempTaskId = taskId; + this.showTaskChangeInfoModal(TASK_MESSAGES.CHANGE_TO_0_PROGRESS); this.taskFields.percentCompleted = 0; return; } - if ( - isCurrentTaskStatusInProgress && - !isNewTaskStatusBlock && - !isCurrProgress100 - ) { - this.message = 'Proceeding further will make task progress 100%.'; - this.showModal = true; - this.buttonRequired = true; - this.tempTaskId = taskId; - this.taskFields.percentCompleted = 100; - return; - } - if ( - isCurrentTaskStatusBlock && - !isNewTaskStatusInProgress && - !isCurrProgress100 - ) { - this.message = `The progress of current task is ${currentTask.percentCompleted}%. Proceeding further will make task progress 100%.`; - this.showModal = true; - this.buttonRequired = true; - this.tempTaskId = taskId; - this.taskFields.percentCompleted = 100; - return; - } } if ( taskData.percentCompleted === TASK_PERCENTAGE.completedPercentage && !this.dev ) { - this.message = TASK_MESSAGES.MARK_DONE; - this.showModal = true; - this.buttonRequired = true; - this.tempTaskId = taskId; + this.showTaskChangeInfoModal(TASK_MESSAGES.MARK_DONE); } else { return this.updateTask(taskId); } From 3089b67cb24bc776454bf40af484a3cc67d4ffe9 Mon Sep 17 00:00:00 2001 From: Shubham Sharma Date: Sun, 17 Mar 2024 11:48:00 +0530 Subject: [PATCH 3/9] Added space --- app/controllers/tasks.js | 1 + 1 file changed, 1 insertion(+) diff --git a/app/controllers/tasks.js b/app/controllers/tasks.js index 8b982dd9..bc28a3f3 100644 --- a/app/controllers/tasks.js +++ b/app/controllers/tasks.js @@ -294,6 +294,7 @@ export default class TasksController extends Controller { parseInt(currentTask.percentCompleted || 0) === 100; const isCurrProgress0 = parseInt(currentTask.percentCompleted || 0) === 0; this.tempTaskId = taskId; + if (this.dev && taskData.status) { if (!isCurrProgress100) { switch (currentTask.status) { From 7334ad96feffcb4659fa949c1e8cca57e952f012 Mon Sep 17 00:00:00 2001 From: Shubham Sharma Date: Sun, 17 Mar 2024 12:08:38 +0530 Subject: [PATCH 4/9] Corrected small ix --- app/controllers/tasks.js | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/app/controllers/tasks.js b/app/controllers/tasks.js index bc28a3f3..94bd0106 100644 --- a/app/controllers/tasks.js +++ b/app/controllers/tasks.js @@ -304,20 +304,23 @@ export default class TasksController extends Controller { TASK_MESSAGES.CHANGE_TO_100_PROGRESS ); this.taskFields.percentCompleted = 100; + return; } - return; + break; case this.TASK_KEYS.BLOCKED: if (!isNewTaskStatusInProgress) { this.showTaskChangeInfoModal( `The progress of current task is ${currentTask.percentCompleted}%. ${TASK_MESSAGES.CHANGE_TO_100_PROGRESS}` ); this.taskFields.percentCompleted = 100; + return; } - return; + break; default: break; } } + if ( isNewTaskStatusInProgress && !isCurrentTaskStatusBlock && From b078fce410e4457dd8121b3e7e9da0eede8ab256 Mon Sep 17 00:00:00 2001 From: Shubham Sharma Date: Mon, 18 Mar 2024 08:36:01 +0530 Subject: [PATCH 5/9] Removed switch and case statements --- app/controllers/tasks.js | 38 +++++++++++++++----------------------- 1 file changed, 15 insertions(+), 23 deletions(-) diff --git a/app/controllers/tasks.js b/app/controllers/tasks.js index 94bd0106..4f04c829 100644 --- a/app/controllers/tasks.js +++ b/app/controllers/tasks.js @@ -287,6 +287,8 @@ export default class TasksController extends Controller { const currentTask = this.getTaskById(taskId); const isCurrentTaskStatusBlock = currentTask.status === this.TASK_KEYS.BLOCKED; + const isCurrentTaskStatusInProgress = + this.TASK_KEYS.IN_PROGRESS === currentTask.status; const isNewTaskStatusInProgress = taskData.status === this.TASK_KEYS.IN_PROGRESS; const isNewTaskStatusBlock = taskData.status === this.TASK_KEYS.BLOCKED; @@ -296,29 +298,19 @@ export default class TasksController extends Controller { this.tempTaskId = taskId; if (this.dev && taskData.status) { - if (!isCurrProgress100) { - switch (currentTask.status) { - case this.TASK_KEYS.IN_PROGRESS: - if (!isNewTaskStatusBlock) { - this.showTaskChangeInfoModal( - TASK_MESSAGES.CHANGE_TO_100_PROGRESS - ); - this.taskFields.percentCompleted = 100; - return; - } - break; - case this.TASK_KEYS.BLOCKED: - if (!isNewTaskStatusInProgress) { - this.showTaskChangeInfoModal( - `The progress of current task is ${currentTask.percentCompleted}%. ${TASK_MESSAGES.CHANGE_TO_100_PROGRESS}` - ); - this.taskFields.percentCompleted = 100; - return; - } - break; - default: - break; - } + if ( + (isCurrentTaskStatusBlock || isCurrentTaskStatusInProgress) && + !isCurrProgress100 && + !isNewTaskStatusBlock && + !isNewTaskStatusInProgress + ) { + this.taskFields.percentCompleted = 100; + let msg = !isNewTaskStatusInProgress + ? `The progress of current task is ${currentTask.percentCompleted}%. ` + : ''; + this.showTaskChangeInfoModal( + `${msg}${TASK_MESSAGES.CHANGE_TO_100_PROGRESS}` + ); } if ( From 36d17e8c24f405a0fe070ebe6ece3847005e8a08 Mon Sep 17 00:00:00 2001 From: Shubham Sharma Date: Mon, 18 Mar 2024 08:38:52 +0530 Subject: [PATCH 6/9] Added return statement --- app/controllers/tasks.js | 1 + 1 file changed, 1 insertion(+) diff --git a/app/controllers/tasks.js b/app/controllers/tasks.js index 4f04c829..661900c2 100644 --- a/app/controllers/tasks.js +++ b/app/controllers/tasks.js @@ -311,6 +311,7 @@ export default class TasksController extends Controller { this.showTaskChangeInfoModal( `${msg}${TASK_MESSAGES.CHANGE_TO_100_PROGRESS}` ); + return; } if ( From 3ea8eddb80e51ff0e95a1defe1504607ac106eb6 Mon Sep 17 00:00:00 2001 From: Shubham Sharma Date: Mon, 18 Mar 2024 08:51:24 +0530 Subject: [PATCH 7/9] Changed the output of a tasktest to keep it consistent --- app/controllers/tasks.js | 9 ++++----- tests/integration/components/tasks-test.js | 4 ++-- 2 files changed, 6 insertions(+), 7 deletions(-) diff --git a/app/controllers/tasks.js b/app/controllers/tasks.js index 661900c2..27412445 100644 --- a/app/controllers/tasks.js +++ b/app/controllers/tasks.js @@ -305,11 +305,8 @@ export default class TasksController extends Controller { !isNewTaskStatusInProgress ) { this.taskFields.percentCompleted = 100; - let msg = !isNewTaskStatusInProgress - ? `The progress of current task is ${currentTask.percentCompleted}%. ` - : ''; this.showTaskChangeInfoModal( - `${msg}${TASK_MESSAGES.CHANGE_TO_100_PROGRESS}` + `The progress of current task is ${currentTask.percentCompleted}%. ${TASK_MESSAGES.CHANGE_TO_100_PROGRESS}` ); return; } @@ -319,7 +316,9 @@ export default class TasksController extends Controller { !isCurrentTaskStatusBlock && !isCurrProgress0 ) { - this.showTaskChangeInfoModal(TASK_MESSAGES.CHANGE_TO_0_PROGRESS); + this.showTaskChangeInfoModal( + `The progress of current task is ${currentTask.percentCompleted}%. ${TASK_MESSAGES.CHANGE_TO_0_PROGRESS}` + ); this.taskFields.percentCompleted = 0; return; diff --git a/tests/integration/components/tasks-test.js b/tests/integration/components/tasks-test.js index 001763cc..e29e8cbb 100644 --- a/tests/integration/components/tasks-test.js +++ b/tests/integration/components/tasks-test.js @@ -102,7 +102,7 @@ module('Integration | Component | tasks', function (hooks) { assert.equal(ctrl.showModal, true); assert.equal( ctrl.message, - 'Proceeding further will make task progress 0%.' + 'The progress of current task is 25%. Proceeding further will make task progress 0%.' ); }); test('changing the task status from IN_PROGRESS to any status other than BLOCKED inform proceeding further will make progress 100', async function (assert) { @@ -127,7 +127,7 @@ module('Integration | Component | tasks', function (hooks) { assert.equal(ctrl.showModal, true); assert.equal( ctrl.message, - 'Proceeding further will make task progress 100%.' + 'The progress of current task is 25%. Proceeding further will make task progress 100%.' ); }); test('changing the task status from BLOCKED to any status other than IN_PROGRESS when percentCompleted is less than 100, inform the user proceeding further will make progress 100', async function (assert) { From 325c4bddd882a5ece1ef3cb7e848a7e1de76eebf Mon Sep 17 00:00:00 2001 From: Shubham Sharma Date: Thu, 21 Mar 2024 08:22:26 +0530 Subject: [PATCH 8/9] Refactored code for task status change --- app/controllers/tasks.js | 106 +++++++++++++++++++++++++-------------- 1 file changed, 69 insertions(+), 37 deletions(-) diff --git a/app/controllers/tasks.js b/app/controllers/tasks.js index 27412445..33078911 100644 --- a/app/controllers/tasks.js +++ b/app/controllers/tasks.js @@ -281,48 +281,80 @@ export default class TasksController extends Controller { this.showModal = true; this.buttonRequired = true; } - @action async handleUpdateTask(taskId, resetCurrentTask) { - this.resetCurrentTask = resetCurrentTask; + isTaskStatusChanged(taskStatus, task) { + return task.status === taskStatus; + } + isProgressChanged(progress, task) { + parseInt(task.percentCompleted || 0) === progress; + } + shouldTaskProgressBe100(taskId) { + const currentTask = this.getTaskById(taskId); + const taskData = this.taskFields; + const isCurrentTaskStatusBlock = this.isTaskStatusChanged( + this.TASK_KEYS.BLOCKED, + currentTask + ); + const isCurrentTaskStatusInProgress = this.isTaskStatusChanged( + this.TASK_KEYS.IN_PROGRESS, + currentTask + ); + const isNewStatusInProgress = this.isTaskStatusChanged( + this.TASK_KEYS.IN_PROGRESS, + taskData + ); + const isNewTaskStatusBlock = this.isTaskStatusChanged( + this.TASK_KEYS.BLOCKED, + taskData + ); + + const isCurrProgress100 = this.isProgressChanged(100, currentTask); + return ( + (isCurrentTaskStatusBlock || isCurrentTaskStatusInProgress) && + !isNewStatusInProgress && + !isNewTaskStatusBlock && + !isCurrProgress100 + ); + } + shouldTaskProgressBe0(taskId) { const taskData = this.taskFields; const currentTask = this.getTaskById(taskId); - const isCurrentTaskStatusBlock = - currentTask.status === this.TASK_KEYS.BLOCKED; - const isCurrentTaskStatusInProgress = - this.TASK_KEYS.IN_PROGRESS === currentTask.status; - const isNewTaskStatusInProgress = - taskData.status === this.TASK_KEYS.IN_PROGRESS; - const isNewTaskStatusBlock = taskData.status === this.TASK_KEYS.BLOCKED; - const isCurrProgress100 = - parseInt(currentTask.percentCompleted || 0) === 100; - const isCurrProgress0 = parseInt(currentTask.percentCompleted || 0) === 0; - this.tempTaskId = taskId; + const isCurrentTaskStatusBlock = this.isTaskStatusChanged( + this.TASK_KEYS.BLOCKED, + currentTask + ); + const isNewStatusInProgress = this.isTaskStatusChanged( + this.TASK_KEYS.IN_PROGRESS, + taskData + ); + const isCurrProgress0 = this.isProgressChanged(0, currentTask); + return ( + isNewStatusInProgress && !isCurrentTaskStatusBlock && !isCurrProgress0 + ); + } + getInfoMsg(taskId) { + const currentTask = this.getTaskById(taskId); + const msg = `The progress of current task is ${currentTask.percentCompleted}%. `; - if (this.dev && taskData.status) { - if ( - (isCurrentTaskStatusBlock || isCurrentTaskStatusInProgress) && - !isCurrProgress100 && - !isNewTaskStatusBlock && - !isNewTaskStatusInProgress - ) { - this.taskFields.percentCompleted = 100; - this.showTaskChangeInfoModal( - `The progress of current task is ${currentTask.percentCompleted}%. ${TASK_MESSAGES.CHANGE_TO_100_PROGRESS}` - ); - return; - } + if (this.shouldTaskProgressBe100(taskId)) { + this.taskFields.percentCompleted = 100; + return `${msg}${TASK_MESSAGES.CHANGE_TO_100_PROGRESS}`; + } - if ( - isNewTaskStatusInProgress && - !isCurrentTaskStatusBlock && - !isCurrProgress0 - ) { - this.showTaskChangeInfoModal( - `The progress of current task is ${currentTask.percentCompleted}%. ${TASK_MESSAGES.CHANGE_TO_0_PROGRESS}` - ); - this.taskFields.percentCompleted = 0; + if (this.shouldTaskProgressBe0(taskId)) { + this.taskFields.percentCompleted = 0; - return; - } + return `${msg}${TASK_MESSAGES.CHANGE_TO_0_PROGRESS}`; + } + return; + } + @action async handleUpdateTask(taskId, resetCurrentTask) { + this.resetCurrentTask = resetCurrentTask; + const taskData = this.taskFields; + this.tempTaskId = taskId; + const msg = this.getInfoMsg(taskId); + if (this.dev && taskData.status && msg) { + this.showTaskChangeInfoModal(msg); + return; } if ( From bd296b940ca624e9578d6b920e44ccbd0d94b6b9 Mon Sep 17 00:00:00 2001 From: Shubham Sharma Date: Fri, 22 Mar 2024 00:17:43 +0530 Subject: [PATCH 9/9] Added more unit test to increase test coverage --- app/controllers/tasks.js | 48 ++++---- tests/integration/components/tasks-test.js | 26 +++++ tests/unit/components/tasks-test.js | 125 +++++++++++++++++++++ 3 files changed, 177 insertions(+), 22 deletions(-) create mode 100644 tests/unit/components/tasks-test.js diff --git a/app/controllers/tasks.js b/app/controllers/tasks.js index 33078911..e398f11b 100644 --- a/app/controllers/tasks.js +++ b/app/controllers/tasks.js @@ -164,7 +164,9 @@ export default class TasksController extends Controller { if (taskData.status || taskData.percentCompleted) { try { const response = await fetch( - `${API_BASE_URL}/tasks/self/${taskId}?userStatusFlag=true`, + `${API_BASE_URL}/tasks/self/${taskId}${ + this.dev ? '?userStatusFlag=true' : '' + }`, { method: 'PATCH', body: JSON.stringify(cleanBody), @@ -281,33 +283,33 @@ export default class TasksController extends Controller { this.showModal = true; this.buttonRequired = true; } - isTaskStatusChanged(taskStatus, task) { + isTaskStatusChanged(task, taskStatus) { return task.status === taskStatus; } - isProgressChanged(progress, task) { - parseInt(task.percentCompleted || 0) === progress; + isProgressChanged(task, progress) { + return parseInt(task.percentCompleted || 0) === progress; } shouldTaskProgressBe100(taskId) { const currentTask = this.getTaskById(taskId); const taskData = this.taskFields; const isCurrentTaskStatusBlock = this.isTaskStatusChanged( - this.TASK_KEYS.BLOCKED, - currentTask + currentTask, + this.TASK_KEYS.BLOCKED ); const isCurrentTaskStatusInProgress = this.isTaskStatusChanged( - this.TASK_KEYS.IN_PROGRESS, - currentTask + currentTask, + this.TASK_KEYS.IN_PROGRESS ); const isNewStatusInProgress = this.isTaskStatusChanged( - this.TASK_KEYS.IN_PROGRESS, - taskData + taskData, + this.TASK_KEYS.IN_PROGRESS ); const isNewTaskStatusBlock = this.isTaskStatusChanged( - this.TASK_KEYS.BLOCKED, - taskData + taskData, + this.TASK_KEYS.BLOCKED ); - const isCurrProgress100 = this.isProgressChanged(100, currentTask); + const isCurrProgress100 = this.isProgressChanged(currentTask, 100); return ( (isCurrentTaskStatusBlock || isCurrentTaskStatusInProgress) && !isNewStatusInProgress && @@ -319,14 +321,14 @@ export default class TasksController extends Controller { const taskData = this.taskFields; const currentTask = this.getTaskById(taskId); const isCurrentTaskStatusBlock = this.isTaskStatusChanged( - this.TASK_KEYS.BLOCKED, - currentTask + currentTask, + this.TASK_KEYS.BLOCKED ); const isNewStatusInProgress = this.isTaskStatusChanged( - this.TASK_KEYS.IN_PROGRESS, - taskData + taskData, + this.TASK_KEYS.IN_PROGRESS ); - const isCurrProgress0 = this.isProgressChanged(0, currentTask); + const isCurrProgress0 = this.isProgressChanged(currentTask, 0); return ( isNewStatusInProgress && !isCurrentTaskStatusBlock && !isCurrProgress0 ); @@ -351,10 +353,12 @@ export default class TasksController extends Controller { this.resetCurrentTask = resetCurrentTask; const taskData = this.taskFields; this.tempTaskId = taskId; - const msg = this.getInfoMsg(taskId); - if (this.dev && taskData.status && msg) { - this.showTaskChangeInfoModal(msg); - return; + if (this.dev && taskData.status) { + const msg = this.getInfoMsg(taskId); + if (msg) { + this.showTaskChangeInfoModal(msg); + return; + } } if ( diff --git a/tests/integration/components/tasks-test.js b/tests/integration/components/tasks-test.js index e29e8cbb..b7764e6d 100644 --- a/tests/integration/components/tasks-test.js +++ b/tests/integration/components/tasks-test.js @@ -104,6 +104,7 @@ module('Integration | Component | tasks', function (hooks) { ctrl.message, 'The progress of current task is 25%. Proceeding further will make task progress 0%.' ); + assert.equal(ctrl.taskFields.percentCompleted, 0); }); test('changing the task status from IN_PROGRESS to any status other than BLOCKED inform proceeding further will make progress 100', async function (assert) { tasks[0].status = 'IN_PROGRESS'; @@ -129,6 +130,7 @@ module('Integration | Component | tasks', function (hooks) { ctrl.message, 'The progress of current task is 25%. Proceeding further will make task progress 100%.' ); + assert.equal(ctrl.taskFields.percentCompleted, 100); }); test('changing the task status from BLOCKED to any status other than IN_PROGRESS when percentCompleted is less than 100, inform the user proceeding further will make progress 100', async function (assert) { tasks[0].status = 'BLOCKED'; @@ -154,5 +156,29 @@ module('Integration | Component | tasks', function (hooks) { ctrl.message, `The progress of current task is ${tasks[0].percentCompleted}%. Proceeding further will make task progress 100%.` ); + assert.equal(ctrl.taskFields.percentCompleted, 100); + }); + test('changing the task status from any status other than blocked and in progress to other status does not result in showing modal', async function (assert) { + tasks[0].status = 'SMOKE_TESTING'; + this.set('dev', true); + const ctrl = this.owner.lookup('controller:tasks'); + + // before action + assert.equal(ctrl.showModal, false); + assert.equal(ctrl.message, ''); + + ctrl.allTasks = tasks; + ctrl.dev = true; + ctrl.taskFields = { + status: 'NEEDS_REVIEW', + }; + + // action + ctrl.send('handleUpdateTask', tasks[0].id, () => {}); + + // after action + assert.equal(ctrl.showModal, false); + assert.equal(ctrl.message, ''); + assert.equal(ctrl.taskFields.percentCompleted, undefined); }); }); diff --git a/tests/unit/components/tasks-test.js b/tests/unit/components/tasks-test.js new file mode 100644 index 00000000..dc23a3ed --- /dev/null +++ b/tests/unit/components/tasks-test.js @@ -0,0 +1,125 @@ +import { module, test } from 'qunit'; +import { setupRenderingTest } from 'ember-qunit'; +import { tasks } from 'website-my/tests/fixtures/tasks'; +import { TASK_KEYS, TASK_MESSAGES } from 'website-my/constants/tasks'; + +module('Unit | Component | tasks', function (hooks) { + setupRenderingTest(hooks); + test('shouldTaskProgressBe100 function should return true if task is moving from in progress to task status other than blocked', async function (assert) { + tasks[0].status = 'IN_PROGRESS'; + const ctrl = this.owner.lookup('controller:tasks'); + + ctrl.getTaskById = () => tasks[0]; + ctrl.taskFields = { + status: 'SMOKE_TESTING', + }; + + const res = ctrl.shouldTaskProgressBe100(tasks[0].id); + + assert.equal(res, true); + }); + test('shouldTaskProgressBe100 function should return false if task is moving from in progress to blocked', async function (assert) { + tasks[0].status = 'BLOCKED'; + const ctrl = this.owner.lookup('controller:tasks'); + + ctrl.getTaskById = () => tasks[0]; + ctrl.taskFields = { + status: 'IN_PROGRESS', + }; + + const res = ctrl.shouldTaskProgressBe100(tasks[0].id); + + assert.equal(res, false); + }); + test('shouldTaskProgressBe0 function should return true if task is moving to in progress from any status other than block', async function (assert) { + tasks[0].status = 'SMOKE_TESTING'; + const ctrl = this.owner.lookup('controller:tasks'); + + ctrl.getTaskById = () => tasks[0]; + + ctrl.taskFields = { + status: 'IN_PROGRESS', + }; + + const res = ctrl.shouldTaskProgressBe0(tasks[0].id); + + assert.equal(res, true); + }); + test('shouldTaskProgressBe0 function should return false if task is moving to in progress from blocked status', async function (assert) { + tasks[0].status = 'BLOCKED'; + const ctrl = this.owner.lookup('controller:tasks'); + + ctrl.getTaskById = () => tasks[0]; + + ctrl.taskFields = { + status: 'IN_PROGRESS', + }; + + const res = ctrl.shouldTaskProgressBe0(tasks[0].id); + + assert.equal(res, false); + }); + test('getInfoMsg function should return current progress and warning that proceeding further will make progress 100, if shouldTaskProgressBe100 returns true', async function (assert) { + tasks[0].status = 'SMOKE_TESTING'; + const ctrl = this.owner.lookup('controller:tasks'); + + ctrl.getTaskById = () => tasks[0]; + + ctrl.shouldTaskProgressBe100 = () => true; + + const res = ctrl.getInfoMsg(tasks[0].id); + const msg = `The progress of current task is ${tasks[0].percentCompleted}%. ${TASK_MESSAGES.CHANGE_TO_100_PROGRESS}`; + + assert.equal(res, msg); + }); + test('getInfoMsg function should return current progress and warning that proceeding further will make progress 0, if shouldTaskProgressBe0 returns true', async function (assert) { + const ctrl = this.owner.lookup('controller:tasks'); + + ctrl.getTaskById = () => tasks[0]; + ctrl.shouldTaskProgressBe0 = () => true; + + const res = ctrl.getInfoMsg(tasks[0].id); + const msg = `The progress of current task is ${tasks[0].percentCompleted}%. ${TASK_MESSAGES.CHANGE_TO_0_PROGRESS}`; + + assert.equal(res, msg); + }); + test('getInfoMsg function should return undefined, if both shouldTaskProgressBe0 and shouldTaskProgressBe100 returns false', async function (assert) { + const ctrl = this.owner.lookup('controller:tasks'); + + ctrl.getTaskById = () => tasks[0]; + ctrl.shouldTaskProgressBe0 = () => false; + ctrl.shouldTaskProgressBe100 = () => false; + + const res = ctrl.getInfoMsg(tasks[0].id); + + assert.equal(res, undefined); + }); + test('isProgressChanged function should return true if percentCompleted of task is same as passed down', async function (assert) { + const ctrl = this.owner.lookup('controller:tasks'); + + const res = ctrl.isProgressChanged(tasks[0], 25); + + assert.equal(res, true); + }); + test('isProgressChanged function should return false if percentCompleted of task is different then passed down value', async function (assert) { + const ctrl = this.owner.lookup('controller:tasks'); + + const res = ctrl.isProgressChanged(tasks[0], 5); + + assert.equal(res, false); + }); + test('isTaskStatusChanged function should return true if status of task is same as passed down value', async function (assert) { + const ctrl = this.owner.lookup('controller:tasks'); + + const res = ctrl.isTaskStatusChanged(tasks[0], tasks[0].status); + + assert.equal(res, true); + }); + test('isTaskStatusChanged function should return false if status of task is different then passed down value', async function (assert) { + const ctrl = this.owner.lookup('controller:tasks'); + + const res = ctrl.isTaskStatusChanged(tasks[0], TASK_KEYS.SANITY_CHECK); + + assert.equal(res, false); + }); +});