Skip to content

Commit 3f4a565

Browse files
committed
test(arc-saas): adding missing test cases on enhanced test cases
adding missing test cases on enhanced test cases GH-67
1 parent c08a8af commit 3f4a565

File tree

10 files changed

+677
-129
lines changed

10 files changed

+677
-129
lines changed

projects/saas-ui/src/app/main/components/billing-plan/billing-plan.component.spec.ts

Lines changed: 79 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -23,21 +23,30 @@ import {Plan} from '../../../shared/models';
2323
describe('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

projects/saas-ui/src/app/main/components/button-renderer/button-renderer.component.spec.ts

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,19 @@ describe('ButtonRendererComponent', () => {
146146
expect(mockRouter.navigate).toHaveBeenCalledWith(['/main/edit-plan/1']);
147147
});
148148

149+
it('should navigate to edit plan with correct id', () => {
150+
const params: ICellRendererParams = {
151+
node: {
152+
data: {
153+
id: 2,
154+
},
155+
},
156+
} as any;
157+
component.agInit(params);
158+
component.editPlan(null);
159+
expect(mockRouter.navigate).toHaveBeenCalledWith(['/main/edit-plan/2']);
160+
});
161+
149162
it('should return true on refresh method', () => {
150163
const params = {} as any;
151164
const result = component.refresh(params);
@@ -157,4 +170,18 @@ describe('ButtonRendererComponent', () => {
157170
component.onGridReady(params);
158171
expect(component.gridApi).toEqual(params.api);
159172
});
173+
174+
it('should validate form fields', () => {
175+
component.addPlanForm.controls['name'].setValue('Test Plan');
176+
component.addPlanForm.controls['description'].setValue('Test Description');
177+
component.addPlanForm.controls['price'].setValue(100);
178+
component.addPlanForm.controls['currencyId'].setValue('USD');
179+
component.addPlanForm.controls['billingCycleId'].setValue(1);
180+
component.addPlanForm.controls['tier'].setValue(1);
181+
182+
expect(component.addPlanForm.valid).toBeTrue();
183+
184+
component.addPlanForm.controls['name'].setValue('');
185+
expect(component.addPlanForm.valid).toBeFalse();
186+
});
160187
});
Lines changed: 48 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,23 @@
1-
import { ComponentFixture, TestBed } from '@angular/core/testing';
1+
import {ComponentFixture, TestBed} from '@angular/core/testing';
22

3-
import { EyeIconRendererComponent } from './eye-icon-renderer.component';
3+
import {EyeIconRendererComponent} from './eye-icon-renderer.component';
4+
import {NbThemeModule} from '@nebular/theme';
5+
import {ThemeModule} from '@project-lib/theme/theme.module';
6+
import {Router} from '@angular/router';
7+
import {By} from '@angular/platform-browser';
8+
import {ICellRendererParams} from 'ag-grid-community';
49

510
describe('EyeIconRendererComponent', () => {
611
let component: EyeIconRendererComponent;
712
let fixture: ComponentFixture<EyeIconRendererComponent>;
13+
let router: jasmine.SpyObj<Router>;
814

915
beforeEach(async () => {
16+
router = jasmine.createSpyObj(['navigate']);
1017
await TestBed.configureTestingModule({
11-
declarations: [ EyeIconRendererComponent ]
12-
})
13-
.compileComponents();
18+
imports: [NbThemeModule.forRoot(), ThemeModule],
19+
declarations: [EyeIconRendererComponent],
20+
}).compileComponents();
1421

1522
fixture = TestBed.createComponent(EyeIconRendererComponent);
1623
component = fixture.componentInstance;
@@ -20,4 +27,40 @@ describe('EyeIconRendererComponent', () => {
2027
it('should create', () => {
2128
expect(component).toBeTruthy();
2229
});
30+
31+
describe('agInit', () => {
32+
it('should initialize params with the provided values', () => {
33+
const mockParams = {node: {data: {id: '123'}}};
34+
component.agInit(mockParams);
35+
expect(component['params']).toEqual(mockParams);
36+
});
37+
});
38+
39+
describe('refresh', () => {
40+
it('should return false when refresh is called', () => {
41+
const result = component.refresh({});
42+
expect(result).toBeFalse();
43+
});
44+
});
45+
46+
it('should render the eye icon as visible when the parameter is true', () => {
47+
const mockParams = {node: {data: {id: '123', visible: true}}};
48+
component.agInit(mockParams);
49+
fixture.detectChanges();
50+
const iconElement = fixture.debugElement.query(By.css('.eye-icon'));
51+
expect(iconElement).toBeTruthy(); // Check if the icon is rendered
52+
// expect(iconElement.nativeElement.classList).toContain('visible'); // Assuming there's a class for visibility
53+
});
54+
55+
it('should handle invalid parameters gracefully', () => {
56+
const mockParams = null; // Simulating invalid parameters
57+
component.agInit(mockParams);
58+
expect(component['params']).toBeNull();
59+
});
60+
61+
it('should navigate to the correct route when onClick is called', () => {
62+
// Arrange: Set up mock parameters with a specific row data ID
63+
const mockParams = {node: {data: {id: '123'}}};
64+
component.agInit;
65+
});
2366
});

0 commit comments

Comments
 (0)