@@ -23,21 +23,30 @@ import {Plan} from '../../../shared/models';
2323describe ( 'BillingPlanComponent' , ( ) => {
2424 let component : BillingPlanComponent ;
2525 let fixture : ComponentFixture < BillingPlanComponent > ;
26- let billingplanService : BillingPlanService ;
26+ let mockBillingPlanService : jasmine . SpyObj < BillingPlanService > ;
2727 let location : Location ;
2828 let route : ActivatedRoute ;
2929 let router : Router ;
3030
31- class MockBillingPlanService {
32- getBillingDetails ( filter : BackendFilter < Plan > ) : Observable < AnyObject [ ] > {
33- return of ( [ ] ) ;
34- }
35- getTotalBillingPlan ( ) : Observable < Count > {
36- return of ( { count : 0 } ) ;
37- }
38- }
31+ const mockBillingData = [
32+ {
33+ companyName : 'Test Company' ,
34+ userName : 'John Doe' ,
35+ planName : 'Premium' ,
36+ startDate : '2024-01-01' ,
37+ endDate : '2024-12-31' ,
38+ status : SubscriptionStatus . ACTIVE ,
39+ } ,
40+ ] ;
3941
4042 beforeEach ( async ( ) => {
43+ mockBillingPlanService = jasmine . createSpyObj ( 'BillingPlanService' , [
44+ 'getPlanOptions' ,
45+ 'getTotalPlan' ,
46+ 'getBillingDetails' ,
47+ 'getTotalBillingPlan' ,
48+ ] ) ;
49+
4150 await TestBed . configureTestingModule ( {
4251 declarations : [ BillingPlanComponent ] ,
4352 imports : [ ThemeModule , RouterTestingModule , MainModule ] ,
@@ -47,15 +56,14 @@ describe('BillingPlanComponent', () => {
4756 { provide : Location , useValue : location } ,
4857 { provide : ActivatedRoute , useValue : route } ,
4958 { provide : Router , useValue : router } ,
50- { provide : BillingPlanService , useClass : MockBillingPlanService } ,
59+ { provide : BillingPlanService , useValue : mockBillingPlanService } ,
5160 ] ,
5261 } ) . compileComponents ( ) ;
5362 } ) ;
5463
5564 beforeEach ( ( ) => {
5665 fixture = TestBed . createComponent ( BillingPlanComponent ) ;
5766 component = fixture . componentInstance ;
58- billingplanService = TestBed . inject ( BillingPlanService ) ;
5967 location = TestBed . inject ( Location ) ;
6068 route = TestBed . inject ( ActivatedRoute ) ;
6169 router = TestBed . inject ( Router ) ;
@@ -74,15 +82,70 @@ describe('BillingPlanComponent', () => {
7482
7583 it ( 'should call getTotal and return count' , ( ) => {
7684 const mockCount : Count = { count : 10 } ;
77- spyOn ( billingplanService , 'getTotalBillingPlan' ) . and . returnValue (
78- of ( mockCount ) ,
79- ) ;
85+ mockBillingPlanService . getTotalBillingPlan . and . returnValue ( of ( mockCount ) ) ;
8086
8187 component . getTotal ( ) . subscribe ( count => {
8288 expect ( count ) . toEqual ( mockCount ) ;
8389 } ) ;
8490 } ) ;
8591
92+ it ( 'should define correct column definitions' , ( ) => {
93+ expect ( component . colDefs . length ) . toBe ( 6 ) ;
94+ expect ( component . colDefs ) . toContain (
95+ jasmine . objectContaining ( {
96+ field : 'companyName' ,
97+ width : 200 ,
98+ minWidth : 20 ,
99+ } ) ,
100+ ) ;
101+ expect ( component . colDefs ) . toContain (
102+ jasmine . objectContaining ( { field : 'userName' , width : 200 , minWidth : 20 } ) ,
103+ ) ;
104+ expect ( component . colDefs ) . toContain (
105+ jasmine . objectContaining ( { field : 'planName' , width : 200 , minWidth : 20 } ) ,
106+ ) ;
107+ expect ( component . colDefs ) . toContain (
108+ jasmine . objectContaining ( { field : 'startDate' , width : 200 , minWidth : 20 } ) ,
109+ ) ;
110+ expect ( component . colDefs ) . toContain (
111+ jasmine . objectContaining ( { field : 'endDate' , width : 200 , minWidth : 20 } ) ,
112+ ) ;
113+ expect ( component . colDefs ) . toContain (
114+ jasmine . objectContaining ( { field : 'status' , width : 200 , minWidth : 20 } ) ,
115+ ) ;
116+ } ) ;
117+
118+ it ( 'should get paginated billing plans' , done => {
119+ const page = 1 ;
120+ const limit = 5 ;
121+
122+ // Make sure the spy is properly configured before the test
123+ mockBillingPlanService . getBillingDetails . and . returnValue (
124+ of ( mockBillingData ) ,
125+ ) ;
126+
127+ component . getPaginatedBillPlans ( page , limit ) . subscribe ( {
128+ next : data => {
129+ expect ( mockBillingPlanService . getBillingDetails ) . toHaveBeenCalledWith ( {
130+ offset : limit * ( page - 1 ) ,
131+ limit : limit ,
132+ } ) ;
133+ expect ( data [ 0 ] ) . toEqual ( {
134+ companyName : mockBillingData [ 0 ] . companyName ,
135+ userName : mockBillingData [ 0 ] . userName ,
136+ planName : mockBillingData [ 0 ] . planName ,
137+ startDate : mockBillingData [ 0 ] . startDate ,
138+ endDate : mockBillingData [ 0 ] . endDate ,
139+ status : SubscriptionStatus [ mockBillingData [ 0 ] . status ] ,
140+ } ) ;
141+ done ( ) ;
142+ } ,
143+ error : error => {
144+ done . fail ( error ) ;
145+ } ,
146+ } ) ;
147+ } ) ;
148+
86149 it ( 'should call getPaginatedBillPlans and return transformed data' , ( ) => {
87150 const mockPlans = [
88151 {
@@ -103,9 +166,7 @@ describe('BillingPlanComponent', () => {
103166 } ,
104167 ] ;
105168
106- spyOn ( billingplanService , 'getBillingDetails' ) . and . returnValue (
107- of ( mockPlans ) ,
108- ) ;
169+ mockBillingPlanService . getBillingDetails . and . returnValue ( of ( mockPlans ) ) ;
109170
110171 component . getPaginatedBillPlans ( 1 , component . limit ) . subscribe ( data => {
111172 expect ( data ) . toEqual ( [
@@ -129,7 +190,7 @@ describe('BillingPlanComponent', () => {
129190 } ) ;
130191 } ) ;
131192 it ( 'should handle errors in getPaginatedBillPlans' , ( ) => {
132- spyOn ( billingplanService , ' getBillingDetails' ) . and . returnValue (
193+ mockBillingPlanService . getBillingDetails . and . returnValue (
133194 throwError ( 'Error' ) ,
134195 ) ;
135196
0 commit comments