Skip to content

Commit

Permalink
fix(Project Library): Search unselects projects that do not match sea…
Browse files Browse the repository at this point in the history
…rch (#1597)
  • Loading branch information
geoffreykwan authored Jan 30, 2024
1 parent f960e84 commit b6fc950
Show file tree
Hide file tree
Showing 2 changed files with 64 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -81,15 +81,36 @@ describe('PersonalLibraryComponent', () => {
allProjectsSelected_clickSelectAllProjects_unselectsAllProjects();
projectsAreSelected_goToArchivedView_projectsAreUnselected();
projectsAreSelected_goToNextPage_projectsAreUnselected();
projectsAreSelected_performSearch_projectsNotMatchingSearchAreUnselected();
});

function setUpFiveProjects() {
TestBed.inject(LibraryService).personalLibraryProjectsSource$ = fakeAsyncResponse([
new LibraryProject({ id: projectId1, metadata: {}, tags: ['archived'] }),
new LibraryProject({ id: projectId2, metadata: {}, tags: ['archived'] }),
new LibraryProject({ id: projectId3, metadata: {}, tags: [] }),
new LibraryProject({ id: projectId4, metadata: {}, tags: [] }),
new LibraryProject({ id: projectId5, metadata: {}, tags: [] })
new LibraryProject({
id: projectId1,
metadata: { title: 'Hello' },
tags: ['archived']
}),
new LibraryProject({
id: projectId2,
metadata: { title: 'Hello World' },
tags: ['archived']
}),
new LibraryProject({
id: projectId3,
metadata: { title: 'World Energy' },
tags: []
}),
new LibraryProject({
id: projectId4,
metadata: { title: 'World Climate' },
tags: []
}),
new LibraryProject({
id: projectId5,
metadata: { title: 'Recycling' },
tags: []
})
]);
}

Expand Down Expand Up @@ -227,6 +248,24 @@ function projectsAreSelected_goToNextPage_projectsAreUnselected() {
});
}

function projectsAreSelected_performSearch_projectsNotMatchingSearchAreUnselected() {
describe('projects are selected', () => {
describe('perform search', () => {
it('projects that do not match search are unselected', async () => {
await (await harness.getSelectAllCheckbox()).check();
expect(await harness.getSelectedProjectIds()).toEqual([projectId5, projectId4, projectId3]);
component.filterUpdated({
searchValue: 'world',
dciArrangementValue: [],
disciplineValue: [],
peValue: []
});
expect(await harness.getSelectedProjectIds()).toEqual([projectId4, projectId3]);
});
});
});
}

function generateExpectedProjectIds(startProjectId: number, endProjectId: number): number[] {
const expectedProjectIds = [];
for (let i = startProjectId; i >= endProjectId; i--) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,16 @@ export class PersonalLibraryComponent extends LibraryComponent {
(project) => project.hasTag('archived') == this.showArchivedView
);
this.numProjectsInView = this.getProjectsInView().length;
this.unselectProjectsOutOfView();
}

private unselectProjectsOutOfView(): void {
const projectsInView = this.getProjectsInView();
this.projects.forEach((project) => {
if (!projectsInView.includes(project)) {
this.unselectProject(project);
}
});
}

protected switchActiveArchivedView(): void {
Expand Down Expand Up @@ -147,6 +157,16 @@ export class PersonalLibraryComponent extends LibraryComponent {
this.archiveProjectService.refreshProjects();
}

private unselectProject(project: LibraryProject): void {
project.selected = false;
if (this.selectedProjects().includes(project)) {
this.selectedProjects.update((selectedProjects) => {
selectedProjects.splice(selectedProjects.indexOf(project), 1);
return selectedProjects;
});
}
}

protected unselectAllProjects(): void {
this.projects.forEach((project) => (project.selected = false));
this.selectedProjects.set([]);
Expand Down

0 comments on commit b6fc950

Please sign in to comment.