Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dev to Main sync #587

Merged
merged 15 commits into from
Mar 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 1 addition & 3 deletions app/components/task/holder.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,7 @@
@closeModel={{this.closeExtensionModel}}
/>
{{/if}}

{{#if (not-eq this.status this.TASK_KEYS.VERIFIED)}}
{{#if (or (not-eq this.status this.TASK_KEYS.VERIFIED) (eq @dev true))}}
<div class='task-update-container'>
<label id='task-update-label' for='task-update'><b>Status:</b></label>
<select
Expand All @@ -43,7 +42,6 @@
</select>
</div>
{{/if}}

<button
class='task-card__extensionForm-button'
data-test-task-extensionForm-button
Expand Down
2 changes: 2 additions & 0 deletions app/constants/tasks.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {
Expand Down
130 changes: 113 additions & 17 deletions app/controllers/tasks.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down Expand Up @@ -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');
Expand Down Expand Up @@ -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;
Expand All @@ -154,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),
Expand Down Expand Up @@ -195,7 +207,9 @@ export default class TasksController extends Controller {
toastNotificationTimeoutOptions
);
this.disabled = false;
error();
if (this.resetCurrentTask) {
this.resetCurrentTask();
}
}
} catch (err) {
this.toast.error(
Expand All @@ -204,7 +218,9 @@ export default class TasksController extends Controller {
toastNotificationTimeoutOptions
);
console.error('Error : ', err);
error();
if (this.resetCurrentTask) {
this.resetCurrentTask();
}
} finally {
this.disabled = false;
}
Expand Down Expand Up @@ -262,16 +278,96 @@ export default class TasksController extends Controller {
);
}
}
showTaskChangeInfoModal(msg) {
this.message = msg;
this.showModal = true;
this.buttonRequired = true;
}
isTaskStatusChanged(task, taskStatus) {
return task.status === taskStatus;
}
isProgressChanged(task, progress) {
return parseInt(task.percentCompleted || 0) === progress;
}
shouldTaskProgressBe100(taskId) {
const currentTask = this.getTaskById(taskId);
const taskData = this.taskFields;
const isCurrentTaskStatusBlock = this.isTaskStatusChanged(
currentTask,
this.TASK_KEYS.BLOCKED
);
const isCurrentTaskStatusInProgress = this.isTaskStatusChanged(
currentTask,
this.TASK_KEYS.IN_PROGRESS
);
const isNewStatusInProgress = this.isTaskStatusChanged(
taskData,
this.TASK_KEYS.IN_PROGRESS
);
const isNewTaskStatusBlock = this.isTaskStatusChanged(
taskData,
this.TASK_KEYS.BLOCKED
);

const isCurrProgress100 = this.isProgressChanged(currentTask, 100);
return (
(isCurrentTaskStatusBlock || isCurrentTaskStatusInProgress) &&
!isNewStatusInProgress &&
!isNewTaskStatusBlock &&
!isCurrProgress100
);
}
shouldTaskProgressBe0(taskId) {
const taskData = this.taskFields;
const currentTask = this.getTaskById(taskId);
const isCurrentTaskStatusBlock = this.isTaskStatusChanged(
currentTask,
this.TASK_KEYS.BLOCKED
);
const isNewStatusInProgress = this.isTaskStatusChanged(
taskData,
this.TASK_KEYS.IN_PROGRESS
);
const isCurrProgress0 = this.isProgressChanged(currentTask, 0);
return (
isNewStatusInProgress && !isCurrentTaskStatusBlock && !isCurrProgress0
);
}
getInfoMsg(taskId) {
const currentTask = this.getTaskById(taskId);
const msg = `The progress of current task is ${currentTask.percentCompleted}%. `;

@action async handleUpdateTask(taskId, error) {
if (this.shouldTaskProgressBe100(taskId)) {
this.taskFields.percentCompleted = 100;
return `${msg}${TASK_MESSAGES.CHANGE_TO_100_PROGRESS}`;
}

if (this.shouldTaskProgressBe0(taskId)) {
this.taskFields.percentCompleted = 0;

return `${msg}${TASK_MESSAGES.CHANGE_TO_0_PROGRESS}`;
}
return;
}
@action async handleUpdateTask(taskId, resetCurrentTask) {
this.resetCurrentTask = resetCurrentTask;
const taskData = this.taskFields;
if (taskData.percentCompleted === TASK_PERCENTAGE.completedPercentage) {
this.message = TASK_MESSAGES.MARK_DONE;
this.showModal = true;
this.buttonRequired = true;
this.tempTaskId = taskId;
this.tempTaskId = taskId;
if (this.dev && taskData.status) {
const msg = this.getInfoMsg(taskId);
if (msg) {
this.showTaskChangeInfoModal(msg);
return;
}
}

if (
taskData.percentCompleted === TASK_PERCENTAGE.completedPercentage &&
!this.dev
) {
this.showTaskChangeInfoModal(TASK_MESSAGES.MARK_DONE);
} else {
return this.updateTask(taskId, error);
return this.updateTask(taskId);
}
}
}
101 changes: 101 additions & 0 deletions tests/integration/components/tasks-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -80,4 +80,105 @@ 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,
'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';
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 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';
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%.`
);
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);
});
});
47 changes: 47 additions & 0 deletions tests/integration/components/tasks/holder-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,53 @@ module('Integration | Component | Tasks Holder', function (hooks) {
.dom('[data-test-task-status-select]')
.hasValue(TASK_KEYS.IN_PROGRESS);
});
test('Verify task status dropdown is hidden when task status is verified', async function (assert) {
const testTask = tasksData[3];
testTask.status = TASK_KEYS.VERIFIED;

this.set('task', testTask);
this.set('mock', () => {});
this.set('onTaskUpdate', (taskId, error) => {
error();
});
this.set('isLoading', false);
this.set('disabled', false);
this.set('defaultType', DEFAULT_TASK_TYPE);

await render(hbs`<Task::Holder
@task={{this.task}}
@onTaskChange={{this.mock}}
@onStausChange={{this.mock}}
@onTaskUpdate={{this.onTaskUpdate}}
@userSelectedTask={{this.defaultType}}
@disabled={{this.disabled}}
/>`);
assert.dom('[data-test-task-status-select]').doesNotExist();
});
test('Verify task status dropdown is visible when task status is verified and feature flag is on', async function (assert) {
const testTask = tasksData[3];
testTask.status = TASK_KEYS.VERIFIED;

this.set('task', testTask);
this.set('mock', () => {});
this.set('onTaskUpdate', (taskId, error) => {
error();
});
this.set('isLoading', false);
this.set('disabled', false);
this.set('defaultType', DEFAULT_TASK_TYPE);
this.set('dev', true);
await render(hbs`<Task::Holder
@task={{this.task}}
@onTaskChange={{this.mock}}
@onStausChange={{this.mock}}
@onTaskUpdate={{this.onTaskUpdate}}
@userSelectedTask={{this.defaultType}}
@disabled={{this.disabled}}
@dev={{this.dev}}
/>`);
assert.dom('[data-test-task-status-select]').hasValue(TASK_KEYS.VERIFIED);
});

test('Verify values of task status upon api failures under feature flag', async function (assert) {
const testTask = tasksData[3];
Expand Down