mirror of
https://github.com/HabitRPG/habitica.git
synced 2025-12-16 22:27:26 +01:00
Drag challenge tasks (#12204)
* Allow challenge tasks to be draggable by leaders and admins * Drag challenge tasks, ensure they're ordered * Ensure group tasks are ordered properly, make draggable * Add tests, fix broken tests * Resolve merge conflict * Remove console.log() * Address code review comments * Code review fixes * Fix lint * Fix importing * taskManager * Lint * Fix collapseChecklist test Co-authored-by: Sabe Jones <sabrecat@gmail.com>
This commit is contained in:
@@ -28,7 +28,6 @@ describe('DELETE /tasks/:id', () => {
|
||||
|
||||
it('deletes a user\'s task', async () => {
|
||||
await user.del(`/tasks/${task._id}`);
|
||||
|
||||
await expect(user.get(`/tasks/${task._id}`)).to.eventually.be.rejected.and.eql({
|
||||
code: 404,
|
||||
error: 'NotFound',
|
||||
|
||||
@@ -97,7 +97,7 @@ describe('POST /tasks/unlink-all/:challengeId', () => {
|
||||
await user.del(`/challenges/${challenge._id}`);
|
||||
await user.post(`/tasks/unlink-all/${challenge._id}?keep=keep-all`);
|
||||
// Get the task for the second user
|
||||
const [, anotherUserTask] = await anotherUser.get('/tasks/user');
|
||||
const [anotherUserTask] = await anotherUser.get('/tasks/user');
|
||||
// Expect the second user to still have the task, but unlinked
|
||||
expect(anotherUserTask.challenge).to.eql({
|
||||
taskId: daily._id,
|
||||
|
||||
@@ -92,16 +92,16 @@ describe('POST /tasks/unlink-one/:taskId', () => {
|
||||
|
||||
it('unlinks a task from a challenge and saves it on keep=keep', async () => {
|
||||
await user.post(`/tasks/challenge/${challenge._id}`, tasksToTest.daily);
|
||||
let [, daily] = await user.get('/tasks/user');
|
||||
let [daily] = await user.get('/tasks/user');
|
||||
await user.del(`/challenges/${challenge._id}`);
|
||||
await user.post(`/tasks/unlink-one/${daily._id}?keep=keep`);
|
||||
[, daily] = await user.get('/tasks/user');
|
||||
[daily] = await user.get('/tasks/user');
|
||||
expect(daily.challenge).to.eql({});
|
||||
});
|
||||
|
||||
it('unlinks a task from a challenge and deletes it on keep=remove', async () => {
|
||||
await user.post(`/tasks/challenge/${challenge._id}`, tasksToTest.daily);
|
||||
const [, daily] = await user.get('/tasks/user');
|
||||
const [daily] = await user.get('/tasks/user');
|
||||
await user.del(`/challenges/${challenge._id}`);
|
||||
await user.post(`/tasks/unlink-one/${daily._id}?keep=remove`);
|
||||
const tasks = await user.get('/tasks/user');
|
||||
|
||||
@@ -21,10 +21,6 @@ describe('GET /tasks/challenge/:challengeId', () => {
|
||||
up: false,
|
||||
down: true,
|
||||
},
|
||||
todo: {
|
||||
text: 'test todo',
|
||||
type: 'todo',
|
||||
},
|
||||
daily: {
|
||||
text: 'test daily',
|
||||
type: 'daily',
|
||||
@@ -32,6 +28,10 @@ describe('GET /tasks/challenge/:challengeId', () => {
|
||||
everyX: 5,
|
||||
startDate: new Date(),
|
||||
},
|
||||
todo: {
|
||||
text: 'test todo',
|
||||
type: 'todo',
|
||||
},
|
||||
reward: {
|
||||
text: 'test reward',
|
||||
type: 'reward',
|
||||
@@ -84,4 +84,35 @@ describe('GET /tasks/challenge/:challengeId', () => {
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
it('maintains challenge task order', async () => {
|
||||
const orderedTasks = {};
|
||||
Object.entries(tasksToTest).forEach(async (taskType, taskValue) => {
|
||||
const results = [];
|
||||
for (let i = 0; i < 5; i += 1) {
|
||||
results.push(user.post(`/tasks/challenge/${challenge._id}`, taskValue));
|
||||
}
|
||||
const taskList = await Promise.all(results);
|
||||
await user.post(`/tasks/${taskList[0]._id}/move/to/3`);
|
||||
|
||||
const firstTask = taskList.unshift();
|
||||
taskList.splice(3, 0, firstTask);
|
||||
|
||||
orderedTasks[taskType] = taskList;
|
||||
});
|
||||
|
||||
const results = await user.get(`/tasks/challenge/${challenge._id}`);
|
||||
const resultTasks = {};
|
||||
|
||||
results.forEach(result => {
|
||||
if (!resultTasks[result.type]) {
|
||||
resultTasks[result.type] = [];
|
||||
}
|
||||
resultTasks[result.type].push(result);
|
||||
});
|
||||
|
||||
Object.entries(orderedTasks).forEach((taskType, taskList) => {
|
||||
expect(resultTasks[taskType]).to.eql(taskList);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
@@ -17,10 +17,6 @@ describe('GET /tasks/group/:groupId', () => {
|
||||
up: false,
|
||||
down: true,
|
||||
},
|
||||
todo: {
|
||||
text: 'test todo',
|
||||
type: 'todo',
|
||||
},
|
||||
daily: {
|
||||
text: 'test daily',
|
||||
type: 'daily',
|
||||
@@ -28,6 +24,10 @@ describe('GET /tasks/group/:groupId', () => {
|
||||
everyX: 5,
|
||||
startDate: new Date(),
|
||||
},
|
||||
todo: {
|
||||
text: 'test todo',
|
||||
type: 'todo',
|
||||
},
|
||||
reward: {
|
||||
text: 'test reward',
|
||||
type: 'reward',
|
||||
@@ -78,4 +78,35 @@ describe('GET /tasks/group/:groupId', () => {
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
it('maintains group task order', async () => {
|
||||
const orderedTasks = {};
|
||||
Object.entries(tasksToTest).forEach(async (taskType, taskValue) => {
|
||||
const results = [];
|
||||
for (let i = 0; i < 5; i += 1) {
|
||||
results.push(user.post(`/tasks/group/${group._id}`, taskValue));
|
||||
}
|
||||
const taskList = await Promise.all(results);
|
||||
await user.post(`/tasks/${taskList[0]._id}/move/to/3`);
|
||||
|
||||
const firstTask = taskList.unshift();
|
||||
taskList.splice(3, 0, firstTask);
|
||||
|
||||
orderedTasks[taskType] = taskList;
|
||||
});
|
||||
|
||||
const results = await user.get(`/tasks/group/${group._id}`);
|
||||
const resultTasks = {};
|
||||
|
||||
results.forEach(result => {
|
||||
if (!resultTasks[result.type]) {
|
||||
resultTasks[result.type] = [];
|
||||
}
|
||||
resultTasks[result.type].push(result);
|
||||
});
|
||||
|
||||
Object.entries(orderedTasks).forEach((taskType, taskList) => {
|
||||
expect(resultTasks[taskType]).to.eql(taskList);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user