Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ describe('OfficeFormComponent', () => {
const OFFICES_PATH = '/organization/offices';
const NEW_OFFICE = 'New Office';
const TEST_OFFICE = 'Test Office';
const TEST_OPENING_DATE = '2026-06-16';

beforeEach(async () => {
officesServiceSpy = jasmine.createSpyObj('OfficesService', [
Expand Down Expand Up @@ -197,16 +198,17 @@ describe('OfficeFormComponent', () => {
expect(component.officeId).toBe(12);
expect(officesServiceSpy.getOfficesOfficeId).toHaveBeenCalledWith(12);
expect(component.office().name).toBe(TEST_OFFICE);
expect(component.openingDate()).toBe(TEST_OPENING_DATE);

officesServiceSpy.putOfficesOfficeId.and.returnValue(of({}) as unknown as Observable<never>);
component.openingDate.set('2026-06-16');
component.openingDate.set(TEST_OPENING_DATE);
component.onSubmit();

expect(officesServiceSpy.putOfficesOfficeId).toHaveBeenCalledWith(
12,
jasmine.objectContaining({
name: TEST_OFFICE,
openingDate: '2026-06-16',
openingDate: TEST_OPENING_DATE,
}),
);
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ import {
IonSelectOption,
IonSpinner,
} from '@ionic/angular/standalone';
import { toIsoDate } from '../../../core/utils/date-formatter';
import { formatArrayDate, toIsoDate } from '../../../core/utils/date-formatter';
import { TooltipDirective } from '../../../shared/directives/tooltip.directive';
import {
OfficesService,
Expand Down Expand Up @@ -217,9 +217,8 @@ export class OfficeFormComponent implements OnInit {
loadOfficeData() {
if (!this.officeId) return;
this.officesService.getOfficesOfficeId(this.officeId).subscribe((data) => {
const dateArray = data.openingDate as unknown as number[];
if (dateArray) {
this.openingDate.set(toIsoDate(new Date(dateArray[0], dateArray[1] - 1, dateArray[2])));
if (data.openingDate) {
this.openingDate.set(formatArrayDate(data.openingDate));
}
this.office.set({
name: data.name,
Expand Down
12 changes: 12 additions & 0 deletions src/app/features/organization/staff/staff-form.component.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,18 @@ describe('StaffFormComponent', () => {
expect(officesServiceSpy.getOffices).toHaveBeenCalled();
});

it('should format the joining date returned by the API', () => {
staffServiceSpy.getStaffStaffId.and.returnValue(
of({ joiningDate: [2026, 1, 5] }) as unknown as ReturnType<StaffService['getStaffStaffId']>,
);
component.staffId = 7;

component.loadStaffData();

expect(staffServiceSpy.getStaffStaffId).toHaveBeenCalledWith(7);
expect(component.joiningDate()).toBe('2026-01-05');
});

it('should create staff with a StaffCreateRequest payload on submit', () => {
staffServiceSpy.postStaff.and.returnValue(
of({}) as unknown as ReturnType<StaffService['postStaff']>,
Expand Down
4 changes: 2 additions & 2 deletions src/app/features/organization/staff/staff-form.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ import {
GetOfficesResponse,
} from '../../../api';
import {
formatArrayDate,
formatDateToFineract,
FINERACT_DATE_FORMAT,
FINERACT_LOCALE,
Expand Down Expand Up @@ -301,8 +302,7 @@ export class StaffFormComponent implements OnInit {
emailAddress: (data as Record<string, unknown>)['emailAddress'] as string | undefined,
});
if (data.joiningDate) {
const jd = data.joiningDate as unknown as number[];
this.joiningDate.set(toIsoDate(new Date(jd[0], jd[1] - 1, jd[2])));
this.joiningDate.set(formatArrayDate(data.joiningDate));
}
});
}
Expand Down
Loading