Skip to content

Commit e7587e1

Browse files
authored
test: qbo skipped export log component (#995)
* test: QBO complete export log * lint fix * test: qbo skipped export log component * rem failing assertions * updated tests and fixtures * fixed breaking tests * lint fixes * pr comments * merge conflicts * lint fixes * lint fixes
1 parent af542bf commit e7587e1

File tree

2 files changed

+203
-7
lines changed

2 files changed

+203
-7
lines changed
Lines changed: 116 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,132 @@
1-
import { ComponentFixture, TestBed } from '@angular/core/testing';
2-
1+
/* eslint-disable max-lines */
2+
/* eslint-disable dot-notation */
3+
import { ComponentFixture, TestBed, fakeAsync, flush, tick } from '@angular/core/testing';
4+
import { FormBuilder, ReactiveFormsModule } from '@angular/forms';
5+
import { of } from 'rxjs';
36
import { QboSkippedExportLogComponent } from './qbo-skipped-export-log.component';
7+
import { UserService } from 'src/app/core/services/misc/user.service';
8+
import { ExportLogService } from 'src/app/core/services/common/export-log.service';
9+
import { AccountingExportService } from 'src/app/core/services/common/accounting-export.service';
10+
import { WindowService } from 'src/app/core/services/common/window.service';
11+
import { PaginatorService } from 'src/app/core/services/common/paginator.service';
12+
import { mockSkippedExpenseGroup, mockSkippedExpenseGroupWithDateRange, mockPaginator, mockUserProfile } from 'src/app/integrations/qbo/qbo.fixture';
13+
import { PaginatorPage } from 'src/app/core/models/enum/enum.model';
414

5-
xdescribe('QboSkippedExportLogComponent', () => {
15+
describe('QboSkippedExportLogComponent', () => {
616
let component: QboSkippedExportLogComponent;
717
let fixture: ComponentFixture<QboSkippedExportLogComponent>;
18+
let exportLogService: jasmine.SpyObj<ExportLogService>;
19+
let userService: jasmine.SpyObj<UserService>;
20+
let paginatorService: jasmine.SpyObj<PaginatorService>;
821

922
beforeEach(async () => {
23+
const exportLogServiceSpy = jasmine.createSpyObj('ExportLogService', ['getSkippedExpenses']);
24+
const userServiceSpy = jasmine.createSpyObj('UserService', ['getUserProfile']);
25+
const paginatorServiceSpy = jasmine.createSpyObj('PaginatorService', ['getPageSize', 'storePageSize']);
26+
1027
await TestBed.configureTestingModule({
11-
declarations: [ QboSkippedExportLogComponent ]
12-
})
13-
.compileComponents();
28+
declarations: [ QboSkippedExportLogComponent ],
29+
imports: [ ReactiveFormsModule ],
30+
providers: [
31+
FormBuilder,
32+
{ provide: ExportLogService, useValue: exportLogServiceSpy },
33+
{ provide: UserService, useValue: userServiceSpy },
34+
{ provide: AccountingExportService, useValue: {} },
35+
{ provide: WindowService, useValue: {} },
36+
{ provide: PaginatorService, useValue: paginatorServiceSpy }
37+
]
38+
}).compileComponents();
39+
40+
exportLogService = TestBed.inject(ExportLogService) as jasmine.SpyObj<ExportLogService>;
41+
userService = TestBed.inject(UserService) as jasmine.SpyObj<UserService>;
42+
paginatorService = TestBed.inject(PaginatorService) as jasmine.SpyObj<PaginatorService>;
43+
});
1444

45+
beforeEach(() => {
1546
fixture = TestBed.createComponent(QboSkippedExportLogComponent);
1647
component = fixture.componentInstance;
48+
userService.getUserProfile.and.returnValue(mockUserProfile);
49+
paginatorService.getPageSize.and.returnValue(mockPaginator);
50+
exportLogService.getSkippedExpenses.and.returnValue(of(mockSkippedExpenseGroup));
1751
fixture.detectChanges();
1852
});
1953

2054
it('should create', () => {
2155
expect(component).toBeTruthy();
2256
});
23-
});
57+
58+
it('should initialize with correct data', () => {
59+
expect(component.isLoading).toBeFalse();
60+
expect(component.totalCount).toBe(mockSkippedExpenseGroup.count);
61+
expect(component.expenses.length).toBe(mockSkippedExpenseGroup.results.length);
62+
expect(component.limit).toBe(mockPaginator.limit);
63+
expect(component.offset).toBe(mockPaginator.offset);
64+
});
65+
66+
it('should handle simple search', fakeAsync(() => {
67+
const searchQuery = 'anish';
68+
component.handleSimpleSearch(searchQuery);
69+
tick(1000);
70+
expect(component.searchQuery).toBe(searchQuery);
71+
expect(component.offset).toBe(0);
72+
expect(component.currentPage).toBe(1);
73+
}));
74+
75+
it('should handle page size changes', () => {
76+
const newLimit = 100;
77+
component.pageSizeChanges(newLimit);
78+
expect(component.isLoading).toBeFalse();
79+
expect(component.currentPage).toBe(1);
80+
expect(component.limit).toBe(newLimit);
81+
expect(paginatorService.storePageSize).toHaveBeenCalledWith(PaginatorPage.EXPORT_LOG, newLimit);
82+
});
83+
84+
it('should handle page changes', () => {
85+
const newOffset = 50;
86+
component.limit = 50;
87+
component.pageChanges(newOffset);
88+
expect(component.isLoading).toBeFalse();
89+
expect(component.offset).toBe(newOffset);
90+
expect(component.currentPage).toBe(2);
91+
});
92+
93+
it('should handle date range selection and hide/show calendar', fakeAsync(() => {
94+
const startDate = new Date('2023-06-15');
95+
const endDate = new Date('2023-06-16');
96+
97+
component.skipExportLogForm.controls.start.setValue([startDate, endDate]);
98+
tick();
99+
100+
expect(component.isDateSelected).toBeTrue();
101+
expect(component.selectedDateFilter).toEqual({ startDate, endDate });
102+
expect(component.hideCalendar).toBeTrue();
103+
104+
tick(10);
105+
106+
expect(component.hideCalendar).toBeFalse();
107+
}));
108+
109+
it('should handle date range reset', fakeAsync(() => {
110+
component.skipExportLogForm.controls.start.setValue(null);
111+
tick();
112+
expect(component.isDateSelected).toBeFalse();
113+
expect(component.selectedDateFilter).toBeNull();
114+
}));
115+
116+
it('should filter expenses based on date range', fakeAsync(() => {
117+
const startDate = new Date('2023-06-15');
118+
const endDate = new Date('2023-06-16');
119+
exportLogService.getSkippedExpenses.and.returnValue(of(mockSkippedExpenseGroupWithDateRange));
120+
121+
component.skipExportLogForm.controls.start.setValue([startDate, endDate]);
122+
123+
tick();
124+
tick(10);
125+
126+
expect(component.filteredExpenses.length).toBe(mockSkippedExpenseGroupWithDateRange.results.length);
127+
expect(component.totalCount).toBe(mockSkippedExpenseGroupWithDateRange.count);
128+
expect(component.hideCalendar).toBeFalse();
129+
130+
flush();
131+
}));
132+
});

src/app/integrations/qbo/qbo.fixture.ts

Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ import { AccountingExportSummary } from "src/app/core/models/db/accounting-expor
1111
import { Error } from "src/app/core/models/db/error.model";
1212
import { AccountingExport } from "src/app/core/models/db/accounting-export.model";
1313
import { ExpenseGroupResponse } from "src/app/core/models/db/expense-group.model";
14+
import { SkipExportLogResponse } from "src/app/core/models/intacct/db/expense-group.model";
15+
import { Paginator } from "src/app/core/models/misc/paginator.model";
1416

1517
export const mockUser: MinimalUser = {
1618
org_id: '123',
@@ -2154,4 +2156,89 @@ export const mockExpenseGroupResponse: ExpenseGroupResponse = {
21542156
]
21552157
};
21562158

2159+
export const mockSkippedExpenseGroup: SkipExportLogResponse = {
2160+
count: 4,
2161+
next: "http://quickbooks-api.staging-integrations:8000/api/workspaces/454/fyle/expenses/?is_skipped=true&limit=50&offset=50&org_id=or79Cob97KSh",
2162+
previous: null,
2163+
results: [
2164+
{
2165+
updated_at: new Date("2024-02-23T05:30:21.570820Z"),
2166+
claim_number: "C/2022/04/R/9",
2167+
employee_email: "[email protected]",
2168+
employee_name: "Ashwin",
2169+
fund_source: "CCC",
2170+
expense_id: "txuPPcLBZhYW",
2171+
org_id: "or79Cob97KSh"
2172+
},
2173+
{
2174+
updated_at: new Date("2024-02-23T05:30:21.564674Z"),
2175+
claim_number: "C/2021/04/R/46",
2176+
employee_email: "[email protected]",
2177+
employee_name: "Victor Martinez",
2178+
fund_source: "CCC",
2179+
expense_id: "txT4JbfgtooE",
2180+
org_id: "or79Cob97KSh"
2181+
},
2182+
{
2183+
updated_at: new Date("2024-02-23T05:30:21.248800Z"),
2184+
claim_number: "C/2022/04/R/30",
2185+
employee_email: "[email protected]",
2186+
employee_name: "Ashwin",
2187+
fund_source: "CCC",
2188+
expense_id: "txYQYWA1c6bU",
2189+
org_id: "or79Cob97KSh"
2190+
},
2191+
{
2192+
updated_at: new Date("2024-02-23T05:30:21.240046Z"),
2193+
claim_number: "C/2022/08/R/22",
2194+
employee_email: "[email protected]",
2195+
employee_name: "Ashwin",
2196+
fund_source: "CCC",
2197+
expense_id: "txyBQM9yIC9J",
2198+
org_id: "or79Cob97KSh"
2199+
}
2200+
]
2201+
};
2202+
2203+
export const mockSkippedExpenseGroupWithDateRange: SkipExportLogResponse = {
2204+
count: 2,
2205+
next: null,
2206+
previous: null,
2207+
results: [
2208+
{
2209+
updated_at: new Date("2023-06-15T10:30:00.000Z"),
2210+
claim_number: "C/2023/06/R/1",
2211+
employee_email: "[email protected]",
2212+
employee_name: "John Doe",
2213+
fund_source: "PERSONAL",
2214+
expense_id: "txABC123",
2215+
org_id: "or79Cob97KSh"
2216+
},
2217+
{
2218+
updated_at: new Date("2023-06-16T14:45:00.000Z"),
2219+
claim_number: "C/2023/06/R/2",
2220+
employee_email: "[email protected]",
2221+
employee_name: "Jane Smith",
2222+
fund_source: "CCC",
2223+
expense_id: "txDEF456",
2224+
org_id: "or79Cob97KSh"
2225+
}
2226+
]
2227+
};
2228+
2229+
export const mockPaginator: Paginator = {
2230+
limit: 50,
2231+
offset: 0
2232+
};
2233+
2234+
export const mockUserProfile = {
2235+
org_id: 'or79Cob97KSh',
2236+
2237+
access_token: 'dummy_access_token',
2238+
refresh_token: 'dummy_refresh_token',
2239+
full_name: 'Test User',
2240+
user_id: 'user123',
2241+
org_name: 'Test Org'
2242+
};
2243+
21572244
export const mockPageSize = { limit: 10, offset: 0 };

0 commit comments

Comments
 (0)