diff --git a/src/app/services/structure-list.service.spec.ts b/src/app/services/structure-list.service.spec.ts index 230f2e331d15a4316a931d442b658b48a4d2a5f6..5a1b05cc44b9160457a6d3b5b0744cac775d9f14 100644 --- a/src/app/services/structure-list.service.spec.ts +++ b/src/app/services/structure-list.service.spec.ts @@ -2,6 +2,7 @@ import { HttpClientTestingModule } from '@angular/common/http/testing'; import { inject, TestBed } from '@angular/core/testing'; import { Day } from '../models/day.model'; import { Structure } from '../models/structure.model'; +import { Time } from '../models/time.model'; import { Week } from '../models/week.model'; import { StructureService } from './structure-list.service'; const { DateTime } = require('luxon'); @@ -28,12 +29,11 @@ describe('StructureService', () => { s.hours.friday = new Day(false); s.hours.saturday = new Day(false); s.hours.sunday = new Day(false); - s.hours.thursday.open = true; - s.hours.thursday.time = [ - { openning: 805, closing: 1200 }, - { openning: 1400, closing: 1600 }, - ]; + s.hours.thursday.time = new Array( + new Time({ openning: 805, closing: 1200 }), + new Time({ openning: 1400, closing: 1600 }) + ); // Init date sur un jeudi à 9h05 const dt = new DateTime.local(2020, 10, 8, 9, 5); @@ -54,8 +54,7 @@ describe('StructureService', () => { s.hours.sunday = new Day(); s.hours.thursday.open = true; - s.hours.thursday.time = [{ openning: 1400, closing: 1600 }]; - + s.hours.thursday.time = new Array(new Time({ openning: 1400, closing: 1600 })); // Init date sur un jeudi à 9h05 const dt = new DateTime.local(2020, 10, 8, 9, 5); const result = structureService.updateOpeningStructure(s, dt); 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 57437de6cf46cc7e7a9296e28c81ec225dc84cbd..98f61f1d4fb7777108336b15010f2110a1949659 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 @@ -1,6 +1,6 @@ <div *ngIf="modalType" - (clickOutside)="emitModules(modules)" + (clickOutside)="closeModal()" fxLayout="column" fxLayoutAlign="space-between" [ngClass]="['modal', 'modal' + modalType]" 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 9c1ad3d140e147fb54201d06335a3fcd2f06e378..cac3dc7a3e005f6151981d063c666afd838b3e60 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 @@ -29,58 +29,57 @@ describe('ModalFilterComponent', () => { 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 }, + { 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.emitModules(); + component.emitModules(modules); 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 }, + { 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'); + 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 }, + { 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 } }; + 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 }, + { 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 } }; + 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 }, + { 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]] }; 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 f4056cd8b8a8aef3819427e7bfeb12d7daceccf0..d987c05f24af2e9e1adda40b141d8ea8de24a16a 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 @@ -18,6 +18,7 @@ export class ModalFilterComponent implements OnInit { @Input() public categories: Category[]; @Input() public modules: Module[] = []; @Output() searchEvent = new EventEmitter(); + @Output() closeEvent = new EventEmitter(); // Checkbox variable checkedModules: Module[]; // Form search input @@ -62,4 +63,8 @@ export class ModalFilterComponent implements OnInit { public emitModules(m: Module[]): void { this.searchEvent.emit(m); } + + public closeModal(): void { + this.closeEvent.emit(); + } } diff --git a/src/app/structure-list/components/search/search.component.html b/src/app/structure-list/components/search/search.component.html index 848365d03d1c680522b182d3435a021822c82705..fb135ddadb2df2f4f008a4788f27f115410436df 100644 --- a/src/app/structure-list/components/search/search.component.html +++ b/src/app/structure-list/components/search/search.component.html @@ -28,7 +28,6 @@ <div class="btnSection" fxLayout="row" fxLayoutAlign="space-between center"> <button type="button" - [disabled]="modalTypeOpened === TypeModal[0]" [ngClass]="{ selected: modalTypeOpened === TypeModal[0], containCheckedFilters: numberAccompanimentChecked }" (click)="openModal(TypeModal[0])" fxLayout="row" @@ -39,7 +38,6 @@ </button> <button type="button" - [disabled]="modalTypeOpened === TypeModal[1]" [ngClass]="{ selected: modalTypeOpened === TypeModal[1], containCheckedFilters: numberTrainingChecked }" (click)="openModal(TypeModal[1])" fxLayout="row" @@ -50,7 +48,6 @@ </button> <button type="button" - [disabled]="modalTypeOpened === TypeModal[2]" [ngClass]="{ selected: modalTypeOpened === TypeModal[2], containCheckedFilters: numberMoreFiltersChecked }" (click)="openModal(TypeModal[2])" fxLayout="row" @@ -66,6 +63,7 @@ [categories]="categories" [modules]="checkedModulesFilter" (searchEvent)="fetchResults($event)" + (closeEvent)="closeModal()" ></app-modal-filter> </div> </div> diff --git a/src/app/structure-list/components/search/search.component.spec.ts b/src/app/structure-list/components/search/search.component.spec.ts index a5507ed760dbed84c2fd7f249061d9e59eac3156..a4cdfb3996a5c88e92c2e04568d4202fbfabe0a3 100644 --- a/src/app/structure-list/components/search/search.component.spec.ts +++ b/src/app/structure-list/components/search/search.component.spec.ts @@ -1,11 +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 { HttpClientTestingModule } from '@angular/common/http/testing'; import { SearchComponent } from './search.component'; -import { TypeModal } from '../../enum/typeModal.enum'; describe('SearchComponent', () => { let component: SearchComponent; @@ -35,14 +32,4 @@ describe('SearchComponent', () => { expect(component.searchEvent.emit).toHaveBeenCalled(); expect(component.searchEvent.emit).toHaveBeenCalledWith(filter); }); - - it('should update categories', () => { - let categories: Category[] = [new Category({ name: 'Accompagnement des démarches' })]; - categories[0].modules = []; - for (let i = 0; i < 7; i++) { - categories[0].modules.push(new Module(5 + i, 'CAF' + i)); - } - component.openModal(TypeModal[0]); - expect(component.categories).toEqual(categories); - }); }); diff --git a/src/app/structure-list/services/search.service.spec.ts b/src/app/structure-list/services/search.service.spec.ts index 4da5c595424448853477d2530cbc4c68d0fc84ed..666955f99731e786af4843fb684ab70f5396b7ef 100644 --- a/src/app/structure-list/services/search.service.spec.ts +++ b/src/app/structure-list/services/search.service.spec.ts @@ -21,13 +21,13 @@ describe('SearchService', () => { it('should return category with number of modules inside', () => { const structureCount: StructureCounter[] = [ - { id: 176, count: 2 }, - { id: 172, count: 1 }, - { id: 173, count: 1 }, + { id: '176', count: 2 }, + { id: '172', count: 1 }, + { id: '173', count: 1 }, ]; - const m1: Module = { id: 176, text: 'strm1', count: 0 }; - const m2: Module = { id: 173, text: 'strm2', count: 0 }; - const m3: Module = { id: 172, text: 'strm3', count: 0 }; + const m1: Module = { id: '176', text: 'strm1', count: 0 }; + const m2: Module = { id: '173', text: 'strm2', count: 0 }; + const m3: Module = { id: '172', text: 'strm3', count: 0 }; const category: Category = { name: 'strCateg', modules: [m1, m2, m3] }; const result = service.setCountModules(category, structureCount); expect(result.modules[0].count).toBe(2);