Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 841ce1a

Browse files
Report component styling and unit test
1 parent f38d254 commit 841ce1a

File tree

2 files changed

+54
-14
lines changed

2 files changed

+54
-14
lines changed
Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,15 @@
1-
<div class="user-bar-chart">
1+
<div class="container">
22
<h2>Users active/In-active report</h2>
33
<mat-divider></mat-divider>
4-
<canvas
5-
baseChart
6-
class="chart"
7-
[data]="barChartData"
8-
[options]="barChartOptions"
9-
[plugins]="barChartPlugins"
10-
[type]="barChartType"
11-
>
12-
</canvas>
4+
<div class="user-bar-chart">
5+
<canvas
6+
baseChart
7+
class="chart"
8+
[data]="barChartData"
9+
[options]="barChartOptions"
10+
[plugins]="barChartPlugins"
11+
[type]="barChartType"
12+
>
13+
</canvas>
14+
</div>
1315
</div>
Lines changed: 42 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,66 @@
11
import { ComponentFixture, TestBed } from '@angular/core/testing';
2-
32
import { UserReportComponent } from './user-report.component';
43
import { UsersService } from 'src/app/shared/services/users.service';
4+
import { of } from 'rxjs';
5+
import { User } from 'src/app/shared/models/user.model';
56
import { HttpClientTestingModule } from '@angular/common/http/testing';
67
import { MaterialModule } from 'src/app/shared/material.module';
78
import { NgChartsModule } from 'ng2-charts';
89

9-
describe('UserRepotComponent', () => {
10+
describe('UserReportComponent', () => {
1011
let component: UserReportComponent;
1112
let fixture: ComponentFixture<UserReportComponent>;
13+
let usersService: UsersService;
1214

1315
beforeEach(async () => {
1416
await TestBed.configureTestingModule({
1517
imports: [HttpClientTestingModule, MaterialModule, NgChartsModule],
1618
declarations: [UserReportComponent],
1719
providers: [UsersService],
1820
}).compileComponents();
21+
});
1922

23+
beforeEach(() => {
2024
fixture = TestBed.createComponent(UserReportComponent);
2125
component = fixture.componentInstance;
26+
usersService = TestBed.inject(UsersService);
2227
fixture.detectChanges();
2328
});
2429

25-
it('should create', () => {
26-
expect(component).toBeTruthy();
30+
it('should prepare chart data correctly', () => {
31+
const mockUsers: User[] = [
32+
{
33+
id: 1,
34+
name: 'John Doe',
35+
avatar: 'avatar_url',
36+
status: true,
37+
email: 'john@example.com',
38+
createdAt: '2022年01月01日T00:00:00',
39+
},
40+
{
41+
id: 2,
42+
name: 'Jane Doe',
43+
avatar: 'avatar_url',
44+
status: false,
45+
email: 'jane@example.com',
46+
createdAt: '2022年02月01日T00:00:00',
47+
},
48+
];
49+
50+
spyOn(usersService, 'getUsers').and.returnValue(of(mockUsers));
51+
spyOn(component, 'prepareChartData').and.callThrough();
52+
53+
component.getUsers();
54+
55+
expect(usersService.getUsers).toHaveBeenCalled();
56+
57+
expect(component.prepareChartData).toHaveBeenCalledWith(mockUsers);
58+
59+
expect(component.barChartData.labels).toEqual(['2022']);
60+
expect(component.barChartData.datasets.length).toBe(2);
61+
expect(component.barChartData.datasets[0].label).toBe('Inactive user');
62+
expect(component.barChartData.datasets[0].data).toEqual([1]);
63+
expect(component.barChartData.datasets[1].label).toBe('Active user');
64+
expect(component.barChartData.datasets[1].data).toEqual([1]);
2765
});
2866
});

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /