1- import { ComponentFixture , TestBed } from '@angular/core/testing' ;
2-
1+ import { ComponentFixture , TestBed , fakeAsync , tick } from '@angular/core/testing' ;
2+ import { FormBuilder , ReactiveFormsModule } from '@angular/forms' ;
3+ import { of } from 'rxjs' ;
34import { IntacctCompletedExportLogComponent } from './intacct-completed-export-log.component' ;
5+ import { TrackingService } from 'src/app/core/services/integration/tracking.service' ;
6+ import { ExportLogService } from 'src/app/core/services/common/export-log.service' ;
7+ import { PaginatorService } from 'src/app/core/services/common/paginator.service' ;
8+ import { UserService } from 'src/app/core/services/misc/user.service' ;
9+ import { mockExpenseGroupResponse , mockPaginator } from '../../../intacct.fixture' ;
10+ import { PaginatorPage , TaskLogState } from 'src/app/core/models/enum/enum.model' ;
11+ import { MinimalUser } from 'src/app/core/models/db/user.model' ;
12+ import { SharedModule } from 'src/app/shared/shared.module' ;
413
5- xdescribe ( 'IntacctCompletedExportLogComponent' , ( ) => {
14+ describe ( 'IntacctCompletedExportLogComponent' , ( ) => {
615 let component : IntacctCompletedExportLogComponent ;
716 let fixture : ComponentFixture < IntacctCompletedExportLogComponent > ;
17+ let exportLogService : jasmine . SpyObj < ExportLogService > ;
18+ let trackingService : jasmine . SpyObj < TrackingService > ;
19+ let paginatorService : jasmine . SpyObj < PaginatorService > ;
20+ let userService : jasmine . SpyObj < UserService > ;
821
922 beforeEach ( async ( ) => {
23+ const exportLogServiceSpy = jasmine . createSpyObj ( 'ExportLogService' , [ 'getExpenseGroups' ] ) ;
24+ const trackingServiceSpy = jasmine . createSpyObj ( 'TrackingService' , [ 'onDateFilter' ] ) ;
25+ const paginatorServiceSpy = jasmine . createSpyObj ( 'PaginatorService' , [ 'getPageSize' , 'storePageSize' ] ) ;
26+ const userServiceSpy = jasmine . createSpyObj ( 'UserService' , [ 'getUserProfile' ] ) ;
27+
1028 await TestBed . configureTestingModule ( {
11- declarations : [ IntacctCompletedExportLogComponent ]
12- } )
13- . compileComponents ( ) ;
29+ declarations : [ IntacctCompletedExportLogComponent ] ,
30+ imports : [ ReactiveFormsModule , SharedModule ] ,
31+ providers : [
32+ FormBuilder ,
33+ { provide : ExportLogService , useValue : exportLogServiceSpy } ,
34+ { provide : TrackingService , useValue : trackingServiceSpy } ,
35+ { provide : PaginatorService , useValue : paginatorServiceSpy } ,
36+ { provide : UserService , useValue : userServiceSpy }
37+ ]
38+ } ) . compileComponents ( ) ;
39+
40+ exportLogService = TestBed . inject ( ExportLogService ) as jasmine . SpyObj < ExportLogService > ;
41+ trackingService = TestBed . inject ( TrackingService ) as jasmine . SpyObj < TrackingService > ;
42+ paginatorService = TestBed . inject ( PaginatorService ) as jasmine . SpyObj < PaginatorService > ;
43+ userService = TestBed . inject ( UserService ) as jasmine . SpyObj < UserService > ;
44+
45+ userService . getUserProfile . and . returnValue ( { org_id : 'ORG123' } as MinimalUser ) ;
46+ paginatorService . getPageSize . and . returnValue ( mockPaginator ) ;
47+ exportLogService . getExpenseGroups . and . returnValue ( of ( mockExpenseGroupResponse ) ) ;
1448
1549 fixture = TestBed . createComponent ( IntacctCompletedExportLogComponent ) ;
1650 component = fixture . componentInstance ;
17- fixture . detectChanges ( ) ;
1851 } ) ;
1952
53+
2054 it ( 'should create' , ( ) => {
2155 expect ( component ) . toBeTruthy ( ) ;
2256 } ) ;
23- } ) ;
57+
58+ it ( 'should initialize component and load data' , ( ) => {
59+ component . ngOnInit ( ) ;
60+ expect ( component . limit ) . toBe ( mockPaginator . limit ) ;
61+ expect ( component . offset ) . toBe ( mockPaginator . offset ) ;
62+ expect ( component . isLoading ) . toBeFalse ( ) ;
63+ expect ( component . totalCount ) . toBe ( mockExpenseGroupResponse . count ) ;
64+ expect ( component . filteredAccountingExports . length ) . toBe ( mockExpenseGroupResponse . results . length ) ;
65+ expect ( component . filteredAccountingExports ) . toEqual ( component . accountingExports ) ;
66+ } ) ;
67+
68+ it ( 'should handle page size changes' , ( ) => {
69+ const newLimit = 20 ;
70+ component . pageSizeChanges ( newLimit ) ;
71+ expect ( component . limit ) . toBe ( newLimit ) ;
72+ expect ( component . currentPage ) . toBe ( 1 ) ;
73+ expect ( paginatorService . storePageSize ) . toHaveBeenCalledWith ( PaginatorPage . EXPORT_LOG , newLimit ) ;
74+ expect ( exportLogService . getExpenseGroups ) . toHaveBeenCalled ( ) ;
75+ } ) ;
76+
77+ it ( 'should handle page changes' , ( ) => {
78+ fixture . detectChanges ( ) ;
79+ component . pageChanges ( 10 ) ;
80+ expect ( component . offset ) . toBe ( 10 ) ;
81+ expect ( component . currentPage ) . toBe ( 2 ) ;
82+ expect ( exportLogService . getExpenseGroups ) . toHaveBeenCalled ( ) ;
83+ } ) ;
84+
85+ it ( 'should handle simple search' , fakeAsync ( ( ) => {
86+ const searchQuery = 'test query' ;
87+ fixture . detectChanges ( ) ;
88+ component . handleSimpleSearch ( searchQuery ) ;
89+ tick ( 1000 ) ;
90+ expect ( component . searchQuery ) . toBe ( searchQuery ) ;
91+ expect ( component . offset ) . toBe ( 0 ) ;
92+ expect ( component . currentPage ) . toBe ( 1 ) ;
93+ expect ( exportLogService . getExpenseGroups ) . toHaveBeenCalled ( ) ;
94+ } ) ) ;
95+
96+ it ( 'should open expense in Fyle' , ( ) => {
97+ const expenseId = 'exp123' ;
98+ spyOn ( window , 'open' ) ;
99+ component . openExpenseinFyle ( expenseId ) ;
100+ expect ( window . open ) . toHaveBeenCalledWith ( jasmine . stringContaining ( expenseId ) , '_blank' ) ;
101+ } ) ;
102+
103+ it ( 'should handle date filter changes' , fakeAsync ( ( ) => {
104+ component . ngOnInit ( ) ;
105+ const dateRange = [ new Date ( '2023-01-01' ) , new Date ( '2023-01-31' ) ] ;
106+ component . exportLogForm . controls . start . setValue ( dateRange ) ;
107+ tick ( 10 ) ;
108+ expect ( component . selectedDateFilter ) . toEqual ( {
109+ startDate : dateRange [ 0 ] ,
110+ endDate : dateRange [ 1 ]
111+ } ) ;
112+ expect ( component . isDateSelected ) . toBeTrue ( ) ;
113+ expect ( exportLogService . getExpenseGroups ) . toHaveBeenCalled ( ) ;
114+ expect ( component . hideCalendar ) . toBeFalse ( ) ;
115+ } ) ) ;
116+
117+ it ( 'should clear date filter when null is set' , fakeAsync ( ( ) => {
118+ fixture . detectChanges ( ) ;
119+ component . exportLogForm . controls . start . setValue ( null ) ;
120+ tick ( 10 ) ;
121+ expect ( component . selectedDateFilter ) . toBeNull ( ) ;
122+ expect ( component . isDateSelected ) . toBeFalse ( ) ;
123+ expect ( exportLogService . getExpenseGroups ) . toHaveBeenCalled ( ) ;
124+ } ) ) ;
125+
126+ it ( 'should call getExpenseGroups with correct parameters' , ( ) => {
127+ component . ngOnInit ( ) ;
128+ expect ( exportLogService . getExpenseGroups ) . toHaveBeenCalledWith (
129+ TaskLogState . COMPLETE ,
130+ mockPaginator . limit ,
131+ mockPaginator . offset ,
132+ undefined ,
133+ null ,
134+ undefined
135+ ) ;
136+ } ) ;
137+
138+ it ( 'should track date filter' , ( ) => {
139+ const dateFilter = { startDate : new Date ( '2023-01-01' ) , endDate : new Date ( '2023-01-31' ) } ;
140+ ( component as any ) . trackDateFilter ( 'custom' , dateFilter ) ;
141+ expect ( trackingService . onDateFilter ) . toHaveBeenCalledWith ( jasmine . any ( String ) , jasmine . objectContaining ( dateFilter ) ) ;
142+ } ) ;
143+ } ) ;
0 commit comments