diff --git a/src/test/javascript/spec/util/shared/request.util.spec.ts b/src/test/javascript/spec/util/shared/request.util.spec.ts new file mode 100644 index 000000000000..e75188913a87 --- /dev/null +++ b/src/test/javascript/spec/util/shared/request.util.spec.ts @@ -0,0 +1,35 @@ +import { createNestedRequestOption } from 'app/shared/util/request.util'; +import { HttpParams } from '@angular/common/http'; + +describe('createNestedRequestOption', () => { + it('should create HttpParams with nested keys', () => { + const req = { key1: 'value1', key2: 'value2' }; + const parentKey = 'parent'; + const params: HttpParams = createNestedRequestOption(req, parentKey); + + expect(params.get('parent.key1')).toBe('value1'); + expect(params.get('parent.key2')).toBe('value2'); + }); + + it('should create HttpParams without parent key', () => { + const req = { key1: 'value1', key2: 'value2' }; + const params: HttpParams = createNestedRequestOption(req); + + expect(params.get('key1')).toBe('value1'); + expect(params.get('key2')).toBe('value2'); + }); + + it('should append sort parameters', () => { + const req = { sort: ['value1', 'value2'] }; + const parentKey = 'parent'; + const params: HttpParams = createNestedRequestOption(req, parentKey); + + expect(params.getAll('parent.sort')).toEqual(['value1', 'value2']); + }); + + it('should handle empty request object', () => { + const params: HttpParams = createNestedRequestOption(); + + expect(params.keys()).toHaveLength(0); + }); +}); diff --git a/src/test/javascript/spec/util/shared/utils.spec.ts b/src/test/javascript/spec/util/shared/utils.spec.ts index e1c484866eca..f0be1a533866 100644 --- a/src/test/javascript/spec/util/shared/utils.spec.ts +++ b/src/test/javascript/spec/util/shared/utils.spec.ts @@ -11,6 +11,7 @@ import { } from 'app/shared/util/utils'; import { Exercise } from 'app/entities/exercise.model'; import { Course } from 'app/entities/course.model'; +import { Range } from 'app/shared/util/utils'; describe('Round', () => { it('Decimal length', () => { @@ -91,6 +92,16 @@ describe('average', () => { }); }); +describe('Range', () => { + it('should return the correct string representation', () => { + const range = new Range(10, 50); + expect(range.toString()).toBe('[10%, 50%)'); + + const rangeInclusive = new Range(0, 100); + expect(rangeInclusive.toString()).toBe('[0%, 100%]'); + }); +}); + describe('getAsMutableObject', () => { it('should return immutable object as mutable object', () => { const immutableObject = Object.freeze({