Skip to content
Snippets Groups Projects
Commit f312291f authored by Jérémie BRISON's avatar Jérémie BRISON
Browse files

fix(search) : fix unit test + fix disabled filters

parent 07807ce5
No related branches found
No related tags found
2 merge requests!31Recette,!12Topic search
...@@ -2,6 +2,7 @@ import { HttpClientTestingModule } from '@angular/common/http/testing'; ...@@ -2,6 +2,7 @@ import { HttpClientTestingModule } from '@angular/common/http/testing';
import { inject, TestBed } from '@angular/core/testing'; import { inject, TestBed } from '@angular/core/testing';
import { Day } from '../models/day.model'; import { Day } from '../models/day.model';
import { Structure } from '../models/structure.model'; import { Structure } from '../models/structure.model';
import { Time } from '../models/time.model';
import { Week } from '../models/week.model'; import { Week } from '../models/week.model';
import { StructureService } from './structure-list.service'; import { StructureService } from './structure-list.service';
const { DateTime } = require('luxon'); const { DateTime } = require('luxon');
...@@ -28,12 +29,11 @@ describe('StructureService', () => { ...@@ -28,12 +29,11 @@ describe('StructureService', () => {
s.hours.friday = new Day(false); s.hours.friday = new Day(false);
s.hours.saturday = new Day(false); s.hours.saturday = new Day(false);
s.hours.sunday = new Day(false); s.hours.sunday = new Day(false);
s.hours.thursday.open = true; s.hours.thursday.open = true;
s.hours.thursday.time = [ s.hours.thursday.time = new Array(
{ openning: 805, closing: 1200 }, new Time({ openning: 805, closing: 1200 }),
{ openning: 1400, closing: 1600 }, new Time({ openning: 1400, closing: 1600 })
]; );
// Init date sur un jeudi à 9h05 // Init date sur un jeudi à 9h05
const dt = new DateTime.local(2020, 10, 8, 9, 5); const dt = new DateTime.local(2020, 10, 8, 9, 5);
...@@ -54,8 +54,7 @@ describe('StructureService', () => { ...@@ -54,8 +54,7 @@ describe('StructureService', () => {
s.hours.sunday = new Day(); s.hours.sunday = new Day();
s.hours.thursday.open = true; 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 // Init date sur un jeudi à 9h05
const dt = new DateTime.local(2020, 10, 8, 9, 5); const dt = new DateTime.local(2020, 10, 8, 9, 5);
const result = structureService.updateOpeningStructure(s, dt); const result = structureService.updateOpeningStructure(s, dt);
......
<div <div
*ngIf="modalType" *ngIf="modalType"
(clickOutside)="emitModules(modules)" (clickOutside)="closeModal()"
fxLayout="column" fxLayout="column"
fxLayoutAlign="space-between" fxLayoutAlign="space-between"
[ngClass]="['modal', 'modal' + modalType]" [ngClass]="['modal', 'modal' + modalType]"
......
...@@ -29,58 +29,57 @@ describe('ModalFilterComponent', () => { ...@@ -29,58 +29,57 @@ describe('ModalFilterComponent', () => {
it('should emit modules', () => { it('should emit modules', () => {
const modules: Module[] = [ const modules: Module[] = [
{ id: 176, text: 'training', count: 3 }, { id: '176', text: 'training', count: 3 },
{ id: 173, text: 'training', count: 2 }, { id: '173', text: 'training', count: 2 },
{ id: 172, text: 'training', count: 2 }, { id: '172', text: 'training', count: 2 },
]; ];
component.checkedModules = modules;
spyOn(component.searchEvent, 'emit'); spyOn(component.searchEvent, 'emit');
component.emitModules(); component.emitModules(modules);
expect(component.searchEvent.emit).toHaveBeenCalled(); expect(component.searchEvent.emit).toHaveBeenCalled();
expect(component.searchEvent.emit).toHaveBeenCalledWith(modules); expect(component.searchEvent.emit).toHaveBeenCalledWith(modules);
}); });
it('should return an index or -1', () => { it('should return an index or -1', () => {
const modules: Module[] = [ const modules: Module[] = [
{ id: 176, text: 'training', count: 0 }, { id: '176', text: 'training', count: 0 },
{ id: 173, text: 'training', count: 0 }, { id: '173', text: 'training', count: 0 },
{ id: 172, text: 'training', count: 0 }, { id: '172', text: 'training', count: 0 },
]; ];
component.checkedModules = modules; component.checkedModules = modules;
const foundItem = component.getIndex(173, 'training'); const foundItem = component.getIndex('173', 'training');
const notFoundItem = component.getIndex(189, 'training'); const notFoundItem = component.getIndex('189', 'training');
expect(foundItem).toEqual(1); expect(foundItem).toEqual(1);
expect(notFoundItem).toEqual(-1); expect(notFoundItem).toEqual(-1);
}); });
it('should add a module to checkedModule array', () => { it('should add a module to checkedModule array', () => {
const modules: Module[] = [ const modules: Module[] = [
{ id: 176, text: 'training', count: 0 }, { id: '176', text: 'training', count: 0 },
{ id: 173, text: 'training', count: 0 }, { id: '173', text: 'training', count: 0 },
{ id: 172, text: 'training', count: 0 }, { id: '172', text: 'training', count: 0 },
]; ];
component.checkedModules = modules; component.checkedModules = modules;
const evt = { target: { checked: true, value: 175 } }; const evt = { target: { checked: true, value: '175' } };
component.onCheckboxChange(evt, 'training'); component.onCheckboxChange(evt, 'training');
expect(component.checkedModules.length).toEqual(4); expect(component.checkedModules.length).toEqual(4);
}); });
it('should remove a module to checkedModule array', () => { it('should remove a module to checkedModule array', () => {
const modules: Module[] = [ const modules: Module[] = [
{ id: 176, text: 'training', count: 0 }, { id: '176', text: 'training', count: 0 },
{ id: 173, text: 'training', count: 0 }, { id: '173', text: 'training', count: 0 },
{ id: 172, text: 'training', count: 0 }, { id: '172', text: 'training', count: 0 },
]; ];
component.checkedModules = modules; component.checkedModules = modules;
const evt = { target: { checked: false, value: 173 } }; const evt = { target: { checked: false, value: '173' } };
component.onCheckboxChange(evt, 'training'); component.onCheckboxChange(evt, 'training');
expect(component.checkedModules.length).toEqual(2); expect(component.checkedModules.length).toEqual(2);
}); });
it('should remove all modules checked from same modal, here morefilters', () => { it('should remove all modules checked from same modal, here morefilters', () => {
const modules: Module[] = [ const modules: Module[] = [
{ id: 176, text: 'morefilters', count: 0 }, { id: '176', text: 'morefilters', count: 0 },
{ id: 173, text: 'morefilters', count: 0 }, { id: '173', text: 'morefilters', count: 0 },
{ id: 172, text: 'morefilters', count: 0 }, { id: '172', text: 'morefilters', count: 0 },
{ id: 179, text: 'training', count: 0 }, { id: '179', text: 'training', count: 0 },
{ id: 190, text: 'training', count: 0 }, { id: '190', text: 'training', count: 0 },
{ id: 167, text: 'training', count: 0 }, { id: '167', text: 'training', count: 0 },
]; ];
component.checkedModules = modules; component.checkedModules = modules;
const category: Category = { name: 'morefilters', modules: [modules[0], modules[1], modules[2]] }; const category: Category = { name: 'morefilters', modules: [modules[0], modules[1], modules[2]] };
......
...@@ -18,6 +18,7 @@ export class ModalFilterComponent implements OnInit { ...@@ -18,6 +18,7 @@ export class ModalFilterComponent implements OnInit {
@Input() public categories: Category[]; @Input() public categories: Category[];
@Input() public modules: Module[] = []; @Input() public modules: Module[] = [];
@Output() searchEvent = new EventEmitter(); @Output() searchEvent = new EventEmitter();
@Output() closeEvent = new EventEmitter();
// Checkbox variable // Checkbox variable
checkedModules: Module[]; checkedModules: Module[];
// Form search input // Form search input
...@@ -62,4 +63,8 @@ export class ModalFilterComponent implements OnInit { ...@@ -62,4 +63,8 @@ export class ModalFilterComponent implements OnInit {
public emitModules(m: Module[]): void { public emitModules(m: Module[]): void {
this.searchEvent.emit(m); this.searchEvent.emit(m);
} }
public closeModal(): void {
this.closeEvent.emit();
}
} }
...@@ -28,7 +28,6 @@ ...@@ -28,7 +28,6 @@
<div class="btnSection" fxLayout="row" fxLayoutAlign="space-between center"> <div class="btnSection" fxLayout="row" fxLayoutAlign="space-between center">
<button <button
type="button" type="button"
[disabled]="modalTypeOpened === TypeModal[0]"
[ngClass]="{ selected: modalTypeOpened === TypeModal[0], containCheckedFilters: numberAccompanimentChecked }" [ngClass]="{ selected: modalTypeOpened === TypeModal[0], containCheckedFilters: numberAccompanimentChecked }"
(click)="openModal(TypeModal[0])" (click)="openModal(TypeModal[0])"
fxLayout="row" fxLayout="row"
...@@ -39,7 +38,6 @@ ...@@ -39,7 +38,6 @@
</button> </button>
<button <button
type="button" type="button"
[disabled]="modalTypeOpened === TypeModal[1]"
[ngClass]="{ selected: modalTypeOpened === TypeModal[1], containCheckedFilters: numberTrainingChecked }" [ngClass]="{ selected: modalTypeOpened === TypeModal[1], containCheckedFilters: numberTrainingChecked }"
(click)="openModal(TypeModal[1])" (click)="openModal(TypeModal[1])"
fxLayout="row" fxLayout="row"
...@@ -50,7 +48,6 @@ ...@@ -50,7 +48,6 @@
</button> </button>
<button <button
type="button" type="button"
[disabled]="modalTypeOpened === TypeModal[2]"
[ngClass]="{ selected: modalTypeOpened === TypeModal[2], containCheckedFilters: numberMoreFiltersChecked }" [ngClass]="{ selected: modalTypeOpened === TypeModal[2], containCheckedFilters: numberMoreFiltersChecked }"
(click)="openModal(TypeModal[2])" (click)="openModal(TypeModal[2])"
fxLayout="row" fxLayout="row"
...@@ -66,6 +63,7 @@ ...@@ -66,6 +63,7 @@
[categories]="categories" [categories]="categories"
[modules]="checkedModulesFilter" [modules]="checkedModulesFilter"
(searchEvent)="fetchResults($event)" (searchEvent)="fetchResults($event)"
(closeEvent)="closeModal()"
></app-modal-filter> ></app-modal-filter>
</div> </div>
</div> </div>
......
import { ComponentFixture, TestBed } from '@angular/core/testing'; import { ComponentFixture, TestBed } from '@angular/core/testing';
import { ReactiveFormsModule } from '@angular/forms'; import { ReactiveFormsModule } from '@angular/forms';
import { Category } from '../../models/category.model';
import { Filter } from '../../models/filter.model'; import { Filter } from '../../models/filter.model';
import { Module } from '../../models/module.model';
import { HttpClientTestingModule } from '@angular/common/http/testing'; import { HttpClientTestingModule } from '@angular/common/http/testing';
import { SearchComponent } from './search.component'; import { SearchComponent } from './search.component';
import { TypeModal } from '../../enum/typeModal.enum';
describe('SearchComponent', () => { describe('SearchComponent', () => {
let component: SearchComponent; let component: SearchComponent;
...@@ -35,14 +32,4 @@ describe('SearchComponent', () => { ...@@ -35,14 +32,4 @@ describe('SearchComponent', () => {
expect(component.searchEvent.emit).toHaveBeenCalled(); expect(component.searchEvent.emit).toHaveBeenCalled();
expect(component.searchEvent.emit).toHaveBeenCalledWith(filter); 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);
});
}); });
...@@ -21,13 +21,13 @@ describe('SearchService', () => { ...@@ -21,13 +21,13 @@ describe('SearchService', () => {
it('should return category with number of modules inside', () => { it('should return category with number of modules inside', () => {
const structureCount: StructureCounter[] = [ const structureCount: StructureCounter[] = [
{ id: 176, count: 2 }, { id: '176', count: 2 },
{ id: 172, count: 1 }, { id: '172', count: 1 },
{ id: 173, count: 1 }, { id: '173', count: 1 },
]; ];
const m1: Module = { id: 176, text: 'strm1', count: 0 }; const m1: Module = { id: '176', text: 'strm1', count: 0 };
const m2: Module = { id: 173, text: 'strm2', count: 0 }; const m2: Module = { id: '173', text: 'strm2', count: 0 };
const m3: Module = { id: 172, text: 'strm3', count: 0 }; const m3: Module = { id: '172', text: 'strm3', count: 0 };
const category: Category = { name: 'strCateg', modules: [m1, m2, m3] }; const category: Category = { name: 'strCateg', modules: [m1, m2, m3] };
const result = service.setCountModules(category, structureCount); const result = service.setCountModules(category, structureCount);
expect(result.modules[0].count).toBe(2); expect(result.modules[0].count).toBe(2);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment