mirror of
https://dev.azure.com/hugendubel/ISA/_git/ISA-Frontend
synced 2025-12-28 22:42:11 +01:00
committed by
Lorenz Hilpert
parent
596ae1da1b
commit
b5c8dc4776
@@ -9,7 +9,10 @@ describe('QuantityControlComponent', () => {
|
||||
let component: QuantityControlComponent;
|
||||
let fixture: ComponentFixture<QuantityControlComponent>;
|
||||
let liveAnnouncerMock: { announce: ReturnType<typeof vi.fn> };
|
||||
let tooltipMock: { show: ReturnType<typeof vi.fn>; hide: ReturnType<typeof vi.fn> };
|
||||
let tooltipMock: {
|
||||
show: ReturnType<typeof vi.fn>;
|
||||
hide: ReturnType<typeof vi.fn>;
|
||||
};
|
||||
|
||||
beforeEach(async () => {
|
||||
liveAnnouncerMock = {
|
||||
@@ -43,16 +46,16 @@ describe('QuantityControlComponent', () => {
|
||||
expect(component).toBeTruthy();
|
||||
});
|
||||
|
||||
it('should have default value of 1', () => {
|
||||
expect(component.value()).toBe(1);
|
||||
it('should have default value of 0', () => {
|
||||
expect(component.value()).toBe(0);
|
||||
});
|
||||
|
||||
it('should not be disabled by default', () => {
|
||||
expect(component.disabled()).toBe(false);
|
||||
});
|
||||
|
||||
it('should have default min of 1', () => {
|
||||
expect(component.min()).toBe(1);
|
||||
it('should have default min of 0', () => {
|
||||
expect(component.min()).toBe(0);
|
||||
});
|
||||
|
||||
it('should have default max of undefined', () => {
|
||||
@@ -68,9 +71,9 @@ describe('QuantityControlComponent', () => {
|
||||
it('should generate options from min to presetLimit with Edit', () => {
|
||||
const options = component.generatedOptions();
|
||||
|
||||
expect(options).toHaveLength(11); // 1-10 + Edit
|
||||
expect(options[0]).toEqual({ value: 1, label: '1' });
|
||||
expect(options[9]).toEqual({ value: 10, label: '10' });
|
||||
expect(options).toHaveLength(11); // 0-9 + Edit
|
||||
expect(options[0]).toEqual({ value: 0, label: '0' });
|
||||
expect(options[9]).toEqual({ value: 9, label: '9' });
|
||||
expect(options[10]).toEqual({ value: 'edit', label: 'Edit' });
|
||||
});
|
||||
|
||||
@@ -85,6 +88,7 @@ describe('QuantityControlComponent', () => {
|
||||
});
|
||||
|
||||
it('should not show Edit option when max is less than or equal to presetLimit', () => {
|
||||
fixture.componentRef.setInput('min', 1);
|
||||
fixture.componentRef.setInput('max', 5);
|
||||
fixture.componentRef.setInput('presetLimit', 10);
|
||||
fixture.detectChanges();
|
||||
@@ -105,7 +109,10 @@ describe('QuantityControlComponent', () => {
|
||||
const options = component.generatedOptions();
|
||||
|
||||
expect(options).toHaveLength(11); // 1-10 + Edit
|
||||
expect(options[options.length - 1]).toEqual({ value: 'edit', label: 'Edit' });
|
||||
expect(options[options.length - 1]).toEqual({
|
||||
value: 'edit',
|
||||
label: 'Edit',
|
||||
});
|
||||
});
|
||||
|
||||
it('should generate correct range with custom min and presetLimit', () => {
|
||||
@@ -159,7 +166,7 @@ describe('QuantityControlComponent', () => {
|
||||
|
||||
expect(liveAnnouncerMock.announce).toHaveBeenCalledWith(
|
||||
'Quantity changed to 8',
|
||||
'polite'
|
||||
'polite',
|
||||
);
|
||||
});
|
||||
});
|
||||
@@ -217,7 +224,7 @@ describe('QuantityControlComponent', () => {
|
||||
|
||||
expect(liveAnnouncerMock.announce).toHaveBeenCalledWith(
|
||||
'Edit mode activated. Type a quantity and press Enter to confirm or Escape to cancel.',
|
||||
'polite'
|
||||
'polite',
|
||||
);
|
||||
});
|
||||
|
||||
@@ -241,7 +248,7 @@ describe('QuantityControlComponent', () => {
|
||||
expect(component.value()).toBe(1); // Clamped to min
|
||||
expect(liveAnnouncerMock.announce).toHaveBeenCalledWith(
|
||||
'Adjusted to minimum 1',
|
||||
'polite'
|
||||
'polite',
|
||||
);
|
||||
});
|
||||
|
||||
@@ -256,7 +263,7 @@ describe('QuantityControlComponent', () => {
|
||||
expect(component.value()).toBe(50); // Clamped to max
|
||||
expect(liveAnnouncerMock.announce).toHaveBeenCalledWith(
|
||||
'Adjusted to maximum 50',
|
||||
'polite'
|
||||
'polite',
|
||||
);
|
||||
});
|
||||
|
||||
@@ -270,7 +277,7 @@ describe('QuantityControlComponent', () => {
|
||||
expect(component.value()).toBe(originalValue); // Value unchanged
|
||||
expect(liveAnnouncerMock.announce).toHaveBeenCalledWith(
|
||||
'Invalid input. Please enter a valid number.',
|
||||
'assertive'
|
||||
'assertive',
|
||||
);
|
||||
});
|
||||
|
||||
@@ -291,7 +298,7 @@ describe('QuantityControlComponent', () => {
|
||||
|
||||
expect(liveAnnouncerMock.announce).toHaveBeenCalledWith(
|
||||
'Edit mode cancelled',
|
||||
'polite'
|
||||
'polite',
|
||||
);
|
||||
});
|
||||
|
||||
|
||||
@@ -91,9 +91,9 @@ export class QuantityControlComponent implements ControlValueAccessor {
|
||||
|
||||
/**
|
||||
* Current quantity value
|
||||
* @default 1
|
||||
* @default 0
|
||||
*/
|
||||
value = model<number>(1);
|
||||
value = model<number>(0);
|
||||
|
||||
/**
|
||||
* Whether the control is disabled
|
||||
@@ -103,9 +103,9 @@ export class QuantityControlComponent implements ControlValueAccessor {
|
||||
|
||||
/**
|
||||
* Minimum selectable value (starting point for dropdown options).
|
||||
* @default 1
|
||||
* @default 0
|
||||
*/
|
||||
min = input<number, unknown>(1, {
|
||||
min = input<number, unknown>(0, {
|
||||
transform: coerceNumberProperty,
|
||||
});
|
||||
|
||||
|
||||
Reference in New Issue
Block a user