Skip to content

Commit

Permalink
test: criado novos testes unitários
Browse files Browse the repository at this point in the history
  • Loading branch information
BernardoSemiOficial committed Sep 21, 2024
1 parent b17d6f3 commit 848d05d
Show file tree
Hide file tree
Showing 22 changed files with 301 additions and 51 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import { Component } from '@angular/core';

@Component({
standalone: true,
selector: 'app-footer',
template: '',
})
export class AppFooterComponentMock {}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import { Component } from '@angular/core';

@Component({
standalone: true,
selector: 'app-header',
template: '',
})
export class AppHeaderComponentMock {}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Component } from '@angular/core';

@Component({ standalone: true, selector: 'app-invitation', template: '' })
export class InvitationStubComponent {}
export class InvitationComponentMock {}
34 changes: 34 additions & 0 deletions frontend/src/__mocks__/services/auth.service.mock.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import { Injectable } from '@angular/core';

import { of } from 'rxjs';

@Injectable({
providedIn: 'root',
})
export class AuthServiceMock {
logoutByUser() {}
logout() {}
alertMessageLogout() {}
setTokens() {}
setAccessToken() {}

login() {
return of({});
}

register() {
return of({});
}

invitation() {
return of({});
}

refreshToken() {
return of({});
}

getAccessToken() {
return {};
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import { Injectable } from '@angular/core';

@Injectable({
providedIn: 'root',
})
export class DialogConfirmationServiceMock {
addConfirmation() {}
}
17 changes: 17 additions & 0 deletions frontend/src/__mocks__/services/invitation.service.mock.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import { Injectable } from '@angular/core';
import { of } from 'rxjs';

@Injectable({
providedIn: 'root',
})
export class InvitationServiceMock {
getInvitationForUser() {
return of({});
}
postInvitations() {
return of({});
}
deleteInvitation() {
return of({});
}
}
24 changes: 24 additions & 0 deletions frontend/src/__mocks__/services/project.service.mock.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import { Injectable } from '@angular/core';

import { of } from 'rxjs';

@Injectable({
providedIn: 'root',
})
export class ProjectServiceMock {
getProject() {
return of({});
}
getTasksForProject() {
return of({});
}
createProjectForUser() {
return of({});
}
editProjectForUser() {
return of({});
}
deleteProject() {
return of({});
}
}
8 changes: 8 additions & 0 deletions frontend/src/__mocks__/services/router.service.mock.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import { Injectable } from '@angular/core';

@Injectable({
providedIn: 'root',
})
export class RouterServiceMock {
navigate() {}
}
20 changes: 20 additions & 0 deletions frontend/src/__mocks__/services/task.service.mock.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import { Injectable } from '@angular/core';
import { of } from 'rxjs';

@Injectable({
providedIn: 'root',
})
export class TaskServiceMock {
getTask() {
return of({});
}
createTask() {
return of({});
}
editTask() {
return of({});
}
deleteTask() {
return of({});
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
formControlName="projectsId"
[optionLabel]="'name'"
[optionValue]="'id'"
[options]="projects()"
[options]="projects"
>
</app-multi-select>
@if (invitations.controls.length > 1 && i > 0) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,27 @@
import { ComponentFixture, TestBed } from '@angular/core/testing';

import { FormBuilder } from '@angular/forms';
import { InvitationService } from '@core/services/invitation/invitation.service';
import { ToastAlertService } from '@core/services/toast-alert/toast-alert.service';
import { InvitationServiceMock } from 'src/__mocks__/services/invitation.service.mock';
import { ToastAlertServiceMock } from 'src/__mocks__/services/toast-alert.service.mock';
import { DashboardDialogInvitationsComponent } from './dashboard-dialog-invitations.component';

describe('DashboardDialogInvitationsComponent', () => {
let component: DashboardDialogInvitationsComponent;
let fixture: ComponentFixture<DashboardDialogInvitationsComponent>;

beforeEach(async () => {
await TestBed.configureTestingModule({
imports: [DashboardDialogInvitationsComponent],
}).compileComponents();
beforeEach(() => {
TestBed.overrideComponent(DashboardDialogInvitationsComponent, {
set: {
imports: [DashboardDialogInvitationsComponent],
providers: [
FormBuilder,
{ provide: InvitationService, useClass: InvitationServiceMock },
{ provide: ToastAlertService, useClass: ToastAlertServiceMock },
],
},
});

fixture = TestBed.createComponent(DashboardDialogInvitationsComponent);
component = fixture.componentInstance;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Component, inject, Input, input, WritableSignal } from '@angular/core';
import { Component, inject, Input, WritableSignal } from '@angular/core';
import {
FormBuilder,
FormGroup,
Expand Down Expand Up @@ -35,9 +35,11 @@ export class DashboardDialogInvitationsComponent {
private fb = inject(FormBuilder);
invitationsService = inject(InvitationService);
toastAlertService = inject(ToastAlertService);

@Input({ required: true, alias: 'visibleSignal' })
visibleDialogInvites!: WritableSignal<boolean>;
projects = input.required<ProjectForUser[]>();
@Input({ required: true }) projects: ProjectForUser[] = [];

sendInvitesForm!: FormGroup<SendInvitationsForm>;
PrimeIcons = PrimeIcons;
isLoadingInvites = false;
Expand Down
40 changes: 34 additions & 6 deletions frontend/src/app/features/dashboard/dashboard.component.spec.ts
Original file line number Diff line number Diff line change
@@ -1,21 +1,49 @@
import { ComponentFixture, TestBed } from '@angular/core/testing';

import { CommonModule } from '@angular/common';
import { ReactiveFormsModule } from '@angular/forms';
import { ActivatedRoute, RouterLink } from '@angular/router';
import { InvitationService } from '@core/services/invitation/invitation.service';
import { ToastAlertService } from '@core/services/toast-alert/toast-alert.service';
import { UserService } from '@core/services/user/user.service';
import { AppButtonComponent } from '@shared/app-button/app-button.component';
import { AppCardComponent } from '@shared/app-card/app-card.component';
import { AppFooterComponentMock } from 'src/__mocks__/components/app-footer.component.mock';
import { AppHeaderComponentMock } from 'src/__mocks__/components/app-header.component.mock';
import { ActivatedRouteMock } from 'src/__mocks__/services/activated-route.service.mock';
import { InvitationServiceMock } from 'src/__mocks__/services/invitation.service.mock';
import { ToastAlertServiceMock } from 'src/__mocks__/services/toast-alert.service.mock';
import { UserServiceMock } from 'src/__mocks__/services/user.service.mock';
import { DashboardDialogInvitationsComponent } from './components/dashboard-dialog-invites/dashboard-dialog-invitations.component';
import { DashboardComponent } from './dashboard.component';

describe('DashboardComponent', () => {
let component: DashboardComponent;
let fixture: ComponentFixture<DashboardComponent>;

beforeEach(async () => {
await TestBed.configureTestingModule({
imports: [DashboardComponent],
providers: [{ provide: UserService, useValue: UserServiceMock }],
}).compileComponents();
beforeEach(() => {
TestBed.overrideComponent(DashboardComponent, {
set: {
imports: [
CommonModule,
RouterLink,
ReactiveFormsModule,
AppCardComponent,
AppButtonComponent,
DashboardDialogInvitationsComponent,
AppHeaderComponentMock,
AppFooterComponentMock,
],
providers: [
{ provide: UserService, useClass: UserServiceMock },
{ provide: ActivatedRoute, useClass: ActivatedRouteMock },
{ provide: ToastAlertService, useClass: ToastAlertServiceMock },
{ provide: InvitationService, useClass: InvitationServiceMock },
],
},
});

fixture = TestBed.createComponent(DashboardComponent);
TestBed.inject(UserServiceMock);
component = fixture.componentInstance;
fixture.detectChanges();
});
Expand Down
4 changes: 2 additions & 2 deletions frontend/src/app/features/dashboard/dashboard.component.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { CommonModule } from '@angular/common';
import { Component, effect, inject, signal } from '@angular/core';
import { ReactiveFormsModule } from '@angular/forms';
import { RouterModule } from '@angular/router';
import { RouterLink } from '@angular/router';
import { ProjectForUser, User } from '@core/interfaces/user.interface';
import { UserService } from '@core/services/user/user.service';
import { ResponseGetProjectsForUser } from '@core/services/user/user.service.types';
Expand All @@ -18,7 +18,7 @@ import { DashboardDialogInvitationsComponent } from './components/dashboard-dial
standalone: true,
imports: [
CommonModule,
RouterModule,
RouterLink,
ReactiveFormsModule,
AppHeaderComponent,
AppFooterComponent,
Expand Down
20 changes: 16 additions & 4 deletions frontend/src/app/features/invitation/invitation.component.spec.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,27 @@
import { ComponentFixture, TestBed } from '@angular/core/testing';

import { AuthService } from '@core/services/auth/auth.service';
import { ToastAlertService } from '@core/services/toast-alert/toast-alert.service';
import { UserService } from '@core/services/user/user.service';
import { AuthServiceMock } from 'src/__mocks__/services/auth.service.mock';
import { ToastAlertServiceMock } from 'src/__mocks__/services/toast-alert.service.mock';
import { UserServiceMock } from 'src/__mocks__/services/user.service.mock';
import { InvitationComponent } from './invitation.component';

describe('InvitationComponent', () => {
let component: InvitationComponent;
let fixture: ComponentFixture<InvitationComponent>;

beforeEach(async () => {
await TestBed.configureTestingModule({
imports: [InvitationComponent],
}).compileComponents();
beforeEach(() => {
TestBed.overrideComponent(InvitationComponent, {
set: {
providers: [
{ provide: AuthService, useClass: AuthServiceMock },
{ provide: UserService, useClass: UserServiceMock },
{ provide: ToastAlertService, useClass: ToastAlertServiceMock },
],
},
});

fixture = TestBed.createComponent(InvitationComponent);
component = fixture.componentInstance;
Expand Down
25 changes: 20 additions & 5 deletions frontend/src/app/features/login/login.component.spec.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,31 @@
import { ComponentFixture, TestBed } from '@angular/core/testing';

import { FormBuilder } from '@angular/forms';
import { Router } from '@angular/router';
import { AuthService } from '@core/services/auth/auth.service';
import { ToastAlertService } from '@core/services/toast-alert/toast-alert.service';
import { UserService } from '@core/services/user/user.service';
import { AuthServiceMock } from 'src/__mocks__/services/auth.service.mock';
import { ToastAlertServiceMock } from 'src/__mocks__/services/toast-alert.service.mock';
import { UserServiceMock } from 'src/__mocks__/services/user.service.mock';
import { LoginComponent } from './login.component';

describe('LoginComponent', () => {
let component: LoginComponent;
let fixture: ComponentFixture<LoginComponent>;

beforeEach(async () => {
await TestBed.configureTestingModule({
imports: [LoginComponent]
})
.compileComponents();
beforeEach(() => {
TestBed.overrideComponent(LoginComponent, {
set: {
providers: [
FormBuilder,
Router,
{ provide: AuthService, useClass: AuthServiceMock },
{ provide: UserService, useClass: UserServiceMock },
{ provide: ToastAlertService, useClass: ToastAlertServiceMock },
],
},
});

fixture = TestBed.createComponent(LoginComponent);
component = fixture.componentInstance;
Expand Down
Loading

0 comments on commit 848d05d

Please sign in to comment.