diff --git a/debug.log b/debug.log index a9f90adc538c4dee84a607acc9dd6f88c1678973..301edff39e50e25f33e6ac1b45b246e43cc30fff 100644 --- a/debug.log +++ b/debug.log @@ -1 +1,2 @@ [1102/160447.168:ERROR:directory_reader_win.cc(43)] FindFirstFile: Le chemin d�acc�s sp�cifi� est introuvable. (0x3) +[1102/165734.564:ERROR:directory_reader_win.cc(43)] FindFirstFile: Le chemin d�acc�s sp�cifi� est introuvable. (0x3) diff --git a/src/app/structure-list/components/modal-filter/modal-filter.component.html b/src/app/structure-list/components/modal-filter/modal-filter.component.html index 12b00255953d1e95389dfdedc1a4583e05042e8a..ec2d69fb075c58894c9f0c3848264bd7f82f00fa 100644 --- a/src/app/structure-list/components/modal-filter/modal-filter.component.html +++ b/src/app/structure-list/components/modal-filter/modal-filter.component.html @@ -27,7 +27,7 @@ </div> <div class="footer" fxLayout="row" fxLayoutAlign="end center" fxLayoutGap="3vw"> <a (click)="clearFilters()">Effacer</a> - <button type="button" (click)="emitFilter()">Appliquer</button> + <button type="button" (click)="emitModules()">Appliquer</button> </div> </div> </div> diff --git a/src/app/structure-list/components/modal-filter/modal-filter.component.spec.ts b/src/app/structure-list/components/modal-filter/modal-filter.component.spec.ts index bf696da42760fd35a3c711758f0d971703b2817c..9c1ad3d140e147fb54201d06335a3fcd2f06e378 100644 --- a/src/app/structure-list/components/modal-filter/modal-filter.component.spec.ts +++ b/src/app/structure-list/components/modal-filter/modal-filter.component.spec.ts @@ -1,6 +1,8 @@ import { ComponentFixture, TestBed } from '@angular/core/testing'; import { ReactiveFormsModule } from '@angular/forms'; +import { Category } from '../../models/category.model'; import { Filter } from '../../models/filter.model'; +import { Module } from '../../models/module.model'; import { ModalFilterComponent } from './modal-filter.component'; @@ -25,9 +27,65 @@ describe('ModalFilterComponent', () => { expect(component).toBeTruthy(); }); - it('should emit filters', () => { + it('should emit modules', () => { + const modules: Module[] = [ + { id: 176, text: 'training', count: 3 }, + { id: 173, text: 'training', count: 2 }, + { id: 172, text: 'training', count: 2 }, + ]; + component.checkedModules = modules; spyOn(component.searchEvent, 'emit'); - component.emitFilter(); + component.emitModules(); expect(component.searchEvent.emit).toHaveBeenCalled(); + expect(component.searchEvent.emit).toHaveBeenCalledWith(modules); + }); + it('should return an index or -1', () => { + const modules: Module[] = [ + { id: 176, text: 'training', count: 0 }, + { id: 173, text: 'training', count: 0 }, + { id: 172, text: 'training', count: 0 }, + ]; + component.checkedModules = modules; + const foundItem = component.getIndex(173, 'training'); + const notFoundItem = component.getIndex(189, 'training'); + expect(foundItem).toEqual(1); + expect(notFoundItem).toEqual(-1); + }); + it('should add a module to checkedModule array', () => { + const modules: Module[] = [ + { id: 176, text: 'training', count: 0 }, + { id: 173, text: 'training', count: 0 }, + { id: 172, text: 'training', count: 0 }, + ]; + component.checkedModules = modules; + const evt = { target: { checked: true, value: 175 } }; + component.onCheckboxChange(evt, 'training'); + expect(component.checkedModules.length).toEqual(4); + }); + it('should remove a module to checkedModule array', () => { + const modules: Module[] = [ + { id: 176, text: 'training', count: 0 }, + { id: 173, text: 'training', count: 0 }, + { id: 172, text: 'training', count: 0 }, + ]; + component.checkedModules = modules; + const evt = { target: { checked: false, value: 173 } }; + component.onCheckboxChange(evt, 'training'); + expect(component.checkedModules.length).toEqual(2); + }); + it('should remove all modules checked from same modal, here morefilters', () => { + const modules: Module[] = [ + { id: 176, text: 'morefilters', count: 0 }, + { id: 173, text: 'morefilters', count: 0 }, + { id: 172, text: 'morefilters', count: 0 }, + { id: 179, text: 'training', count: 0 }, + { id: 190, text: 'training', count: 0 }, + { id: 167, text: 'training', count: 0 }, + ]; + component.checkedModules = modules; + const category: Category = { name: 'morefilters', modules: [modules[0], modules[1], modules[2]] }; + component.categories = [category]; + component.clearFilters(); + expect(component.checkedModules.length).toEqual(3); }); }); diff --git a/src/app/structure-list/components/modal-filter/modal-filter.component.ts b/src/app/structure-list/components/modal-filter/modal-filter.component.ts index ff6050e604f82822c80d05338c10bb6ae045da8e..2f46075fa9809c9adf2d9d261735956069d3819c 100644 --- a/src/app/structure-list/components/modal-filter/modal-filter.component.ts +++ b/src/app/structure-list/components/modal-filter/modal-filter.component.ts @@ -29,12 +29,12 @@ export class ModalFilterComponent implements OnInit { } // Return index of a specific module in array modules - private getIndex(id: number, categ: string): number { + public getIndex(id: number, categ: string): number { return this.checkedModules.findIndex((m: Module) => m.id === id && m.text === categ); } // Management of the checkbox event (Check / Uncheck) - private onCheckboxChange(event, categ: string): void { + public onCheckboxChange(event, categ: string): void { const checkValue: number = parseInt(event.target.value, 10); if (event.target.checked) { this.checkedModules.push(new Module(checkValue, categ)); @@ -47,7 +47,7 @@ export class ModalFilterComponent implements OnInit { } // Clear only filters in the current modal - private clearFilters(): void { + public clearFilters(): void { this.categories.forEach((categ: Category) => { categ.modules.forEach((module: Module) => { if (this.getIndex(module.id, categ.name) > -1) { @@ -57,8 +57,8 @@ export class ModalFilterComponent implements OnInit { }); } - // Sends an array containing all filters - public emitFilter(): void { + // Sends an array containing all modules + public emitModules(): void { this.searchEvent.emit(this.checkedModules); } } diff --git a/src/app/structure-list/components/search/search.component.ts b/src/app/structure-list/components/search/search.component.ts index 6db165c6c514a32ee3e69b37c72442046c88b2db..5ad6e6a1f9d723e7681efee243a2360f6dcfb259 100644 --- a/src/app/structure-list/components/search/search.component.ts +++ b/src/app/structure-list/components/search/search.component.ts @@ -23,12 +23,12 @@ export class SearchComponent implements OnInit { @Output() searchEvent = new EventEmitter(); // Form search input - private searchForm: FormGroup; + public searchForm: FormGroup; // Modal variable public categories: Category[]; - private modalTypeOpened: string; + public modalTypeOpened: string; // Checkbox variable - private checkedModulesFilter: Module[]; + public checkedModulesFilter: Module[]; ngOnInit(): void { // Will store the different categories