|
|
@ -5,7 +5,10 @@ import { MAT_DIALOG_DATA, MatDialogRef } from '@angular/material/dialog'; |
|
|
import { NoopAnimationsModule } from '@angular/platform-browser/animations'; |
|
|
import { NoopAnimationsModule } from '@angular/platform-browser/animations'; |
|
|
import { of } from 'rxjs'; |
|
|
import { of } from 'rxjs'; |
|
|
|
|
|
|
|
|
import { GfCreateOrUpdateBudgetDialogComponent } from './create-or-update-budget-dialog.component'; |
|
|
import { |
|
|
|
|
|
CreateOrUpdateBudgetDialogData, |
|
|
|
|
|
GfCreateOrUpdateBudgetDialogComponent |
|
|
|
|
|
} from './create-or-update-budget-dialog.component'; |
|
|
|
|
|
|
|
|
describe('GfCreateOrUpdateBudgetDialogComponent', () => { |
|
|
describe('GfCreateOrUpdateBudgetDialogComponent', () => { |
|
|
let component: GfCreateOrUpdateBudgetDialogComponent; |
|
|
let component: GfCreateOrUpdateBudgetDialogComponent; |
|
|
@ -17,7 +20,7 @@ describe('GfCreateOrUpdateBudgetDialogComponent', () => { |
|
|
>; |
|
|
>; |
|
|
let fixture: ComponentFixture<GfCreateOrUpdateBudgetDialogComponent>; |
|
|
let fixture: ComponentFixture<GfCreateOrUpdateBudgetDialogComponent>; |
|
|
|
|
|
|
|
|
beforeEach(async () => { |
|
|
const setup = async (dialogData: CreateOrUpdateBudgetDialogData) => { |
|
|
dataService = { |
|
|
dataService = { |
|
|
createBudget: jest.fn().mockReturnValue( |
|
|
createBudget: jest.fn().mockReturnValue( |
|
|
of({ |
|
|
of({ |
|
|
@ -57,10 +60,7 @@ describe('GfCreateOrUpdateBudgetDialogComponent', () => { |
|
|
}, |
|
|
}, |
|
|
{ |
|
|
{ |
|
|
provide: MAT_DIALOG_DATA, |
|
|
provide: MAT_DIALOG_DATA, |
|
|
useValue: { |
|
|
useValue: dialogData |
|
|
budget: undefined, |
|
|
|
|
|
month: '2026-06' |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
} |
|
|
] |
|
|
] |
|
|
}).compileComponents(); |
|
|
}).compileComponents(); |
|
|
@ -68,9 +68,15 @@ describe('GfCreateOrUpdateBudgetDialogComponent', () => { |
|
|
fixture = TestBed.createComponent(GfCreateOrUpdateBudgetDialogComponent); |
|
|
fixture = TestBed.createComponent(GfCreateOrUpdateBudgetDialogComponent); |
|
|
component = fixture.componentInstance; |
|
|
component = fixture.componentInstance; |
|
|
fixture.autoDetectChanges(); |
|
|
fixture.autoDetectChanges(); |
|
|
}); |
|
|
}; |
|
|
|
|
|
|
|
|
it('creates a budget and closes with refresh', async () => { |
|
|
it('creates a budget and closes with refresh', async () => { |
|
|
|
|
|
await setup({ |
|
|
|
|
|
budget: undefined, |
|
|
|
|
|
currency: 'USD', |
|
|
|
|
|
month: '2026-06' |
|
|
|
|
|
}); |
|
|
|
|
|
|
|
|
component.budgetForm.setValue({ |
|
|
component.budgetForm.setValue({ |
|
|
amount: 500, |
|
|
amount: 500, |
|
|
categoryId: 'food', |
|
|
categoryId: 'food', |
|
|
@ -83,8 +89,52 @@ describe('GfCreateOrUpdateBudgetDialogComponent', () => { |
|
|
expect(dataService.createBudget).toHaveBeenCalledWith({ |
|
|
expect(dataService.createBudget).toHaveBeenCalledWith({ |
|
|
amount: 500, |
|
|
amount: 500, |
|
|
categoryId: 'food', |
|
|
categoryId: 'food', |
|
|
|
|
|
currency: 'USD', |
|
|
|
|
|
month: '2026-06' |
|
|
|
|
|
}); |
|
|
|
|
|
expect(dialogRef.close).toHaveBeenCalledWith({ refresh: true }); |
|
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
it('updates a budget and closes with refresh', async () => { |
|
|
|
|
|
await setup({ |
|
|
|
|
|
budget: { |
|
|
|
|
|
amount: 500, |
|
|
|
|
|
category: { |
|
|
|
|
|
id: 'food', |
|
|
|
|
|
name: 'Food' |
|
|
|
|
|
}, |
|
|
|
|
|
categoryId: 'food', |
|
|
|
|
|
createdAt: new Date('2026-06-01'), |
|
|
|
|
|
currency: 'USD', |
|
|
|
|
|
id: 'budget-1', |
|
|
|
|
|
month: '2026-06', |
|
|
|
|
|
remaining: 500, |
|
|
|
|
|
spent: 0, |
|
|
|
|
|
updatedAt: new Date('2026-06-01') |
|
|
|
|
|
}, |
|
|
|
|
|
currency: 'USD', |
|
|
|
|
|
month: '2026-06' |
|
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
component.budgetForm.setValue({ |
|
|
|
|
|
amount: 650, |
|
|
|
|
|
categoryId: 'food', |
|
|
month: '2026-06' |
|
|
month: '2026-06' |
|
|
}); |
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
component.onSubmit(); |
|
|
|
|
|
await fixture.whenStable(); |
|
|
|
|
|
|
|
|
|
|
|
expect(dataService.updateBudget).toHaveBeenCalledWith({ |
|
|
|
|
|
budget: { |
|
|
|
|
|
amount: 650, |
|
|
|
|
|
categoryId: 'food', |
|
|
|
|
|
currency: 'USD', |
|
|
|
|
|
id: 'budget-1', |
|
|
|
|
|
month: '2026-06' |
|
|
|
|
|
}, |
|
|
|
|
|
id: 'budget-1' |
|
|
|
|
|
}); |
|
|
expect(dialogRef.close).toHaveBeenCalledWith({ refresh: true }); |
|
|
expect(dialogRef.close).toHaveBeenCalledWith({ refresh: true }); |
|
|
}); |
|
|
}); |
|
|
}); |
|
|
}); |
|
|
|