Commit 54518e68 authored by Vitali Stupin's avatar Vitali Stupin

Getting filter limits from configuration

parent 9b8fd8e6
......@@ -6,6 +6,11 @@ export class AppConfigMock extends AppConfig {
private configMock: any = {
MAX_LIMIT: 1000000,
DEFAULT_LIMIT: 10,
LIMITS: {
10: 10,
20: 20,
50: 50
},
INSTANCES: {
EE: 'https://www.x-tee.ee/catalogue/EE/wsdls/',
'ee-test': 'https://www.x-tee.ee/catalogue/ee-test/wsdls/',
......@@ -17,7 +22,8 @@ export class AppConfigMock extends AppConfig {
ENG: 'eng'
},
PREVIEW_SIZE: 5,
FILTER_DEBOUNCE: 200
// Smaller value for faster unit testing
FILTER_DEBOUNCE: 20
};
public getConfig(key: any) {
......
......@@ -16,9 +16,7 @@
<label for="limitSelect">{{'search.limit' | translate}}</label>
<select class="form-control" id="limitSelect"
[(ngModel)]="limit" (change)="setLimit(limit)">
<option value="10">10</option>
<option value="20">20</option>
<option value="50">50</option>
<option *ngFor="let key of getLimitKeys()" [ngValue]="key">{{limits[key]}}</option>
<option value="all">{{'search.allOption' | translate}}</option>
</select>
</div>
......@@ -32,4 +30,4 @@
</div>
</div>
</div>
</div>
\ No newline at end of file
</div>
......@@ -29,6 +29,7 @@ describe('SearchComponent', () => {
beforeEach(() => {
subsystemsService = TestBed.get(SubsystemsService);
spyOn(subsystemsService, 'getLimits').and.returnValue({10: 10, 20: 20});
spyOn(subsystemsService, 'setNonEmpty').and.returnValue(null);
spyOn(subsystemsService, 'setLimit').and.returnValue(null);
spyOn(subsystemsService, 'setFilter').and.returnValue(null);
......@@ -41,6 +42,11 @@ describe('SearchComponent', () => {
expect(component).toBeTruthy();
});
it('getLimitKeys should work', () => {
expect(component.getLimitKeys()).toEqual(['10', '20']);
expect(subsystemsService.getLimits).toHaveBeenCalledWith();
});
it('setNonEmpty should work', () => {
component.setNonEmpty(true);
expect(subsystemsService.setNonEmpty).toHaveBeenCalledWith(true);
......
......@@ -7,10 +7,18 @@ import { SubsystemsService } from '../../subsystems.service';
})
export class SearchComponent implements OnInit {
limit: string;
limits: object;
nonEmpty: boolean;
filter: string;
constructor(private subsystemsService: SubsystemsService) {}
constructor(private subsystemsService: SubsystemsService) {
this.limit = this.subsystemsService.getLimit();
this.limits = this.subsystemsService.getLimits();
}
getLimitKeys(): string[] {
return Object.keys(this.limits);
}
setNonEmpty(nonEmpty: boolean) {
this.subsystemsService.setNonEmpty(nonEmpty);
......
......@@ -267,6 +267,10 @@ describe('SubsystemsService', () => {
service.setLimit('10');
expect(service.filteredSubsystemsSubject.value.length).toEqual(10);
// Should set default limit of 10
service.setLimit('5');
expect(service.filteredSubsystemsSubject.value.length).toEqual(10);
});
it('getLimit should work', () => {
......@@ -276,6 +280,10 @@ describe('SubsystemsService', () => {
expect(service.getLimit()).toEqual('all');
});
it('getLimits should work', () => {
expect(service.getLimits()).toEqual(config.getConfig('LIMITS'));
});
it('getInstances should work', () => {
expect(service.getInstances()).toEqual(Object.keys(config.getConfig('INSTANCES')));
});
......
......@@ -157,19 +157,26 @@ export class SubsystemsService {
return this.limit.toString();
}
getLimits(): object {
return this.config.getConfig('LIMITS');
}
setLimit(limit: string) {
switch (limit) {
case '20':
this.limit = 20;
break;
case '50':
this.limit = 50;
break;
case 'all':
this.limit = this.config.getConfig('MAX_LIMIT');
const limits = this.config.getConfig('LIMITS');
let found = false;
for (const key of Object.keys(limits)) {
if (limit === key) {
this.limit = limits[key];
found = true;
break;
default:
this.limit = 10;
}
}
if (!found && limit === 'all') {
this.limit = this.config.getConfig('MAX_LIMIT');
found = true;
}
if (!found) {
this.limit = this.config.getConfig('DEFAULT_LIMIT');
}
this.updateFiltered();
}
......
{
"MAX_LIMIT": 1000000,
"DEFAULT_LIMIT": 10,
"LIMITS": {
"10": 10,
"20": 20,
"50": 50
},
"INSTANCES": {
"EE": "https://www.x-tee.ee/catalogue/EE/wsdls/",
"ee-test": "https://www.x-tee.ee/catalogue/ee-test/wsdls/",
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment