Skip to content

Commit 3274b50

Browse files
committed
update tests and rename component
1 parent 7c638b1 commit 3274b50

File tree

9 files changed

+45
-42
lines changed

9 files changed

+45
-42
lines changed

web-app/admin/src/app/admin/admin-teams/admin-teams.module.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,21 +10,21 @@ import { MatFormFieldModule } from '@angular/material/form-field';
1010
import { MatInputModule } from '@angular/material/input';
1111
import { MatButtonModule } from '@angular/material/button';
1212

13-
import { AdminTeamsComponent } from './admin-dashboard/admin-teams.component';
14-
import { AdminTeamCreateComponent } from './admin-team-create/admin-team-create.component';
13+
import { TeamDashboardComponent } from './dashboard/team-dashboard.component';
14+
import { CreateTeamDialogComponent } from './create-team/create-team.component';
1515
import { TeamsService } from './teams-service';
1616

1717
const routes: Routes = [
1818
{
1919
path: '',
20-
component: AdminTeamsComponent
20+
component: TeamDashboardComponent
2121
}
2222
];
2323

2424
@NgModule({
2525
declarations: [
26-
AdminTeamsComponent,
27-
AdminTeamCreateComponent
26+
TeamDashboardComponent,
27+
CreateTeamDialogComponent
2828
],
2929
imports: [
3030
CommonModule,
@@ -43,7 +43,7 @@ const routes: Routes = [
4343
TeamsService
4444
],
4545
entryComponents: [
46-
AdminTeamCreateComponent
46+
CreateTeamDialogComponent
4747
]
4848
})
4949
export class AdminTeamsModule { }
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
<div class="admin-team-create">
22
<h1 mat-dialog-title>New Team</h1>
33
<div mat-dialog-content>
4+
<div *ngIf="errorMessage" class="error-message" style="color: red; margin-bottom: 16px;">
5+
{{ errorMessage }}
6+
</div>
47
<form [formGroup]="teamForm">
58
<mat-form-field class="full-width">
69
<mat-label>Name</mat-label>
Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,15 @@ import { Team } from '../team';
66

77
@Component({
88
selector: 'mage-admin-team-create',
9-
templateUrl: './admin-team-create.component.html',
10-
styleUrls: ['./admin-team-create.component.scss']
9+
templateUrl: './create-team.component.html',
10+
styleUrls: ['./create-team.component.scss']
1111
})
12-
export class AdminTeamCreateComponent {
12+
export class CreateTeamDialogComponent {
1313
teamForm: FormGroup;
14+
errorMessage: string = '';
1415

1516
constructor(
16-
public dialogRef: MatDialogRef<AdminTeamCreateComponent>,
17+
public dialogRef: MatDialogRef<CreateTeamDialogComponent>,
1718
@Inject(MAT_DIALOG_DATA) public data: { team: Partial<Team> },
1819
private fb: FormBuilder,
1920
private teamsService: TeamsService
@@ -26,12 +27,19 @@ export class AdminTeamCreateComponent {
2627

2728
save(): void {
2829
if (this.teamForm.invalid) {
30+
this.errorMessage = 'Please fill in all required fields.';
2931
return;
3032
}
3133

34+
this.errorMessage = '';
3235
const teamData = this.teamForm.value;
33-
this.teamsService.createTeam(teamData).subscribe(newTeam => {
34-
this.dialogRef.close(newTeam);
36+
this.teamsService.createTeam(teamData).subscribe({
37+
next: (newTeam) => {
38+
this.dialogRef.close(newTeam);
39+
},
40+
error: () => {
41+
this.errorMessage = 'Failed to create team. Please try again.';
42+
}
3543
});
3644
}
3745

Lines changed: 15 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,14 @@ import { NoopAnimationsModule } from '@angular/platform-browser/animations';
66
import { FormsModule } from '@angular/forms';
77
import { of } from 'rxjs';
88

9-
import { AdminTeamsComponent } from './admin-teams.component';
9+
import { TeamDashboardComponent } from './team-dashboard.component';
1010
import { TeamsService } from '../teams-service';
1111
import { Team } from '../team';
12-
import { AdminTeamCreateComponent } from '../admin-team-create/admin-team-create.component';
12+
import { CreateTeamDialogComponent } from '../create-team/create-team.component';
1313

14-
describe('AdminTeamsComponent', () => {
15-
let component: AdminTeamsComponent;
16-
let fixture: ComponentFixture<AdminTeamsComponent>;
14+
fdescribe('TeamDashboardComponent', () => {
15+
let component: TeamDashboardComponent;
16+
let fixture: ComponentFixture<TeamDashboardComponent>;
1717
let mockTeamsService: jasmine.SpyObj<TeamsService>;
1818
let mockDialog: jasmine.SpyObj<MatDialog>;
1919

@@ -33,7 +33,7 @@ describe('AdminTeamsComponent', () => {
3333
const dialogSpy = jasmine.createSpyObj('MatDialog', ['open']);
3434

3535
await TestBed.configureTestingModule({
36-
declarations: [AdminTeamsComponent],
36+
declarations: [TeamDashboardComponent],
3737
imports: [
3838
MatTableModule,
3939
MatPaginatorModule,
@@ -46,19 +46,17 @@ describe('AdminTeamsComponent', () => {
4646
]
4747
}).compileComponents();
4848

49-
fixture = TestBed.createComponent(AdminTeamsComponent);
49+
fixture = TestBed.createComponent(TeamDashboardComponent);
5050
component = fixture.componentInstance;
5151
mockTeamsService = TestBed.inject(TeamsService) as jasmine.SpyObj<TeamsService>;
5252
mockDialog = TestBed.inject(MatDialog) as jasmine.SpyObj<MatDialog>;
5353

5454
mockTeamsService.getTeams.and.returnValue(of(mockTeamsResponse));
55+
mockTeamsService.getTeams.calls.reset();
5556
});
5657

5758
it('should create', () => {
5859
expect(component).toBeTruthy();
59-
});
60-
61-
it('should initialize with correct default values', () => {
6260
expect(component.teamSearch).toBe('');
6361
expect(component.pageSize).toBe(10);
6462
expect(component.pageIndex).toBe(0);
@@ -81,11 +79,14 @@ describe('AdminTeamsComponent', () => {
8179

8280
it('should perform search with debouncing', fakeAsync(() => {
8381
fixture.detectChanges();
84-
mockTeamsService.getTeams.calls.reset();
85-
8682
component.search('test');
8783
tick(100); // Less than debounce time
88-
expect(mockTeamsService.getTeams).not.toHaveBeenCalled();
84+
expect(mockTeamsService.getTeams).not.toHaveBeenCalledWith({
85+
term: 'test',
86+
sort: { name: 1 },
87+
limit: 10,
88+
start: '0'
89+
});
8990

9091
tick(200); // Complete debounce time (250ms total)
9192
expect(mockTeamsService.getTeams).toHaveBeenCalledWith({
@@ -107,9 +108,6 @@ describe('AdminTeamsComponent', () => {
107108
}));
108109

109110
it('should handle page changes', () => {
110-
fixture.detectChanges();
111-
mockTeamsService.getTeams.calls.reset();
112-
113111
const pageEvent: PageEvent = {
114112
pageIndex: 1,
115113
pageSize: 25,
@@ -131,8 +129,6 @@ describe('AdminTeamsComponent', () => {
131129
it('should reset search and pagination', () => {
132130
component.teamSearch = 'test';
133131
component.pageIndex = 2;
134-
fixture.detectChanges();
135-
mockTeamsService.getTeams.calls.reset();
136132

137133
component.reset();
138134

@@ -153,32 +149,28 @@ describe('AdminTeamsComponent', () => {
153149

154150
component.newTeam();
155151

156-
expect(mockDialog.open).toHaveBeenCalledWith(AdminTeamCreateComponent, {
152+
expect(mockDialog.open).toHaveBeenCalledWith(CreateTeamDialogComponent, {
157153
width: '50rem',
158154
height: '25rem',
159155
data: { team: {} }
160156
});
161157
});
162158

163159
it('should refresh teams after creating new team', () => {
164-
fixture.detectChanges();
165160
const newTeam = { id: '4', name: 'New Team', description: 'New team description' };
166161
const dialogRefSpy = jasmine.createSpyObj('MatDialogRef', ['afterClosed']);
167162
dialogRefSpy.afterClosed.and.returnValue(of(newTeam));
168163
mockDialog.open.and.returnValue(dialogRefSpy);
169-
mockTeamsService.getTeams.calls.reset();
170164

171165
component.newTeam();
172166

173167
expect(mockTeamsService.getTeams).toHaveBeenCalled();
174168
});
175169

176170
it('should not refresh teams if dialog is cancelled', () => {
177-
fixture.detectChanges();
178171
const dialogRefSpy = jasmine.createSpyObj('MatDialogRef', ['afterClosed']);
179172
dialogRefSpy.afterClosed.and.returnValue(of(null));
180173
mockDialog.open.and.returnValue(dialogRefSpy);
181-
mockTeamsService.getTeams.calls.reset();
182174

183175
component.newTeam();
184176

web-app/admin/src/app/admin/admin-teams/admin-dashboard/admin-teams.component.ts renamed to web-app/admin/src/app/admin/admin-teams/dashboard/team-dashboard.component.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,14 @@ import { Team } from '../team';
66
import { Subject } from 'rxjs';
77
import { debounceTime, distinctUntilChanged, switchMap, takeUntil } from 'rxjs/operators';
88
import { TeamsService } from '../teams-service';
9-
import { AdminTeamCreateComponent } from '../admin-team-create/admin-team-create.component';
9+
import { CreateTeamDialogComponent } from '../create-team/create-team.component';
1010

1111
@Component({
1212
selector: 'mage-admin-teams',
13-
templateUrl: './admin-teams.component.html',
14-
styleUrls: ['./admin-teams.component.scss']
13+
templateUrl: './team-dashboard.component.html',
14+
styleUrls: ['./team-dashboard.component.scss']
1515
})
16-
export class AdminTeamsComponent implements OnInit, OnDestroy {
16+
export class TeamDashboardComponent implements OnInit, OnDestroy {
1717
teamSearch = '';
1818
teams: Team[] = [];
1919
totalTeams = 0;
@@ -97,7 +97,7 @@ export class AdminTeamsComponent implements OnInit, OnDestroy {
9797
}
9898

9999
newTeam(): void {
100-
const dialogRef = this.modal.open(AdminTeamCreateComponent, {
100+
const dialogRef = this.modal.open(CreateTeamDialogComponent, {
101101
width: '50rem',
102102
height: '25rem',
103103
data: { team: {} }

web-app/admin/src/ng1/app.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ import { AdminServiceComponent } from '../app/admin/admin-feeds/admin-service/ad
2424
import { AdminFeedEditComponent } from '../app/admin/admin-feeds/admin-feed/admin-feed-edit/admin-feed-edit.component';
2525
import { AuthenticationCreateComponent } from '../app/admin/admin-authentication/admin-authentication-create/admin-authentication-create.component';
2626
import { AdminEventFormPreviewComponent } from '../app/admin/admin-event/admin-event-form/admin-event-form-preview/admin-event-form-preview.component';
27-
import { AdminTeamsComponent } from '../app/admin/admin-teams/admin-dashboard/admin-teams.component';
27+
import { TeamDashboardComponent } from '../app/admin/admin-teams/dashboard/team-dashboard.component';
2828

2929
require('angular-minicolors');
3030
require('select2');
@@ -64,7 +64,7 @@ app
6464
.directive('authenticationCreate', downgradeComponent({ component: AuthenticationCreateComponent }))
6565
.directive('contact', downgradeComponent({ component: ContactComponent }))
6666
.directive('adminEventFormPreview', downgradeComponent({ component: AdminEventFormPreviewComponent }))
67-
.directive('adminTeams', downgradeComponent({ component: AdminTeamsComponent }));
67+
.directive('adminTeams', downgradeComponent({ component: TeamDashboardComponent }));
6868

6969
app
7070
.component('navbar', require('./navbar/navbar.component'))

0 commit comments

Comments
 (0)