Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -87,4 +87,32 @@ describe('TimeTrackerProjectTaskDropdown', () => {

expect(wrapper.emitted('changed')?.at(-1)).toEqual(['', null]);
});

it('keeps a project\'s tasks visible when the search term matches the project name', async () => {
const project = {
id: 'p-dummy',
name: 'dummy',
color: '#fff',
client_id: null,
is_archived: false,
} as unknown as Project;
const tasks = [
{ id: 't-1', name: 'design', project_id: 'p-dummy', is_done: false },
{ id: 't-2', name: 'build', project_id: 'p-dummy', is_done: false },
] as unknown as Task[];

const wrapper = mountDropdown({ projects: [project], tasks });
await nextTick();
await nextTick();

const searchInput = wrapper.find('[data-testid="client_dropdown_search"]');
await searchInput.setValue('dummy');
await nextTick();

// project itself shows up
expect(wrapper.find('[data-project-id="p-dummy"]').exists()).toBe(true);
// and its tasks are still available even though they don't match "dummy":
// the task expander keeps showing all of the project's tasks
expect(wrapper.text()).toContain('2 Tasks');
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -201,21 +201,24 @@ function updateFilteredResults() {
return task.project_id === filterProject.id;
});

const filteredTasks = projectTasks.filter((filterTask) => {
return (
filterTask.name
.toLowerCase()
.includes(searchValue.value?.toLowerCase()?.trim() || '') &&
(!filterTask.is_done || filterTask.id === task.value)
);
// tasks that should be selectable regardless of the search term
// (open tasks, plus the currently selected one even if it's done)
const availableTasks = projectTasks.filter((filterTask) => {
return !filterTask.is_done || filterTask.id === task.value;
});

const filteredTasks = availableTasks.filter((filterTask) => {
return filterTask.name
.toLowerCase()
.includes(searchValue.value?.toLowerCase()?.trim() || '');
});

if (
(projectNameIncludesSearchTerm || clientNameIncludesSearchTerm) &&
(!filterProject.is_archived || project.value === filterProject.id)
) {
// search term matches project name
addProjectToFilterObject(tempFilteredClients, filterProject, filteredTasks, false);
// search term matches project (or client) name: show all the tasks
addProjectToFilterObject(tempFilteredClients, filterProject, availableTasks, false);
} else if (filteredTasks.length > 0 && !filterProject.is_archived) {
// search term matches task name
addProjectToFilterObject(tempFilteredClients, filterProject, filteredTasks, true);
Expand Down