Skip to content
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion src/app/curriculum/curriculum.component.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ describe('CurriculumComponent', () => {
providers: [
MockProviders(ConfigService, UserService),
MockProvider(LibraryService, {
filterValuesUpdated$: of(),
communityLibraryProjectsSource$: of([]),
numberOfPublicProjectsVisible$: of(3),
numberOfPersonalProjectsVisible$: of(2)
Expand Down
7 changes: 7 additions & 0 deletions src/app/domain/projectFilterValues.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { Subject } from 'rxjs';
import { LibraryProject } from '../modules/library/libraryProject';

export class ProjectFilterValues {
Expand All @@ -9,6 +10,8 @@ export class ProjectFilterValues {
searchValue: string = '';
standardValue: string[] = [];
unitTypeValue: string[] = [];
private updatedSource = new Subject<void>();
public updated$ = this.updatedSource.asObservable();

matches(project: LibraryProject): boolean {
return (
Expand Down Expand Up @@ -116,4 +119,8 @@ export class ProjectFilterValues {
)
);
}

emitUpdated(): void {
this.updatedSource.next();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,7 @@ describe('LibraryFiltersComponent', () => {
officialLibraryProjectsSource$: of([] as LibraryProject[]),
communityLibraryProjectsSource$: of([] as LibraryProject[]),
sharedLibraryProjectsSource$: of([] as LibraryProject[]),
personalLibraryProjectsSource$: of([] as LibraryProject[]),
filterValuesUpdated$: of()
personalLibraryProjectsSource$: of([] as LibraryProject[])
}),
ProjectFilterValues
]
Expand All @@ -45,15 +44,15 @@ describe('LibraryFiltersComponent', () => {
expect(component['disciplineOptions'].length).toBe(2);
});

it('should call LibraryService.filterValuesUpdated when the search value changes', waitForAsync(() => {
const libraryServiceFilterValuesSpy = spyOn(TestBed.get(LibraryService), 'filterValuesUpdated');
it('should call ProjectFilterValues.emitUpdated when the search value changes', waitForAsync(() => {
const spy = spyOn(TestBed.inject(ProjectFilterValues), 'emitUpdated');
component['searchUpdated']('photo');
expect(libraryServiceFilterValuesSpy).toHaveBeenCalled();
expect(spy).toHaveBeenCalled();
}));

it('should call LibraryService.filterValuesUpdated when a filter value changes', waitForAsync(() => {
const libraryServiceFilterValuesSpy = spyOn(TestBed.get(LibraryService), 'filterValuesUpdated');
it('should call ProjectFilterValues.emitUpdated when a filter value changes', waitForAsync(() => {
const spy = spyOn(TestBed.inject(ProjectFilterValues), 'emitUpdated');
component['filterUpdated'](['Earth Sciences', 'Physical Sciences'], 'discipline');
expect(libraryServiceFilterValuesSpy).toHaveBeenCalled();
expect(spy).toHaveBeenCalled();
}));
});
Original file line number Diff line number Diff line change
Expand Up @@ -52,19 +52,19 @@ export class LibraryFiltersComponent {
private libraryService: LibraryService,
private utilService: UtilService
) {
libraryService.officialLibraryProjectsSource$.subscribe((projects: LibraryProject[]) => {
this.libraryService.officialLibraryProjectsSource$.subscribe((projects: LibraryProject[]) => {
this.libraryProjects = projects;
this.populateFilterOptions();
});
libraryService.communityLibraryProjectsSource$.subscribe((projects: LibraryProject[]) => {
this.libraryService.communityLibraryProjectsSource$.subscribe((projects: LibraryProject[]) => {
this.communityProjects = projects;
this.populateFilterOptions();
});
libraryService.sharedLibraryProjectsSource$.subscribe((projects: LibraryProject[]) => {
this.libraryService.sharedLibraryProjectsSource$.subscribe((projects: LibraryProject[]) => {
this.sharedProjects = projects;
this.populateFilterOptions();
});
libraryService.personalLibraryProjectsSource$.subscribe((projects: LibraryProject[]) => {
this.libraryService.personalLibraryProjectsSource$.subscribe((projects: LibraryProject[]) => {
this.personalProjects = projects;
this.populateFilterOptions();
});
Expand Down Expand Up @@ -170,7 +170,7 @@ export class LibraryFiltersComponent {
}

private emitFilterValues(): void {
this.libraryService.filterValuesUpdated();
this.filterValues.emitUpdated();
}

protected clearFilterValues(): void {
Expand Down
4 changes: 1 addition & 3 deletions src/app/modules/library/library/library.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,7 @@ export abstract class LibraryComponent implements OnInit {
) {}

ngOnInit(): void {
this.subscriptions.add(
this.libraryService.filterValuesUpdated$.subscribe(() => this.filterUpdated())
);
this.subscriptions.add(this.filterValues.updated$.subscribe(() => this.filterUpdated()));
}

ngOnDestroy(): void {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import { ProjectFilterValues } from '../../../domain/projectFilterValues';
export class MockLibraryService {
libraryGroupsSource$ = fakeAsyncResponse({});
officialLibraryProjectsSource$ = fakeAsyncResponse([]);
filterValuesUpdated$ = of();
implementationModelOptions: LibraryGroup[] = [];
numberOfPublicProjectsVisible = new BehaviorSubject<number>(0);
getOfficialLibraryProjects() {}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ describe('PublicLibraryComponent', () => {
imports: [PublicLibraryComponent],
providers: [
MockProvider(LibraryService, {
filterValuesUpdated$: of(),
communityLibraryProjectsSource$: of([
{ id: 1, name: 'P1' },
{ id: 2, name: 'P2' }
Expand Down
7 changes: 0 additions & 7 deletions src/app/services/library.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,6 @@ import { Router } from '@angular/router';
export class LibraryService {
private libraryGroupsUrl = '/api/project/library';
private communityProjectsUrl = '/api/project/community';
private filterValuesUpdatedSource = new Subject<void>();
public filterValuesUpdated$ = this.filterValuesUpdatedSource.asObservable();
private personalProjectsUrl = '/api/project/personal';
private sharedProjectsUrl = '/api/project/shared';
private copyProjectUrl = '/api/project/copy';
Expand Down Expand Up @@ -127,10 +125,6 @@ export class LibraryService {
return this.http.post(this.copyProjectUrl, body, { headers: headers });
}

filterValuesUpdated(): void {
this.filterValuesUpdatedSource.next();
}

addPersonalLibraryProject(project: LibraryProject) {
this.newProjectSource.next(project);
this.router.navigate(['/curriculum/personal'], { state: { newProjectId: project.id } });
Expand All @@ -154,6 +148,5 @@ export class LibraryService {
this.communityLibraryProjectsSource.next([]);
this.personalLibraryProjectsSource.next([]);
this.sharedLibraryProjectsSource.next([]);
this.filterValuesUpdatedSource.next();
}
}
44 changes: 18 additions & 26 deletions src/app/teacher/teacher-home/teacher-home.component.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,10 @@ import { User } from '../../domain/user';
import { Project } from '../../domain/project';
import { TeacherHomeComponent } from './teacher-home.component';
import { Run } from '../../domain/run';
import { NO_ERRORS_SCHEMA, Component } from '@angular/core';
import { NO_ERRORS_SCHEMA } from '@angular/core';
import { ConfigService } from '../../services/config.service';
import { Config } from '../../domain/config';
import { LibraryService } from '../../services/library.service';
import { RouterTestingModule } from '@angular/router/testing';
import { provideRouter } from '@angular/router';

export function fakeAsyncResponse<T>(data: T) {
return defer(() => Promise.resolve(data));
Expand Down Expand Up @@ -39,7 +38,7 @@ export class MockTeacherService {
run2.project = project2;
runs.push(run1);
runs.push(run2);
return Observable.create((observer) => {
return new Observable((observer) => {
observer.next(runs);
observer.complete();
});
Expand All @@ -65,16 +64,16 @@ export class MockUserService {
user.roles = ['teacher'];
user.username = 'DemoTeacher';
user.id = 123456;
return Observable.create((observer) => {
observer.next(user);
return new Observable((observer) => {
observer.next([user]);
observer.complete();
});
}
}

export class MockConfigService {
getConfig(): Observable<Config> {
return Observable.create((observer) => {
return new Observable((observer) => {
const config: Config = {
contextPath: '/wise',
logOutURL: '/logout',
Expand All @@ -98,29 +97,22 @@ export class MockConfigService {
}
}

export class MockLibraryService {
clearAll(): void {}
}

describe('TeacherHomeComponent', () => {
let component: TeacherHomeComponent;
let fixture: ComponentFixture<TeacherHomeComponent>;

beforeEach(
waitForAsync(() => {
TestBed.configureTestingModule({
declarations: [TeacherHomeComponent],
imports: [RouterTestingModule],
providers: [
{ provide: TeacherService, useClass: MockTeacherService },
{ provide: UserService, useClass: MockUserService },
{ provide: ConfigService, useClass: MockConfigService },
{ provide: LibraryService, useClass: MockLibraryService }
],
schemas: [NO_ERRORS_SCHEMA]
}).compileComponents();
})
);
beforeEach(waitForAsync(() => {
TestBed.configureTestingModule({
declarations: [TeacherHomeComponent],
providers: [
{ provide: TeacherService, useClass: MockTeacherService },
{ provide: UserService, useClass: MockUserService },
{ provide: ConfigService, useClass: MockConfigService },
provideRouter([])
],
schemas: [NO_ERRORS_SCHEMA]
}).compileComponents();
}));

beforeEach(() => {
fixture = TestBed.createComponent(TeacherHomeComponent);
Expand Down
14 changes: 4 additions & 10 deletions src/app/teacher/teacher-home/teacher-home.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,13 @@ import { UserService } from '../../services/user.service';
import { User } from '../../domain/user';
import { ConfigService } from '../../services/config.service';
import { MatTabGroup } from '@angular/material/tabs';
import { LibraryService } from '../../services/library.service';
import { Router } from '@angular/router';

@Component({
selector: 'app-teacher-home',
templateUrl: './teacher-home.component.html',
styleUrls: ['./teacher-home.component.scss'],
standalone: false
selector: 'app-teacher-home',
templateUrl: './teacher-home.component.html',
styleUrls: ['./teacher-home.component.scss'],
standalone: false
})
export class TeacherHomeComponent implements OnInit {
@ViewChild('tabs', { static: true }) tabs: MatTabGroup;
Expand All @@ -26,7 +25,6 @@ export class TeacherHomeComponent implements OnInit {
constructor(
private userService: UserService,
private configService: ConfigService,
private libraryService: LibraryService,
private router: Router
) {}

Expand All @@ -40,10 +38,6 @@ export class TeacherHomeComponent implements OnInit {
});
}

ngOnDestroy() {
this.libraryService.clearAll();
}

getUser() {
this.userService.getUser().subscribe((user) => {
this.user = user;
Expand Down
1 change: 1 addition & 0 deletions src/assets/wise5/authoringTool/new-project-template.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ export const newProjectTemplate = {
},
metadata: {
title: '',
features: [],
resources: [],
unitType: 'Platform'
},
Expand Down
Loading
Loading