fix(deploy): new test
This commit is contained in:
@@ -0,0 +1,108 @@
|
||||
import { of } from 'rxjs';
|
||||
import { ActivatedRoute, Router } from '@angular/router';
|
||||
import { CalculatorPageComponent } from './calculator-page.component';
|
||||
import {
|
||||
QuoteEstimatorService,
|
||||
QuoteResult,
|
||||
} from './services/quote-estimator.service';
|
||||
import { LanguageService } from '../../core/services/language.service';
|
||||
import { UploadFormComponent } from './components/upload-form/upload-form.component';
|
||||
|
||||
describe('CalculatorPageComponent', () => {
|
||||
const createResult = (sessionId: string, notes?: string): QuoteResult => ({
|
||||
sessionId,
|
||||
items: [
|
||||
{
|
||||
id: 'line-1',
|
||||
fileName: 'part-a.stl',
|
||||
unitPrice: 4,
|
||||
unitTime: 120,
|
||||
unitWeight: 2,
|
||||
quantity: 1,
|
||||
},
|
||||
],
|
||||
setupCost: 2,
|
||||
globalMachineCost: 0,
|
||||
currency: 'CHF',
|
||||
totalPrice: 6,
|
||||
totalTimeHours: 0,
|
||||
totalTimeMinutes: 2,
|
||||
totalWeight: 2,
|
||||
notes,
|
||||
});
|
||||
|
||||
function createComponent() {
|
||||
const estimator = jasmine.createSpyObj<QuoteEstimatorService>(
|
||||
'QuoteEstimatorService',
|
||||
['updateLineItem', 'getQuoteSession', 'mapSessionToQuoteResult'],
|
||||
);
|
||||
const router = jasmine.createSpyObj<Router>('Router', ['navigate']);
|
||||
const route = {
|
||||
data: of({}),
|
||||
queryParams: of({}),
|
||||
} as unknown as ActivatedRoute;
|
||||
const languageService = jasmine.createSpyObj<LanguageService>(
|
||||
'LanguageService',
|
||||
['selectedLang'],
|
||||
);
|
||||
|
||||
const component = new CalculatorPageComponent(
|
||||
estimator,
|
||||
router,
|
||||
route,
|
||||
languageService,
|
||||
);
|
||||
|
||||
const uploadForm = jasmine.createSpyObj<UploadFormComponent>(
|
||||
'UploadFormComponent',
|
||||
['updateItemQuantityByIndex', 'updateItemQuantityByName'],
|
||||
);
|
||||
component.uploadForm = uploadForm;
|
||||
|
||||
return {
|
||||
component,
|
||||
estimator,
|
||||
uploadForm,
|
||||
};
|
||||
}
|
||||
|
||||
it('updates left panel quantities even when item id is missing', () => {
|
||||
const { component, estimator, uploadForm } = createComponent();
|
||||
|
||||
component.onItemChange({
|
||||
index: 0,
|
||||
fileName: 'part-a.stl',
|
||||
quantity: 4,
|
||||
});
|
||||
|
||||
expect(uploadForm.updateItemQuantityByIndex).toHaveBeenCalledWith(0, 4);
|
||||
expect(uploadForm.updateItemQuantityByName).toHaveBeenCalledWith(
|
||||
'part-a.stl',
|
||||
4,
|
||||
);
|
||||
expect(estimator.updateLineItem).not.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it('refreshes quote totals after successful line item update', () => {
|
||||
const { component, estimator } = createComponent();
|
||||
component.result.set(createResult('session-1', 'persisted notes'));
|
||||
|
||||
estimator.updateLineItem.and.returnValue(of({ ok: true }));
|
||||
estimator.getQuoteSession.and.returnValue(of({ session: { id: 'session-1' } }));
|
||||
estimator.mapSessionToQuoteResult.and.returnValue(createResult('session-1'));
|
||||
|
||||
component.onItemChange({
|
||||
id: 'line-1',
|
||||
index: 0,
|
||||
fileName: 'part-a.stl',
|
||||
quantity: 7,
|
||||
});
|
||||
|
||||
expect(estimator.updateLineItem).toHaveBeenCalledWith('line-1', {
|
||||
quantity: 7,
|
||||
});
|
||||
expect(estimator.getQuoteSession).toHaveBeenCalledWith('session-1');
|
||||
expect(component.result()?.notes).toBe('persisted notes');
|
||||
expect(component.result()?.items[0].quantity).toBe(1);
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,79 @@
|
||||
import { ComponentFixture, TestBed } from '@angular/core/testing';
|
||||
import { TranslateModule } from '@ngx-translate/core';
|
||||
import { QuoteResultComponent } from './quote-result.component';
|
||||
import { QuoteResult } from '../../services/quote-estimator.service';
|
||||
|
||||
describe('QuoteResultComponent', () => {
|
||||
let fixture: ComponentFixture<QuoteResultComponent>;
|
||||
let component: QuoteResultComponent;
|
||||
|
||||
const createResult = (): QuoteResult => ({
|
||||
sessionId: 'session-1',
|
||||
items: [
|
||||
{
|
||||
id: 'line-1',
|
||||
fileName: 'part-a.stl',
|
||||
unitPrice: 2,
|
||||
unitTime: 120,
|
||||
unitWeight: 1.2,
|
||||
quantity: 2,
|
||||
},
|
||||
{
|
||||
id: 'line-2',
|
||||
fileName: 'part-b.stl',
|
||||
unitPrice: 1.5,
|
||||
unitTime: 60,
|
||||
unitWeight: 0.5,
|
||||
quantity: 1,
|
||||
},
|
||||
],
|
||||
setupCost: 5,
|
||||
globalMachineCost: 0,
|
||||
currency: 'CHF',
|
||||
totalPrice: 0,
|
||||
totalTimeHours: 0,
|
||||
totalTimeMinutes: 0,
|
||||
totalWeight: 0,
|
||||
});
|
||||
|
||||
beforeEach(async () => {
|
||||
await TestBed.configureTestingModule({
|
||||
imports: [QuoteResultComponent, TranslateModule.forRoot()],
|
||||
}).compileComponents();
|
||||
|
||||
fixture = TestBed.createComponent(QuoteResultComponent);
|
||||
component = fixture.componentInstance;
|
||||
fixture.componentRef.setInput('result', createResult());
|
||||
fixture.detectChanges();
|
||||
});
|
||||
|
||||
it('emits quantity changes with clamped max quantity', () => {
|
||||
spyOn(component.itemChange, 'emit');
|
||||
|
||||
component.updateQuantity(0, 999);
|
||||
component.flushQuantityUpdate(0);
|
||||
|
||||
expect(component.items()[0].quantity).toBe(component.maxInputQuantity);
|
||||
expect(component.itemChange.emit).toHaveBeenCalledWith({
|
||||
id: 'line-1',
|
||||
index: 0,
|
||||
fileName: 'part-a.stl',
|
||||
quantity: component.maxInputQuantity,
|
||||
});
|
||||
});
|
||||
|
||||
it('computes totals from local item quantities', () => {
|
||||
component.updateQuantity(1, 3);
|
||||
|
||||
const totals = component.totals();
|
||||
expect(totals.price).toBe(13.5);
|
||||
expect(totals.hours).toBe(0);
|
||||
expect(totals.minutes).toBe(7);
|
||||
expect(totals.weight).toBe(4);
|
||||
});
|
||||
|
||||
it('flags over-limit quantities for direct order', () => {
|
||||
component.updateQuantity(0, 101);
|
||||
expect(component.hasQuantityOverLimit()).toBeTrue();
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user