Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test: qbo skipped export log component #995

Merged
merged 13 commits into from
Oct 8, 2024
Original file line number Diff line number Diff line change
@@ -1,23 +1,132 @@
import { ComponentFixture, TestBed } from '@angular/core/testing';

/* eslint-disable max-lines */
/* eslint-disable dot-notation */
import { ComponentFixture, TestBed, fakeAsync, flush, tick } from '@angular/core/testing';
import { FormBuilder, ReactiveFormsModule } from '@angular/forms';
import { of } from 'rxjs';
import { QboSkippedExportLogComponent } from './qbo-skipped-export-log.component';
import { UserService } from 'src/app/core/services/misc/user.service';
import { ExportLogService } from 'src/app/core/services/common/export-log.service';
import { AccountingExportService } from 'src/app/core/services/common/accounting-export.service';
import { WindowService } from 'src/app/core/services/common/window.service';
import { PaginatorService } from 'src/app/core/services/common/paginator.service';
import { mockSkippedExpenseGroup, mockSkippedExpenseGroupWithDateRange, mockPaginator, mockUserProfile } from 'src/app/integrations/qbo/qbo.fixture';
import { PaginatorPage } from 'src/app/core/models/enum/enum.model';

xdescribe('QboSkippedExportLogComponent', () => {
describe('QboSkippedExportLogComponent', () => {
let component: QboSkippedExportLogComponent;
let fixture: ComponentFixture<QboSkippedExportLogComponent>;
let exportLogService: jasmine.SpyObj<ExportLogService>;
let userService: jasmine.SpyObj<UserService>;
let paginatorService: jasmine.SpyObj<PaginatorService>;

beforeEach(async () => {
const exportLogServiceSpy = jasmine.createSpyObj('ExportLogService', ['getSkippedExpenses']);
const userServiceSpy = jasmine.createSpyObj('UserService', ['getUserProfile']);
const paginatorServiceSpy = jasmine.createSpyObj('PaginatorService', ['getPageSize', 'storePageSize']);

await TestBed.configureTestingModule({
declarations: [ QboSkippedExportLogComponent ]
})
.compileComponents();
declarations: [ QboSkippedExportLogComponent ],
imports: [ ReactiveFormsModule ],
providers: [
FormBuilder,
{ provide: ExportLogService, useValue: exportLogServiceSpy },
{ provide: UserService, useValue: userServiceSpy },
{ provide: AccountingExportService, useValue: {} },
{ provide: WindowService, useValue: {} },
{ provide: PaginatorService, useValue: paginatorServiceSpy }
]
}).compileComponents();

exportLogService = TestBed.inject(ExportLogService) as jasmine.SpyObj<ExportLogService>;
userService = TestBed.inject(UserService) as jasmine.SpyObj<UserService>;
paginatorService = TestBed.inject(PaginatorService) as jasmine.SpyObj<PaginatorService>;
});

beforeEach(() => {
fixture = TestBed.createComponent(QboSkippedExportLogComponent);
component = fixture.componentInstance;
userService.getUserProfile.and.returnValue(mockUserProfile);
paginatorService.getPageSize.and.returnValue(mockPaginator);
exportLogService.getSkippedExpenses.and.returnValue(of(mockSkippedExpenseGroup));
fixture.detectChanges();
});

it('should create', () => {
expect(component).toBeTruthy();
});
});

it('should initialize with correct data', () => {
expect(component.isLoading).toBeFalse();
expect(component.totalCount).toBe(mockSkippedExpenseGroup.count);
expect(component.expenses.length).toBe(mockSkippedExpenseGroup.results.length);
expect(component.limit).toBe(mockPaginator.limit);
expect(component.offset).toBe(mockPaginator.offset);
});

it('should handle simple search', fakeAsync(() => {
const searchQuery = 'anish';
component.handleSimpleSearch(searchQuery);
tick(1000);
expect(component.searchQuery).toBe(searchQuery);
expect(component.offset).toBe(0);
expect(component.currentPage).toBe(1);
}));

it('should handle page size changes', () => {
const newLimit = 100;
component.pageSizeChanges(newLimit);
expect(component.isLoading).toBeFalse();
expect(component.currentPage).toBe(1);
expect(component.limit).toBe(newLimit);
expect(paginatorService.storePageSize).toHaveBeenCalledWith(PaginatorPage.EXPORT_LOG, newLimit);
});

it('should handle page changes', () => {
const newOffset = 50;
component.limit = 50;
component.pageChanges(newOffset);
expect(component.isLoading).toBeFalse();
expect(component.offset).toBe(newOffset);
expect(component.currentPage).toBe(2);
});

it('should handle date range selection and hide/show calendar', fakeAsync(() => {
const startDate = new Date('2023-06-15');
const endDate = new Date('2023-06-16');

component.skipExportLogForm.controls.start.setValue([startDate, endDate]);
tick();

expect(component.isDateSelected).toBeTrue();
expect(component.selectedDateFilter).toEqual({ startDate, endDate });
expect(component.hideCalendar).toBeTrue();

tick(10);

expect(component.hideCalendar).toBeFalse();
}));

it('should handle date range reset', fakeAsync(() => {
component.skipExportLogForm.controls.start.setValue(null);
tick();
expect(component.isDateSelected).toBeFalse();
expect(component.selectedDateFilter).toBeNull();
}));

it('should filter expenses based on date range', fakeAsync(() => {
const startDate = new Date('2023-06-15');
const endDate = new Date('2023-06-16');
exportLogService.getSkippedExpenses.and.returnValue(of(mockSkippedExpenseGroupWithDateRange));

component.skipExportLogForm.controls.start.setValue([startDate, endDate]);

tick();
tick(10);

expect(component.filteredExpenses.length).toBe(mockSkippedExpenseGroupWithDateRange.results.length);
expect(component.totalCount).toBe(mockSkippedExpenseGroupWithDateRange.count);
expect(component.hideCalendar).toBeFalse();

flush();
}));
});
87 changes: 87 additions & 0 deletions src/app/integrations/qbo/qbo.fixture.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ import { AccountingExportSummary } from "src/app/core/models/db/accounting-expor
import { Error } from "src/app/core/models/db/error.model";
import { AccountingExport } from "src/app/core/models/db/accounting-export.model";
import { ExpenseGroupResponse } from "src/app/core/models/db/expense-group.model";
import { SkipExportLogResponse } from "src/app/core/models/intacct/db/expense-group.model";
import { Paginator } from "src/app/core/models/misc/paginator.model";

export const mockUser: MinimalUser = {
org_id: '123',
Expand Down Expand Up @@ -2154,4 +2156,89 @@ export const mockExpenseGroupResponse: ExpenseGroupResponse = {
]
};

export const mockSkippedExpenseGroup: SkipExportLogResponse = {
count: 4,
next: "http://quickbooks-api.staging-integrations:8000/api/workspaces/454/fyle/expenses/?is_skipped=true&limit=50&offset=50&org_id=or79Cob97KSh",
previous: null,
results: [
{
updated_at: new Date("2024-02-23T05:30:21.570820Z"),
claim_number: "C/2022/04/R/9",
employee_email: "[email protected]",
employee_name: "Ashwin",
fund_source: "CCC",
expense_id: "txuPPcLBZhYW",
org_id: "or79Cob97KSh"
},
{
updated_at: new Date("2024-02-23T05:30:21.564674Z"),
claim_number: "C/2021/04/R/46",
employee_email: "[email protected]",
employee_name: "Victor Martinez",
fund_source: "CCC",
expense_id: "txT4JbfgtooE",
org_id: "or79Cob97KSh"
},
{
updated_at: new Date("2024-02-23T05:30:21.248800Z"),
claim_number: "C/2022/04/R/30",
employee_email: "[email protected]",
employee_name: "Ashwin",
fund_source: "CCC",
expense_id: "txYQYWA1c6bU",
org_id: "or79Cob97KSh"
},
{
updated_at: new Date("2024-02-23T05:30:21.240046Z"),
claim_number: "C/2022/08/R/22",
employee_email: "[email protected]",
employee_name: "Ashwin",
fund_source: "CCC",
expense_id: "txyBQM9yIC9J",
org_id: "or79Cob97KSh"
}
]
};

export const mockSkippedExpenseGroupWithDateRange: SkipExportLogResponse = {
count: 2,
next: null,
previous: null,
results: [
{
updated_at: new Date("2023-06-15T10:30:00.000Z"),
claim_number: "C/2023/06/R/1",
employee_email: "[email protected]",
employee_name: "John Doe",
fund_source: "PERSONAL",
expense_id: "txABC123",
org_id: "or79Cob97KSh"
},
{
updated_at: new Date("2023-06-16T14:45:00.000Z"),
claim_number: "C/2023/06/R/2",
employee_email: "[email protected]",
employee_name: "Jane Smith",
fund_source: "CCC",
expense_id: "txDEF456",
org_id: "or79Cob97KSh"
}
]
};

export const mockPaginator: Paginator = {
limit: 50,
offset: 0
};

export const mockUserProfile = {
org_id: 'or79Cob97KSh',
email: '[email protected]',
access_token: 'dummy_access_token',
refresh_token: 'dummy_refresh_token',
full_name: 'Test User',
user_id: 'user123',
org_name: 'Test Org'
};

export const mockPageSize = { limit: 10, offset: 0 };
Loading