Files
Artemis-Eapil/apps/showcase_ui/src/app/components/setting-slider/setting-slider.component.spec.ts
T

18 lines
1.3 KiB
TypeScript

import { TestBed } from '@angular/core/testing';
import { SettingSliderComponent, REASONING_VALUES, REASONING_LABELS } from './setting-slider.component';
describe('Setting slider', () => {
it('maps the selected position to the exact request value and exposes its readable label', () => {
const f=TestBed.createComponent(SettingSliderComponent);
f.componentRef.setInput('label','思考强度');f.componentRef.setInput('values',REASONING_VALUES);f.componentRef.setInput('labels',REASONING_LABELS);f.componentRef.setInput('value','high');f.detectChanges();
const slider=f.nativeElement.querySelector('input');expect(slider.getAttribute('aria-valuetext')).toBe('高 · high');
const emit=spyOn(f.componentInstance.valueChange,'emit');slider.value='7';slider.dispatchEvent(new Event('input'));
expect(emit).toHaveBeenCalledWith('max');f.destroy();
});
it('preserves a saved custom time until the slider is actually changed', () => {
const f=TestBed.createComponent(SettingSliderComponent);const emit=spyOn(f.componentInstance.valueChange,'emit');
f.componentRef.setInput('label','执行时限');f.componentRef.setInput('values',[60,300,1800]);f.componentRef.setInput('value',125);f.detectChanges();
expect(f.nativeElement.querySelector('output').textContent).toBe('125 秒');expect(emit).not.toHaveBeenCalled();f.destroy();
});
});