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' ;
36import { 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+ } ) ;
0 commit comments