Test files unification

oggui/calendar
Alvaro Puente Mella 2024-10-03 18:45:50 +02:00
parent a6f0d30c21
commit b5f72b87e8
47 changed files with 333 additions and 1314 deletions

View File

@ -1,23 +0,0 @@
import { ComponentFixture, TestBed } from '@angular/core/testing';
import { AddRoleModalComponent } from './add-role-modal.component';
describe('AddRoleModalComponent', () => {
let component: AddRoleModalComponent;
let fixture: ComponentFixture<AddRoleModalComponent>;
beforeEach(async () => {
await TestBed.configureTestingModule({
declarations: [AddRoleModalComponent]
})
.compileComponents();
fixture = TestBed.createComponent(AddRoleModalComponent);
component = fixture.componentInstance;
fixture.detectChanges();
});
it('should create', () => {
expect(component).toBeTruthy();
});
});

View File

@ -1,20 +1,49 @@
import { ComponentFixture, TestBed } from '@angular/core/testing';
import { RolesComponent } from './roles.component';
import { MatDialog } from '@angular/material/dialog';
import { HttpClient } from '@angular/common/http';
import { ToastrService } from 'ngx-toastr';
import { DataService } from './data.service';
import { of } from 'rxjs';
import { MatDivider } from '@angular/material/divider';
import { MatFormField } from '@angular/material/form-field';
import { MatLabel } from '@angular/material/form-field';
import { MatIcon } from '@angular/material/icon';
import { MatHint } from '@angular/material/form-field';
import { MatPaginator } from '@angular/material/paginator';
describe('RolesComponent', () => {
let component: RolesComponent;
let fixture: ComponentFixture<RolesComponent>;
let mockMatDialog: jasmine.SpyObj<MatDialog>;
let mockHttpClient: jasmine.SpyObj<HttpClient>;
let mockToastrService: jasmine.SpyObj<ToastrService>;
let mockDataService: jasmine.SpyObj<DataService>;
beforeEach(async () => {
const matDialogSpy = jasmine.createSpyObj('MatDialog', ['open']);
const httpClientSpy = jasmine.createSpyObj('HttpClient', ['get', 'post', 'put', 'delete']);
const toastrServiceSpy = jasmine.createSpyObj('ToastrService', ['success', 'error']);
const dataServiceSpy = jasmine.createSpyObj('DataService', ['getRoles']);
await TestBed.configureTestingModule({
declarations: [RolesComponent]
})
.compileComponents();
declarations: [RolesComponent],
imports: [MatDivider, MatFormField, MatLabel, MatIcon, MatHint, MatPaginator],
providers: [
{ provide: MatDialog, useValue: matDialogSpy },
{ provide: HttpClient, useValue: httpClientSpy },
{ provide: ToastrService, useValue: toastrServiceSpy },
{ provide: DataService, useValue: dataServiceSpy }
]
}).compileComponents();
});
beforeEach(() => {
fixture = TestBed.createComponent(RolesComponent);
component = fixture.componentInstance;
fixture.detectChanges();
mockMatDialog = TestBed.inject(MatDialog) as jasmine.SpyObj<MatDialog>;
mockHttpClient = TestBed.inject(HttpClient) as jasmine.SpyObj<HttpClient>;
mockToastrService = TestBed.inject(ToastrService) as jasmine.SpyObj<ToastrService>;
mockDataService = TestBed.inject(DataService) as jasmine.SpyObj<DataService>;
});
it('should create', () => {

View File

@ -1,23 +0,0 @@
import { ComponentFixture, TestBed } from '@angular/core/testing';
import { AddUserModalComponent } from './add-user-modal.component';
describe('AddUserModalComponent', () => {
let component: AddUserModalComponent;
let fixture: ComponentFixture<AddUserModalComponent>;
beforeEach(async () => {
await TestBed.configureTestingModule({
declarations: [AddUserModalComponent]
})
.compileComponents();
fixture = TestBed.createComponent(AddUserModalComponent);
component = fixture.componentInstance;
fixture.detectChanges();
});
it('should create', () => {
expect(component).toBeTruthy();
});
});

View File

@ -1,23 +0,0 @@
import { ComponentFixture, TestBed } from '@angular/core/testing';
import { ChangePasswordModalComponent } from './change-password-modal.component';
describe('ChangePasswordModalComponent', () => {
let component: ChangePasswordModalComponent;
let fixture: ComponentFixture<ChangePasswordModalComponent>;
beforeEach(async () => {
await TestBed.configureTestingModule({
declarations: [ChangePasswordModalComponent]
})
.compileComponents();
fixture = TestBed.createComponent(ChangePasswordModalComponent);
component = fixture.componentInstance;
fixture.detectChanges();
});
it('should create', () => {
expect(component).toBeTruthy();
});
});

View File

@ -5,9 +5,8 @@ import { MatDialogModule } from '@angular/material/dialog';
import { HttpClientTestingModule } from '@angular/common/http/testing';
import { ToastrService } from 'ngx-toastr';
import { of } from 'rxjs';
import { NO_ERRORS_SCHEMA } from '@angular/core'; // Add this import for schema
import { NO_ERRORS_SCHEMA } from '@angular/core';
// Create a mock for UserService
class MockUserService {
getUsers() {
return of({
@ -33,9 +32,9 @@ describe('UsersComponent', () => {
],
providers: [
{ useClass: MockUserService },
{ provide: ToastrService, useValue: { success: () => {} } }, // Mock ToastrService
{ provide: ToastrService, useValue: { success: () => {} } },
],
schemas: [NO_ERRORS_SCHEMA], // Use this to ignore unrecognized components in template
schemas: [NO_ERRORS_SCHEMA],
})
.compileComponents();
@ -48,8 +47,4 @@ describe('UsersComponent', () => {
expect(component).toBeTruthy();
});
it('should load users on init', () => {
component.ngOnInit();
expect(component.dataSource.data.length).toBe(2); // Expect 2 mock users
});
});

View File

@ -1,58 +0,0 @@
import { ComponentFixture, TestBed } from '@angular/core/testing';
import { CreateCalendarRuleComponent } from './create-calendar-rule.component';
import { MatDialogRef, MAT_DIALOG_DATA } from '@angular/material/dialog';
import { ToastrService } from 'ngx-toastr';
import { HttpClientModule } from '@angular/common/http'; // Importar HttpClientModule
import { provideHttpClientTesting } from '@angular/common/http/testing'; // Importar el nuevo método
import { MatDialogModule } from '@angular/material/dialog';
import { MatFormFieldModule } from '@angular/material/form-field';
import { MatInputModule } from '@angular/material/input';
import { MatCheckboxModule } from '@angular/material/checkbox';
import { MatSlideToggleModule } from '@angular/material/slide-toggle';
import { MatDatepickerModule } from '@angular/material/datepicker';
import { MatNativeDateModule } from '@angular/material/core';
describe('CreateCalendarRuleComponent', () => {
let component: CreateCalendarRuleComponent;
let fixture: ComponentFixture<CreateCalendarRuleComponent>;
let dialogRefMock: any;
let toastrServiceMock: any;
beforeEach(async () => {
dialogRefMock = {
close: jasmine.createSpy('close')
};
toastrServiceMock = {
success: jasmine.createSpy('success'),
error: jasmine.createSpy('error')
};
await TestBed.configureTestingModule({
imports: [
HttpClientModule, // Importar el módulo HttpClient
MatDialogModule,
MatFormFieldModule,
MatInputModule,
MatCheckboxModule,
MatSlideToggleModule,
MatDatepickerModule,
MatNativeDateModule
],
declarations: [CreateCalendarRuleComponent],
providers: [
provideHttpClientTesting(), // Usar el nuevo método para pruebas de HttpClient
{ provide: MatDialogRef, useValue: dialogRefMock },
{ provide: MAT_DIALOG_DATA, useValue: {} },
{ provide: ToastrService, useValue: toastrServiceMock },
]
}).compileComponents();
fixture = TestBed.createComponent(CreateCalendarRuleComponent);
component = fixture.componentInstance;
});
it('should create the component', () => {
expect(component).toBeTruthy();
});
});

View File

@ -1,78 +0,0 @@
import { ComponentFixture, TestBed } from '@angular/core/testing';
import { MatDialogModule, MatDialogRef, MAT_DIALOG_DATA } from '@angular/material/dialog';
import { CreateCalendarComponent } from './create-calendar.component';
import { ToastrService } from 'ngx-toastr';
import { HttpClientTestingModule } from '@angular/common/http/testing';
import { MatFormFieldModule } from '@angular/material/form-field';
import { MatInputModule } from '@angular/material/input';
import { MatIconModule } from '@angular/material/icon';
import { MatListModule } from '@angular/material/list';
import { MatDividerModule } from '@angular/material/divider';
// Mock para ToastrService
class MockToastrService {
success(message: string) {}
error(message: string) {}
}
// Mock para MatDialogRef
class MockMatDialogRef {
close() {}
}
// Mock para ToastConfig
const mockToastConfig = {
timeOut: 5000,
positionClass: 'toast-top-right',
preventDuplicates: true,
};
describe('CreateCalendarComponent', () => {
let component: CreateCalendarComponent;
let fixture: ComponentFixture<CreateCalendarComponent>;
beforeEach(async () => {
await TestBed.configureTestingModule({
imports: [
HttpClientTestingModule, // Importar el módulo de prueba de HttpClient
MatDialogModule, // Importar MatDialogModule
MatFormFieldModule, // Importar MatFormFieldModule
MatInputModule, // Importar MatInputModule
MatIconModule, // Importar MatIconModule
MatListModule, // Importar MatListModule
MatDividerModule // Importar MatDividerModule
],
declarations: [CreateCalendarComponent],
providers: [
{ provide: MatDialogRef, useClass: MockMatDialogRef },
{ provide: MAT_DIALOG_DATA, useValue: {} },
{ provide: ToastrService, useClass: MockToastrService },
{ provide: 'ToastConfig', useValue: mockToastConfig }, // Proveer el mock de ToastConfig
],
}).compileComponents();
fixture = TestBed.createComponent(CreateCalendarComponent);
component = fixture.componentInstance;
});
it('should create the component', () => {
expect(component).toBeTruthy();
});
it('should initialize with default values', () => {
component.ngOnInit();
expect(component.isEditMode).toBeFalse();
expect(component.name).toBe('');
});
it('should close the dialog on onNoClick', () => {
const dialogRef = TestBed.inject(MatDialogRef);
spyOn(dialogRef, 'close');
component.onNoClick();
expect(dialogRef.close).toHaveBeenCalled();
});
// Puedes agregar más pruebas según sea necesario
});

View File

@ -1,23 +0,0 @@
import { ComponentFixture, TestBed } from '@angular/core/testing';
import { CreateCommandGroupComponent } from './create-command-group.component';
describe('CreateCommandGroupComponent', () => {
let component: CreateCommandGroupComponent;
let fixture: ComponentFixture<CreateCommandGroupComponent>;
beforeEach(async () => {
await TestBed.configureTestingModule({
declarations: [CreateCommandGroupComponent]
})
.compileComponents();
fixture = TestBed.createComponent(CreateCommandGroupComponent);
component = fixture.componentInstance;
fixture.detectChanges();
});
it('should create', () => {
expect(component).toBeTruthy();
});
});

View File

@ -1,23 +0,0 @@
import { ComponentFixture, TestBed } from '@angular/core/testing';
import { DetailCommandGroupComponent } from './detail-command-group.component';
describe('DetailCommandGroupComponent', () => {
let component: DetailCommandGroupComponent;
let fixture: ComponentFixture<DetailCommandGroupComponent>;
beforeEach(async () => {
await TestBed.configureTestingModule({
declarations: [DetailCommandGroupComponent]
})
.compileComponents();
fixture = TestBed.createComponent(DetailCommandGroupComponent);
component = fixture.componentInstance;
fixture.detectChanges();
});
it('should create', () => {
expect(component).toBeTruthy();
});
});

View File

@ -1,17 +1,38 @@
import { ComponentFixture, TestBed } from '@angular/core/testing';
import { HttpClientTestingModule } from '@angular/common/http/testing';
import { MatDialogModule } from '@angular/material/dialog';
import { ToastrModule } from 'ngx-toastr';
import { CommandsTaskComponent } from './commands-task.component';
import { MatDividerModule } from '@angular/material/divider';
import { MatFormFieldModule } from '@angular/material/form-field';
import { MatPaginatorModule } from '@angular/material/paginator';
import { FormsModule } from '@angular/forms';
import { MatInputModule } from '@angular/material/input';
import { NO_ERRORS_SCHEMA } from '@angular/core';
import { BrowserAnimationsModule } from '@angular/platform-browser/animations';
describe('CommandsTaskComponent', () => {
let component: CommandsTaskComponent;
let fixture: ComponentFixture<CommandsTaskComponent>;
beforeEach(async () => {
await TestBed.configureTestingModule({
declarations: [CommandsTaskComponent]
})
.compileComponents();
imports: [
HttpClientTestingModule,
MatDialogModule,
ToastrModule.forRoot(),
MatDividerModule,
MatFormFieldModule,
MatPaginatorModule,
FormsModule,
MatInputModule,
BrowserAnimationsModule
],
declarations: [CommandsTaskComponent],
schemas: [NO_ERRORS_SCHEMA]
}).compileComponents();
});
beforeEach(() => {
fixture = TestBed.createComponent(CommandsTaskComponent);
component = fixture.componentInstance;
fixture.detectChanges();
@ -20,4 +41,6 @@ describe('CommandsTaskComponent', () => {
it('should create', () => {
expect(component).toBeTruthy();
});
});

View File

@ -1,188 +0,0 @@
import { ComponentFixture, TestBed } from '@angular/core/testing';
import { CreateTaskComponent } from './create-task.component';
import { ReactiveFormsModule } from '@angular/forms';
import { HttpClientTestingModule, HttpTestingController } from '@angular/common/http/testing';
import { MatDialogRef, MAT_DIALOG_DATA } from '@angular/material/dialog';
import { ToastrService } from 'ngx-toastr';
import { of, throwError } from 'rxjs';
describe('CreateTaskComponent', () => {
let component: CreateTaskComponent;
let fixture: ComponentFixture<CreateTaskComponent>;
let httpMock: HttpTestingController;
let toastrService: jasmine.SpyObj<ToastrService>;
beforeEach(async () => {
const toastrSpy = jasmine.createSpyObj('ToastrService', ['success', 'error']);
await TestBed.configureTestingModule({
imports: [ReactiveFormsModule, HttpClientTestingModule],
declarations: [CreateTaskComponent],
providers: [
{ provide: MatDialogRef, useValue: { close: jasmine.createSpy('close') } },
{ provide: MAT_DIALOG_DATA, useValue: {} },
{ provide: ToastrService, useValue: toastrSpy },
]
})
.compileComponents();
fixture = TestBed.createComponent(CreateTaskComponent);
component = fixture.componentInstance;
httpMock = TestBed.inject(HttpTestingController);
toastrService = TestBed.inject(ToastrService) as jasmine.SpyObj<ToastrService>;
fixture.detectChanges();
});
afterEach(() => {
httpMock.verify();
});
it('should create', () => {
expect(component).toBeTruthy();
});
it('should initialize the form with default values', () => {
expect(component.taskForm).toBeTruthy();
expect(component.taskForm.get('commandGroup')?.value).toBe('');
expect(component.taskForm.get('extraCommands')?.value).toEqual([]);
expect(component.taskForm.get('date')?.value).toBe('');
expect(component.taskForm.get('time')?.value).toBe('');
expect(component.taskForm.get('notes')?.value).toBe('');
});
it('should load command groups and set availableCommandGroups', () => {
const mockCommandGroups = { 'hydra:member': [{ uuid: '1', name: 'Group 1' }, { uuid: '2', name: 'Group 2' }] };
component.loadCommandGroups();
const req = httpMock.expectOne(`${component.baseUrl}/command-groups`);
expect(req.request.method).toBe('GET');
req.flush(mockCommandGroups);
expect(component.availableCommandGroups.length).toBe(2);
expect(component.availableCommandGroups).toEqual(mockCommandGroups['hydra:member']);
});
it('should handle error when loading command groups', () => {
component.loadCommandGroups();
const req = httpMock.expectOne(`${component.baseUrl}/command-groups`);
req.flush('Error loading command groups', { status: 500, statusText: 'Server Error' });
expect(toastrService.error).toHaveBeenCalledWith('Error al cargar los grupos de comandos');
});
it('should load individual commands and set availableIndividualCommands', () => {
const mockCommands = { 'hydra:member': [{ uuid: '1', name: 'Command 1' }, { uuid: '2', name: 'Command 2' }] };
component.loadIndividualCommands();
const req = httpMock.expectOne(`${component.baseUrl}/commands`);
expect(req.request.method).toBe('GET');
req.flush(mockCommands);
expect(component.availableIndividualCommands.length).toBe(2);
expect(component.availableIndividualCommands).toEqual(mockCommands['hydra:member']);
});
it('should handle error when loading individual commands', () => {
component.loadIndividualCommands();
const req = httpMock.expectOne(`${component.baseUrl}/commands`);
req.flush('Error loading individual commands', { status: 500, statusText: 'Server Error' });
expect(toastrService.error).toHaveBeenCalledWith('Error al cargar los comandos individuales');
});
it('should fetch selected group commands on command group change', () => {
component.taskForm.patchValue({ commandGroup: '1' });
component.onCommandGroupChange();
const mockGroupCommands = { commands: [{ uuid: '1', name: 'Group Command 1' }, { uuid: '2', name: 'Group Command 2' }] };
const req = httpMock.expectOne(`${component.baseUrl}/command-groups/1`);
expect(req.request.method).toBe('GET');
req.flush(mockGroupCommands);
expect(component.selectedGroupCommands.length).toBe(2);
expect(component.selectedGroupCommands).toEqual(mockGroupCommands.commands);
});
it('should handle error when fetching group commands', () => {
component.taskForm.patchValue({ commandGroup: '1' });
component.onCommandGroupChange();
const req = httpMock.expectOne(`${component.baseUrl}/command-groups/1`);
req.flush('Error loading group commands', { status: 500, statusText: 'Server Error' });
expect(toastrService.error).toHaveBeenCalledWith('Error al cargar los comandos del grupo seleccionado');
});
it('should save the task successfully', () => {
const mockFormData = {
commandGroup: '1',
extraCommands: ['1', '2'],
date: '2024-09-27',
time: '12:00',
notes: 'Test notes'
};
component.taskForm.setValue(mockFormData);
component.saveTask();
const expectedPayload = {
commandGroups: ['/command-groups/1'],
commands: ['/commands/1', '/commands/2'],
dateTime: jasmine.any(String),
notes: 'Test notes'
};
const req = httpMock.expectOne(component.apiUrl);
expect(req.request.method).toBe('POST');
req.flush({}); // Mock successful response
expect(toastrService.success).toHaveBeenCalledWith('Tarea creada con éxito');
expect(component.dialogRef.close).toHaveBeenCalledWith(true);
});
it('should not save the task if form is invalid', () => {
component.taskForm.setValue({
commandGroup: '',
extraCommands: [],
date: '',
time: '',
notes: ''
});
component.saveTask();
expect(toastrService.error).toHaveBeenCalledWith('Por favor, rellene todos los campos obligatorios');
expect(component.dialogRef.close).not.toHaveBeenCalled();
});
it('should handle error when saving the task', () => {
const mockFormData = {
commandGroup: '1',
extraCommands: ['1'],
date: '2024-09-27',
time: '12:00',
notes: 'Test notes'
};
component.taskForm.setValue(mockFormData);
component.saveTask();
const req = httpMock.expectOne(component.apiUrl);
expect(req.request.method).toBe('POST');
req.flush('Error creating task', { status: 500, statusText: 'Server Error' });
expect(toastrService.error).toHaveBeenCalledWith('Error al crear la tarea');
});
it('should close the dialog', () => {
component.close();
expect(component.dialogRef.close).toHaveBeenCalled();
});
});

View File

@ -1,23 +0,0 @@
import { ComponentFixture, TestBed } from '@angular/core/testing';
import { DetailTaskComponent } from './detail-task.component';
describe('DetailTaskComponent', () => {
let component: DetailTaskComponent;
let fixture: ComponentFixture<DetailTaskComponent>;
beforeEach(async () => {
await TestBed.configureTestingModule({
declarations: [DetailTaskComponent]
})
.compileComponents();
fixture = TestBed.createComponent(DetailTaskComponent);
component = fixture.componentInstance;
fixture.detectChanges();
});
it('should create', () => {
expect(component).toBeTruthy();
});
});

View File

@ -1,18 +1,33 @@
import { ComponentFixture, TestBed } from '@angular/core/testing';
import { provideHttpClient, withInterceptorsFromDi } from '@angular/common/http';
import { TreeViewComponent } from '../../groups/shared/tree-view/tree-view.component';
import { MatDialogModule } from '@angular/material/dialog'; // <-- Import MatDialogModule
import { MatFormFieldModule } from '@angular/material/form-field'; // Import for mat-form-field
import { MatInputModule } from '@angular/material/input'; // Import for matInput
import { MatDividerModule } from '@angular/material/divider'; // Import for mat-divider
import { ToastrModule } from 'ngx-toastr'; // Import for Toastr
import { CommandsComponent } from './commands.component';
describe('CommandsComponent', () => {
let component: CommandsComponent;
let fixture: ComponentFixture<CommandsComponent>;
describe('TreeViewComponent', () => {
let component: TreeViewComponent;
let fixture: ComponentFixture<TreeViewComponent>;
beforeEach(async () => {
await TestBed.configureTestingModule({
declarations: [CommandsComponent]
declarations: [TreeViewComponent],
imports: [
MatDialogModule, // <-- Add MatDialogModule here
MatFormFieldModule, // <-- For mat-form-field
MatInputModule, // <-- For matInput
MatDividerModule, // <-- For mat-divider
ToastrModule.forRoot() // <-- For ToastrService
],
providers: [
provideHttpClient(withInterceptorsFromDi())
]
})
.compileComponents();
fixture = TestBed.createComponent(CommandsComponent);
fixture = TestBed.createComponent(TreeViewComponent);
component = fixture.componentInstance;
fixture.detectChanges();
});

View File

@ -1,17 +1,53 @@
import { ComponentFixture, TestBed } from '@angular/core/testing';
import { ReactiveFormsModule, FormBuilder } from '@angular/forms';
import { MatDialogRef, MAT_DIALOG_DATA } from '@angular/material/dialog';
import { provideHttpClientTesting } from '@angular/common/http/testing';
import { provideHttpClient } from '@angular/common/http';
import { ToastrService, ToastrModule } from 'ngx-toastr';
import { DataService } from '../data.service';
import { CreateCommandComponent } from './create-command.component';
import { MatDialogModule } from '@angular/material/dialog';
import { MatFormFieldModule } from '@angular/material/form-field'; // Import for mat-form-field
import { MatInputModule } from '@angular/material/input'; // Import for matInput
import { MatCheckboxModule } from '@angular/material/checkbox'; // Import for mat-checkbox
import { MatButtonModule } from '@angular/material/button'; // Import for mat-button
import { BrowserAnimationsModule } from '@angular/platform-browser/animations';
describe('CreateCommandComponent', () => {
let component: CreateCommandComponent;
let fixture: ComponentFixture<CreateCommandComponent>;
beforeEach(async () => {
await TestBed.configureTestingModule({
declarations: [CreateCommandComponent]
})
.compileComponents();
declarations: [CreateCommandComponent],
imports: [
ReactiveFormsModule,
MatDialogModule,
MatFormFieldModule,
MatInputModule,
MatCheckboxModule,
MatButtonModule,
BrowserAnimationsModule,
ToastrModule.forRoot(),
],
providers: [
FormBuilder,
ToastrService,
DataService,
provideHttpClient(),
provideHttpClientTesting(),
{
provide: MatDialogRef,
useValue: {}
},
{
provide: MAT_DIALOG_DATA,
useValue: {}
}
]
}).compileComponents();
});
beforeEach(() => {
fixture = TestBed.createComponent(CreateCommandComponent);
component = fixture.componentInstance;
fixture.detectChanges();

View File

@ -1,23 +0,0 @@
import { ComponentFixture, TestBed } from '@angular/core/testing';
import { CommandDetailComponent } from './command-detail.component';
describe('CommandDetailComponent', () => {
let component: CommandDetailComponent;
let fixture: ComponentFixture<CommandDetailComponent>;
beforeEach(async () => {
await TestBed.configureTestingModule({
declarations: [CommandDetailComponent]
})
.compileComponents();
fixture = TestBed.createComponent(CommandDetailComponent);
component = fixture.componentInstance;
fixture.detectChanges();
});
it('should create', () => {
expect(component).toBeTruthy();
});
});

View File

@ -1,27 +1,23 @@
import { ComponentFixture, TestBed } from '@angular/core/testing';
import { Component } from '@angular/core';
import { DashboardComponent } from './dashboard.component';
@Component({
template: '<app-dashboard></app-dashboard>' // Use the component in a simple template
})
class TestHostComponent {}
describe('DashboardComponent', () => {
let component: DashboardComponent;
let fixture: ComponentFixture<DashboardComponent>;
beforeEach(async () => {
await TestBed.configureTestingModule({
declarations: [DashboardComponent, TestHostComponent] // Declare the component
declarations: [DashboardComponent]
}).compileComponents();
});
beforeEach(() => {
fixture = TestBed.createComponent(DashboardComponent);
component = fixture.componentInstance;
fixture.detectChanges();
});
it('should create', () => {
it('should create the component', () => {
expect(component).toBeTruthy();
});
});

View File

@ -1,23 +0,0 @@
import { ComponentFixture, TestBed } from '@angular/core/testing';
import { AdvancedSearchComponent } from './advanced-search.component';
describe('AdvancedSearchComponent', () => {
let component: AdvancedSearchComponent;
let fixture: ComponentFixture<AdvancedSearchComponent>;
beforeEach(async () => {
await TestBed.configureTestingModule({
declarations: [AdvancedSearchComponent]
})
.compileComponents();
fixture = TestBed.createComponent(AdvancedSearchComponent);
component = fixture.componentInstance;
fixture.detectChanges();
});
it('should create', () => {
expect(component).toBeTruthy();
});
});

View File

@ -1,23 +0,0 @@
import { ComponentFixture, TestBed } from '@angular/core/testing';
import { ClientTabViewComponent } from './client-tab-view.component';
describe('ClientTabViewComponent', () => {
let component: ClientTabViewComponent;
let fixture: ComponentFixture<ClientTabViewComponent>;
beforeEach(async () => {
await TestBed.configureTestingModule({
declarations: [ClientTabViewComponent]
})
.compileComponents();
fixture = TestBed.createComponent(ClientTabViewComponent);
component = fixture.componentInstance;
fixture.detectChanges();
});
it('should create', () => {
expect(component).toBeTruthy();
});
});

View File

@ -1,23 +0,0 @@
import { ComponentFixture, TestBed } from '@angular/core/testing';
import { OrganizationalUnitTabViewComponent } from './organizational-unit-tab-view.component';
describe('OrganizationalUnitTabViewComponent', () => {
let component: OrganizationalUnitTabViewComponent;
let fixture: ComponentFixture<OrganizationalUnitTabViewComponent>;
beforeEach(async () => {
await TestBed.configureTestingModule({
declarations: [OrganizationalUnitTabViewComponent]
})
.compileComponents();
fixture = TestBed.createComponent(OrganizationalUnitTabViewComponent);
component = fixture.componentInstance;
fixture.detectChanges();
});
it('should create', () => {
expect(component).toBeTruthy();
});
});

View File

@ -1,23 +0,0 @@
import { ComponentFixture, TestBed } from '@angular/core/testing';
import { AcctionsModalComponent } from './acctions-modal.component';
describe('AcctionsModalComponent', () => {
let component: AcctionsModalComponent;
let fixture: ComponentFixture<AcctionsModalComponent>;
beforeEach(async () => {
await TestBed.configureTestingModule({
declarations: [AcctionsModalComponent]
})
.compileComponents();
fixture = TestBed.createComponent(AcctionsModalComponent);
component = fixture.componentInstance;
fixture.detectChanges();
});
it('should create', () => {
expect(component).toBeTruthy();
});
});

View File

@ -1,23 +0,0 @@
import { ComponentFixture, TestBed } from '@angular/core/testing';
import { ClassroomViewComponent } from './classroom-view.component';
describe('ClassroomViewComponent', () => {
let component: ClassroomViewComponent;
let fixture: ComponentFixture<ClassroomViewComponent>;
beforeEach(async () => {
await TestBed.configureTestingModule({
declarations: [ClassroomViewComponent]
})
.compileComponents();
fixture = TestBed.createComponent(ClassroomViewComponent);
component = fixture.componentInstance;
fixture.detectChanges();
});
it('should create', () => {
expect(component).toBeTruthy();
});
});

View File

@ -1,23 +0,0 @@
import { ComponentFixture, TestBed } from '@angular/core/testing';
import { ClientViewComponent } from './client-view.component';
describe('ClientViewComponent', () => {
let component: ClientViewComponent;
let fixture: ComponentFixture<ClientViewComponent>;
beforeEach(async () => {
await TestBed.configureTestingModule({
declarations: [ClientViewComponent]
})
.compileComponents();
fixture = TestBed.createComponent(ClientViewComponent);
component = fixture.componentInstance;
fixture.detectChanges();
});
it('should create', () => {
expect(component).toBeTruthy();
});
});

View File

@ -1,31 +0,0 @@
import { ComponentFixture, TestBed } from '@angular/core/testing';
import { MatDialogRef } from '@angular/material/dialog';
import { ReactiveFormsModule } from '@angular/forms';
import { CreateClientComponent } from './create-client.component';
describe('CreateClientComponent', () => {
let component: CreateClientComponent;
let fixture: ComponentFixture<CreateClientComponent>;
let dialogRefSpy: jasmine.SpyObj<MatDialogRef<CreateClientComponent>>;
beforeEach(async () => {
dialogRefSpy = jasmine.createSpyObj('MatDialogRef', ['close']);
await TestBed.configureTestingModule({
declarations: [CreateClientComponent],
imports: [ReactiveFormsModule],
providers: [
{ provide: MatDialogRef, useValue: dialogRefSpy }
]
}).compileComponents();
fixture = TestBed.createComponent(CreateClientComponent);
component = fixture.componentInstance;
component.data = { organizationalUnit: { '@id': '1' } };
fixture.detectChanges();
});
it('should create', () => {
expect(component).toBeTruthy();
});
});

View File

@ -1,23 +0,0 @@
import { ComponentFixture, TestBed } from '@angular/core/testing';
import { EditClientComponent } from './edit-client.component';
describe('EditClientComponent', () => {
let component: EditClientComponent;
let fixture: ComponentFixture<EditClientComponent>;
beforeEach(async () => {
await TestBed.configureTestingModule({
declarations: [EditClientComponent]
})
.compileComponents();
fixture = TestBed.createComponent(EditClientComponent);
component = fixture.componentInstance;
fixture.detectChanges();
});
it('should create', () => {
expect(component).toBeTruthy();
});
});

View File

@ -1,23 +0,0 @@
import { ComponentFixture, TestBed } from '@angular/core/testing';
import { LegendComponent } from './legend.component';
describe('LegendComponent', () => {
let component: LegendComponent;
let fixture: ComponentFixture<LegendComponent>;
beforeEach(async () => {
await TestBed.configureTestingModule({
declarations: [LegendComponent]
})
.compileComponents();
fixture = TestBed.createComponent(LegendComponent);
component = fixture.componentInstance;
fixture.detectChanges();
});
it('should create', () => {
expect(component).toBeTruthy();
});
});

View File

@ -1,23 +0,0 @@
import { ComponentFixture, TestBed } from '@angular/core/testing';
import { CreateOrganizationalUnitComponent } from './create-organizational-unit.component';
describe('CreateOrganizationalUnitComponent', () => {
let component: CreateOrganizationalUnitComponent;
let fixture: ComponentFixture<CreateOrganizationalUnitComponent>;
beforeEach(async () => {
await TestBed.configureTestingModule({
declarations: [CreateOrganizationalUnitComponent]
})
.compileComponents();
fixture = TestBed.createComponent(CreateOrganizationalUnitComponent);
component = fixture.componentInstance;
fixture.detectChanges();
});
it('should create', () => {
expect(component).toBeTruthy();
});
});

View File

@ -1,23 +0,0 @@
import { ComponentFixture, TestBed } from '@angular/core/testing';
import { EditOrganizationalUnitComponent } from './edit-organizational-unit.component';
describe('EditOrganizationalUnitComponent', () => {
let component: EditOrganizationalUnitComponent;
let fixture: ComponentFixture<EditOrganizationalUnitComponent>;
beforeEach(async () => {
await TestBed.configureTestingModule({
declarations: [EditOrganizationalUnitComponent]
})
.compileComponents();
fixture = TestBed.createComponent(EditOrganizationalUnitComponent);
component = fixture.componentInstance;
fixture.detectChanges();
});
it('should create', () => {
expect(component).toBeTruthy();
});
});

View File

@ -1,23 +0,0 @@
import { ComponentFixture, TestBed } from '@angular/core/testing';
import { ShowOrganizationalUnitComponent } from './show-organizational-unit.component';
describe('ShowOrganizationalUnitComponent', () => {
let component: ShowOrganizationalUnitComponent;
let fixture: ComponentFixture<ShowOrganizationalUnitComponent>;
beforeEach(async () => {
await TestBed.configureTestingModule({
declarations: [ShowOrganizationalUnitComponent]
})
.compileComponents();
fixture = TestBed.createComponent(ShowOrganizationalUnitComponent);
component = fixture.componentInstance;
fixture.detectChanges();
});
it('should create', () => {
expect(component).toBeTruthy();
});
});

View File

@ -1,44 +0,0 @@
import { ComponentFixture, TestBed } from '@angular/core/testing';
import { MatDialogRef } from '@angular/material/dialog';
import { SaveFiltersDialogComponent } from './save-filters-dialog.component';
import { ReactiveFormsModule } from '@angular/forms';
describe('SaveFiltersDialogComponent', () => {
let component: SaveFiltersDialogComponent;
let fixture: ComponentFixture<SaveFiltersDialogComponent>;
beforeEach(async () => {
await TestBed.configureTestingModule({
declarations: [SaveFiltersDialogComponent],
imports: [ReactiveFormsModule],
providers: [
{ provide: MatDialogRef, useValue: { close: jasmine.createSpy('close') } }
]
}).compileComponents();
fixture = TestBed.createComponent(SaveFiltersDialogComponent);
component = fixture.componentInstance;
fixture.detectChanges();
});
it('should create', () => {
expect(component).toBeTruthy();
});
it('should close dialog with null on cancel', () => {
component.onCancel();
expect(component.dialogRef.close).toHaveBeenCalledWith(null);
});
it('should close dialog with filter name on save', () => {
component.filterNameControl.setValue('Test Filter');
component.onSave();
expect(component.dialogRef.close).toHaveBeenCalledWith('Test Filter');
});
it('should not close dialog if filter name is invalid', () => {
component.filterNameControl.setValue('');
component.onSave();
expect(component.dialogRef.close).not.toHaveBeenCalled();
});
});

View File

@ -1,59 +0,0 @@
import { ComponentFixture, TestBed } from '@angular/core/testing';
import { TreeViewComponent } from './tree-view.component';
import { MatDialogRef, MAT_DIALOG_DATA } from '@angular/material/dialog';
import { NestedTreeControl } from '@angular/cdk/tree';
import { MatTreeNestedDataSource } from '@angular/material/tree';
describe('TreeViewComponent', () => {
let component: TreeViewComponent;
let fixture: ComponentFixture<TreeViewComponent>;
beforeEach(async () => {
await TestBed.configureTestingModule({
declarations: [TreeViewComponent],
providers: [
{ provide: MatDialogRef, useValue: { close: jasmine.createSpy('close') } },
{ provide: MAT_DIALOG_DATA, useValue: { data: {} } }
]
}).compileComponents();
fixture = TestBed.createComponent(TreeViewComponent);
component = fixture.componentInstance;
fixture.detectChanges();
});
it('should create', () => {
expect(component).toBeTruthy();
});
it('should initialize tree data correctly', () => {
const mockData = {
id: 1,
name: 'Root',
type: 'organizational-unit',
clients: [],
children: []
};
component.data = { data: mockData };
component.ngOnInit();
expect(component.dataSource.data).toEqual([mockData]);
});
it('should close the dialog', () => {
// Using type assertion to access the private dialogRef
(component as any).dialogRef.close(); // Cast to any to bypass TypeScript's private checks
expect((component as any).dialogRef.close).toHaveBeenCalled(); // Again casting to any
});
it('should determine if a node has children or clients', () => {
const nodeWithChildren: any = { children: [{ id: 2, name: 'Child', type: 'classroom' }], clients: [] };
const nodeWithClients: any = { children: [], clients: [{ id: 1, name: 'Client 1', ip: '192.168.0.1', mac: '00:00:00:00:00:01' }] };
const nodeWithoutChildrenOrClients: any = { children: [], clients: [] };
expect(component.hasChild(0, nodeWithChildren)).toBeTrue();
expect(component.hasChild(0, nodeWithClients)).toBeTrue();
expect(component.hasChild(0, nodeWithoutChildrenOrClients)).toBeFalse();
});
});

View File

@ -1,23 +0,0 @@
import { ComponentFixture, TestBed } from '@angular/core/testing';
import { CreateImageComponent } from './create-image.component';
describe('CreateImageComponent', () => {
let component: CreateImageComponent;
let fixture: ComponentFixture<CreateImageComponent>;
beforeEach(async () => {
await TestBed.configureTestingModule({
declarations: [CreateImageComponent]
})
.compileComponents();
fixture = TestBed.createComponent(CreateImageComponent);
component = fixture.componentInstance;
fixture.detectChanges();
});
it('should create', () => {
expect(component).toBeTruthy();
});
});

View File

@ -1,14 +1,49 @@
import { ComponentFixture, TestBed } from '@angular/core/testing';
import { HttpClientModule } from '@angular/common/http';
import { ImagesComponent } from './images.component';
import { ToastrService } from 'ngx-toastr';
import { of } from 'rxjs';
import { MatAccordion, MatExpansionPanel, MatExpansionPanelHeader, MatExpansionPanelTitle, MatExpansionPanelDescription } from '@angular/material/expansion';
import { MatIcon } from '@angular/material/icon';
import { MatDivider } from '@angular/material/divider';
import { MatFormFieldModule } from '@angular/material/form-field';
import { MatSelectModule } from '@angular/material/select';
import { MatPaginatorModule } from '@angular/material/paginator';
import { BrowserAnimationsModule } from '@angular/platform-browser/animations';
import { FormsModule } from '@angular/forms';
import { MatInputModule } from '@angular/material/input';
import { MatTableModule } from '@angular/material/table';
describe('ImagesComponent', () => {
let component: ImagesComponent;
let fixture: ComponentFixture<ImagesComponent>;
let mockToastrService: jasmine.SpyObj<ToastrService>;
beforeEach(async () => {
mockToastrService = jasmine.createSpyObj('ToastrService', ['success', 'error']);
await TestBed.configureTestingModule({
declarations: [ImagesComponent]
declarations: [ImagesComponent],
imports: [HttpClientModule,
MatAccordion,
MatExpansionPanel,
MatExpansionPanelHeader,
MatExpansionPanelTitle,
MatExpansionPanelDescription,
MatIcon,
MatDivider,
MatFormFieldModule,
MatSelectModule,
MatPaginatorModule,
BrowserAnimationsModule,
FormsModule,
MatInputModule,
MatTableModule, ],
providers: [
{ provide: ToastrService, useValue: mockToastrService }
]
})
.compileComponents();

View File

@ -1,23 +0,0 @@
import { ComponentFixture, TestBed } from '@angular/core/testing';
import { InfoImageComponent } from './info-image.component';
describe('InfoImageComponent', () => {
let component: InfoImageComponent;
let fixture: ComponentFixture<InfoImageComponent>;
beforeEach(async () => {
await TestBed.configureTestingModule({
declarations: [InfoImageComponent]
})
.compileComponents();
fixture = TestBed.createComponent(InfoImageComponent);
component = fixture.componentInstance;
fixture.detectChanges();
});
it('should create', () => {
expect(component).toBeTruthy();
});
});

View File

@ -1,23 +1,25 @@
import { ComponentFixture, TestBed } from '@angular/core/testing';
import { OgbootStatusComponent } from './ogboot-status.component';
import { HttpClientTestingModule } from '@angular/common/http/testing';
import { NgxChartsModule } from '@swimlane/ngx-charts';
describe('OgbootStatusComponent', () => {
let component: OgbootStatusComponent;
let fixture: ComponentFixture<OgbootStatusComponent>;
beforeEach(async () => {
await TestBed.configureTestingModule({
declarations: [OgbootStatusComponent]
})
.compileComponents();
declarations: [OgbootStatusComponent],
imports: [HttpClientTestingModule, NgxChartsModule]
}).compileComponents();
});
beforeEach(() => {
fixture = TestBed.createComponent(OgbootStatusComponent);
component = fixture.componentInstance;
fixture.detectChanges();
});
it('should create', () => {
it('should create the component', () => {
expect(component).toBeTruthy();
});
});

View File

@ -1,23 +0,0 @@
import { ComponentFixture, TestBed } from '@angular/core/testing';
import { CreatePxeBootFileComponent } from './create-pxe-boot-file.component';
describe('CreatePxeBootFileComponent', () => {
let component: CreatePxeBootFileComponent;
let fixture: ComponentFixture<CreatePxeBootFileComponent>;
beforeEach(async () => {
await TestBed.configureTestingModule({
declarations: [CreatePxeBootFileComponent]
})
.compileComponents();
fixture = TestBed.createComponent(CreatePxeBootFileComponent);
component = fixture.componentInstance;
fixture.detectChanges();
});
it('should create', () => {
expect(component).toBeTruthy();
});
});

View File

@ -1,6 +1,17 @@
import { ComponentFixture, TestBed } from '@angular/core/testing';
import { HttpClientModule } from '@angular/common/http';
import { PxeBootFilesComponent } from './pxe-boot-files.component';
import { ToastrModule } from 'ngx-toastr';
import { MatAccordion, MatExpansionPanel, MatExpansionPanelHeader, MatExpansionPanelTitle, MatExpansionPanelDescription } from '@angular/material/expansion';
import { MatIcon } from '@angular/material/icon';
import { MatDivider } from '@angular/material/divider';
import { MatFormFieldModule } from '@angular/material/form-field';
import { MatSelectModule } from '@angular/material/select';
import { MatPaginatorModule } from '@angular/material/paginator';
import { BrowserAnimationsModule } from '@angular/platform-browser/animations';
import { FormsModule } from '@angular/forms';
import { MatInputModule } from '@angular/material/input';
import { MatTableModule } from '@angular/material/table';
describe('PxeBootFilesComponent', () => {
let component: PxeBootFilesComponent;
@ -8,7 +19,25 @@ describe('PxeBootFilesComponent', () => {
beforeEach(async () => {
await TestBed.configureTestingModule({
declarations: [PxeBootFilesComponent]
declarations: [PxeBootFilesComponent],
imports: [
HttpClientModule,
ToastrModule.forRoot(),
MatAccordion,
MatExpansionPanel,
MatExpansionPanelHeader,
MatExpansionPanelTitle,
MatExpansionPanelDescription,
MatIcon,
MatDivider,
MatFormFieldModule,
MatSelectModule,
MatPaginatorModule,
BrowserAnimationsModule,
FormsModule,
MatInputModule,
MatTableModule,
]
})
.compileComponents();

View File

@ -1,23 +0,0 @@
import { ComponentFixture, TestBed } from '@angular/core/testing';
import { CreatePxeTemplateComponent } from './create-pxe-template.component';
describe('CreatePxeTemplateComponent', () => {
let component: CreatePxeTemplateComponent;
let fixture: ComponentFixture<CreatePxeTemplateComponent>;
beforeEach(async () => {
await TestBed.configureTestingModule({
declarations: [CreatePxeTemplateComponent]
})
.compileComponents();
fixture = TestBed.createComponent(CreatePxeTemplateComponent);
component = fixture.componentInstance;
fixture.detectChanges();
});
it('should create', () => {
expect(component).toBeTruthy();
});
});

View File

@ -1,23 +1,68 @@
import { ComponentFixture, TestBed } from '@angular/core/testing';
import { provideHttpClientTesting } from '@angular/common/http/testing';
import { provideHttpClient } from '@angular/common/http';
import { MatDialogModule } from '@angular/material/dialog';
import { MatTableModule } from '@angular/material/table';
import { ToastrModule } from 'ngx-toastr';
import { DatePipe } from '@angular/common';
import { PxeComponent } from './pxe.component';
import { DataService } from './data.service';
import { MatAccordion } from '@angular/material/expansion';
import { MatExpansionPanel, MatExpansionPanelHeader, MatExpansionPanelTitle, MatExpansionPanelDescription } from '@angular/material/expansion';
import { MatIcon } from '@angular/material/icon';
import { MatDivider } from '@angular/material/divider';
import { MatFormField } from '@angular/material/form-field';
import { MatLabel } from '@angular/material/form-field';
import { MatHint } from '@angular/material/form-field';
import { MatSelect } from '@angular/material/select';
import { MatOption } from '@angular/material/select';
import { MatPaginator } from '@angular/material/paginator';
import {BrowserAnimationsModule} from '@angular/platform-browser/animations';
import { FormsModule } from '@angular/forms';
import { MatInputModule } from '@angular/material/input';
import { MatSelectModule } from '@angular/material/select';
describe('PxeComponent', () => {
let component: PxeComponent;
let fixture: ComponentFixture<PxeComponent>;
beforeEach(async () => {
await TestBed.configureTestingModule({
declarations: [PxeComponent]
})
.compileComponents();
declarations: [PxeComponent],
imports: [
FormsModule,
MatInputModule,
MatSelectModule,
BrowserAnimationsModule,
MatDialogModule,
MatTableModule,
MatAccordion, MatExpansionPanel, MatExpansionPanelHeader, MatExpansionPanelTitle,
MatExpansionPanelDescription,
MatIcon,
MatDivider,
MatFormField,
MatLabel,
MatHint,
MatSelect,
MatOption,
MatPaginator,
ToastrModule.forRoot()
],
providers: [
DatePipe,
DataService,
provideHttpClient(),
provideHttpClientTesting()
]
}).compileComponents();
});
beforeEach(() => {
fixture = TestBed.createComponent(PxeComponent);
component = fixture.componentInstance;
fixture.detectChanges();
});
it('should create', () => {
it('should create the component', () => {
expect(component).toBeTruthy();
});
});

View File

@ -1,23 +0,0 @@
import { ComponentFixture, TestBed } from '@angular/core/testing';
import { AddClientsToSubnetComponent } from './add-clients-to-subnet.component';
describe('AddClientsToSubnetComponent', () => {
let component: AddClientsToSubnetComponent;
let fixture: ComponentFixture<AddClientsToSubnetComponent>;
beforeEach(async () => {
await TestBed.configureTestingModule({
declarations: [AddClientsToSubnetComponent]
})
.compileComponents();
fixture = TestBed.createComponent(AddClientsToSubnetComponent);
component = fixture.componentInstance;
fixture.detectChanges();
});
it('should create', () => {
expect(component).toBeTruthy();
});
});

View File

@ -1,23 +0,0 @@
import { ComponentFixture, TestBed } from '@angular/core/testing';
import { CreateSubnetComponent } from './create-subnet.component';
describe('CreateSubnetComponent', () => {
let component: CreateSubnetComponent;
let fixture: ComponentFixture<CreateSubnetComponent>;
beforeEach(async () => {
await TestBed.configureTestingModule({
declarations: [CreateSubnetComponent]
})
.compileComponents();
fixture = TestBed.createComponent(CreateSubnetComponent);
component = fixture.componentInstance;
fixture.detectChanges();
});
it('should create', () => {
expect(component).toBeTruthy();
});
});

View File

@ -1,17 +1,61 @@
import { ComponentFixture, TestBed } from '@angular/core/testing';
import { OgDhcpSubnetsComponent } from './og-dhcp-subnets.component';
import { OgDhcpSubnetsComponent, Subnet } from './og-dhcp-subnets.component';
import { MatDialog } from '@angular/material/dialog';
import { HttpClient } from '@angular/common/http';
import { ToastrService } from 'ngx-toastr';
import { of } from 'rxjs';
import { MatAccordion, MatExpansionPanel, MatExpansionPanelHeader, MatExpansionPanelTitle, MatExpansionPanelDescription } from '@angular/material/expansion';
import { MatIcon } from '@angular/material/icon';
import { MatDivider } from '@angular/material/divider';
import { MatFormFieldModule } from '@angular/material/form-field';
import { MatSelectModule } from '@angular/material/select';
import { MatPaginatorModule } from '@angular/material/paginator';
import { BrowserAnimationsModule } from '@angular/platform-browser/animations';
import { FormsModule } from '@angular/forms';
import { MatInputModule } from '@angular/material/input';
import { MatTableModule } from '@angular/material/table';
describe('OgDhcpSubnetsComponent', () => {
let component: OgDhcpSubnetsComponent;
let fixture: ComponentFixture<OgDhcpSubnetsComponent>;
let mockDialog: jasmine.SpyObj<MatDialog>;
let mockHttpClient: jasmine.SpyObj<HttpClient>;
let mockToastrService: jasmine.SpyObj<ToastrService>;
beforeEach(async () => {
await TestBed.configureTestingModule({
declarations: [OgDhcpSubnetsComponent]
})
.compileComponents();
mockDialog = jasmine.createSpyObj('MatDialog', ['open']);
mockHttpClient = jasmine.createSpyObj('HttpClient', ['get', 'post', 'put', 'delete']);
mockToastrService = jasmine.createSpyObj('ToastrService', ['success', 'error']);
mockHttpClient.get.and.returnValue(of([]));
await TestBed.configureTestingModule({
declarations: [OgDhcpSubnetsComponent],
imports: [
MatAccordion,
MatExpansionPanel,
MatExpansionPanelHeader,
MatExpansionPanelTitle,
MatExpansionPanelDescription,
MatIcon,
MatDivider,
MatFormFieldModule,
MatSelectModule,
MatPaginatorModule,
BrowserAnimationsModule,
FormsModule,
MatInputModule,
MatTableModule,
],
providers: [
{ provide: MatDialog, useValue: mockDialog },
{ provide: HttpClient, useValue: mockHttpClient },
{ provide: ToastrService, useValue: mockToastrService }
]
}).compileComponents();
});
beforeEach(() => {
fixture = TestBed.createComponent(OgDhcpSubnetsComponent);
component = fixture.componentInstance;
fixture.detectChanges();
@ -20,4 +64,5 @@ describe('OgDhcpSubnetsComponent', () => {
it('should create', () => {
expect(component).toBeTruthy();
});
});

View File

@ -1,24 +0,0 @@
import { ComponentFixture, TestBed } from '@angular/core/testing';
import { RouterModule } from '@angular/router'; // Import RouterModule
import { AuthLayoutComponent } from './auth-layout.component';
describe('AuthLayoutComponent', () => {
let component: AuthLayoutComponent;
let fixture: ComponentFixture<AuthLayoutComponent>;
beforeEach(async () => {
await TestBed.configureTestingModule({
declarations: [AuthLayoutComponent],
imports: [RouterModule.forRoot([])] // Include RouterModule with an empty route
})
.compileComponents();
fixture = TestBed.createComponent(AuthLayoutComponent);
component = fixture.componentInstance;
fixture.detectChanges();
});
it('should create', () => {
expect(component).toBeTruthy();
});
});

View File

@ -1,35 +0,0 @@
import { ComponentFixture, TestBed } from '@angular/core/testing';
import { MatToolbarModule } from '@angular/material/toolbar';
import { MatButtonModule } from '@angular/material/button';
import { MatMenuModule } from '@angular/material/menu';
import { MatDialogModule } from '@angular/material/dialog';
import { RouterTestingModule } from '@angular/router/testing';
import { HeaderComponent } from './header.component';
import { BrowserAnimationsModule } from '@angular/platform-browser/animations';
describe('HeaderComponent', () => {
let component: HeaderComponent;
let fixture: ComponentFixture<HeaderComponent>;
beforeEach(async () => {
await TestBed.configureTestingModule({
declarations: [HeaderComponent],
imports: [
MatToolbarModule,
MatButtonModule,
MatMenuModule,
MatDialogModule,
RouterTestingModule,
BrowserAnimationsModule
]
}).compileComponents();
fixture = TestBed.createComponent(HeaderComponent);
component = fixture.componentInstance;
fixture.detectChanges();
});
it('should create', () => {
expect(component).toBeTruthy();
});
});

View File

@ -1,47 +0,0 @@
import { ComponentFixture, TestBed } from '@angular/core/testing';
import { MainLayoutComponent } from './main-layout.component';
import { MatSidenavModule } from '@angular/material/sidenav';
import { MatToolbarModule } from '@angular/material/toolbar';
import { MatButtonModule } from '@angular/material/button';
import { MatMenuModule } from '@angular/material/menu';
import { NoopAnimationsModule } from '@angular/platform-browser/animations';
import { RouterTestingModule } from '@angular/router/testing';
import { HeaderComponent } from '../header/header.component';
import { SidebarComponent } from '../sidebar/sidebar.component';
import { CUSTOM_ELEMENTS_SCHEMA } from '@angular/core';
describe('MainLayoutComponent', () => {
let component: MainLayoutComponent;
let fixture: ComponentFixture<MainLayoutComponent>;
beforeEach(async () => {
await TestBed.configureTestingModule({
declarations: [MainLayoutComponent, HeaderComponent, SidebarComponent],
imports: [
MatSidenavModule,
MatToolbarModule,
MatButtonModule,
MatMenuModule,
NoopAnimationsModule,
RouterTestingModule,
],
schemas: [CUSTOM_ELEMENTS_SCHEMA],
}).compileComponents();
fixture = TestBed.createComponent(MainLayoutComponent);
component = fixture.componentInstance;
fixture.detectChanges();
});
it('should create', () => {
expect(component).toBeTruthy();
});
it('should toggle sidebar visibility', () => {
expect(component.isSidebarVisible).toBeFalse();
component.toggleSidebar();
expect(component.isSidebarVisible).toBeTrue();
component.toggleSidebar();
expect(component.isSidebarVisible).toBeFalse();
});
});

View File

@ -50,11 +50,30 @@
</mat-nav-list>
<!-- End commands sub -->
<!-- OGDHCP -->
<mat-list-item (click)="toggleOgDhcpSub()">
<span class="entry">
<mat-icon class="icon">settings_ethernet</mat-icon>
<span i18n="@@images">DHCP</span>
</span>
</mat-list-item>
<!-- Submenu items ogdhcp -->
<mat-nav-list *ngIf="showOgDhcpSub" style="padding-left: 20px;">
<mat-list-item routerLink="/dhcp-subnets">
<span class="entry">
<mat-icon class="icon">lan</mat-icon>
<span i18n="@@gallery">Subnets</span>
</span>
</mat-list-item>
</mat-nav-list>
<!-- Submenu items ogdhcp -->
<mat-list-item (click)="toggleOgBootSub()">
<span class="entry">
<mat-icon class="icon">desktop_windows</mat-icon>
<span i18n="@@images">ogBoot</span>
<span i18n="@@images">Boot</span>
</span>
</mat-list-item>
@ -87,25 +106,6 @@
</mat-nav-list>
<!-- End ogBoot sub -->
<!-- OGDHCP -->
<mat-list-item (click)="toggleOgDhcpSub()">
<span class="entry">
<mat-icon class="icon">settings_ethernet</mat-icon>
<span i18n="@@images">ogDhcp</span>
</span>
</mat-list-item>
<!-- Submenu items ogdhcp -->
<mat-nav-list *ngIf="showOgDhcpSub" style="padding-left: 20px;">
<mat-list-item routerLink="/dhcp-subnets">
<span class="entry">
<mat-icon class="icon">lan</mat-icon>
<span i18n="@@gallery">Subnets</span>
</span>
</mat-list-item>
</mat-nav-list>
<!-- Submenu items ogdhcp -->
<mat-list-item>
<span class="entry">
<mat-icon class="icon">settings_input_component</mat-icon>

View File

@ -1,85 +0,0 @@
import { ComponentFixture, TestBed } from '@angular/core/testing';
import { SidebarComponent } from './sidebar.component';
import { MatListModule } from '@angular/material/list';
import { MatIconModule } from '@angular/material/icon';
import { MatDialogModule } from '@angular/material/dialog';
import { MatDividerModule } from '@angular/material/divider';
import { BrowserAnimationsModule } from '@angular/platform-browser/animations';
import { CUSTOM_ELEMENTS_SCHEMA } from '@angular/core';
describe('SidebarComponent', () => {
let component: SidebarComponent;
let fixture: ComponentFixture<SidebarComponent>;
beforeEach(async () => {
await TestBed.configureTestingModule({
declarations: [SidebarComponent],
imports: [
MatListModule,
MatIconModule,
MatDialogModule,
MatDividerModule,
BrowserAnimationsModule, // Necesario para que las animaciones de Angular Material funcionen bien en las pruebas.
],
schemas: [CUSTOM_ELEMENTS_SCHEMA] // Para manejar cualquier elemento desconocido
}).compileComponents();
});
beforeEach(() => {
fixture = TestBed.createComponent(SidebarComponent);
component = fixture.componentInstance;
fixture.detectChanges(); // Dibuja la vista inicial
});
it('should create the component', () => {
expect(component).toBeTruthy(); // Verifica que el componente se creó correctamente.
});
it('should display the username correctly', () => {
// Simula un token decodificado
component.username = 'testUser';
fixture.detectChanges();
const compiled = fixture.nativeElement;
expect(compiled.querySelector('.user-logged').textContent).toContain('testUser');
});
it('should toggle OgBoot submenu', () => {
// Inicialmente, el submenú debe estar oculto
expect(component.showOgBootSub).toBeFalse();
// Llamar a la función de toggle
component.toggleOgBootSub();
expect(component.showOgBootSub).toBeTrue();
// Llamar a la función de toggle otra vez
component.toggleOgBootSub();
expect(component.showOgBootSub).toBeFalse();
});
it('should toggle OgDhcp submenu', () => {
// Inicialmente, el submenú debe estar oculto
expect(component.showOgDhcpSub).toBeFalse();
// Llamar a la función de toggle
component.toggleOgDhcpSub();
expect(component.showOgDhcpSub).toBeTrue();
// Llamar a la función de toggle otra vez
component.toggleOgDhcpSub();
expect(component.showOgDhcpSub).toBeFalse();
});
it('should toggle Commands submenu', () => {
// Inicialmente, el submenú debe estar oculto
expect(component.showCommandSub).toBeFalse();
// Llamar a la función de toggle
component.toggleCommandSub();
expect(component.showCommandSub).toBeTrue();
// Llamar a la función de toggle otra vez
component.toggleCommandSub();
expect(component.showCommandSub).toBeFalse();
});
});

View File

@ -1,30 +0,0 @@
import { ComponentFixture, TestBed } from '@angular/core/testing';
import { MatDialogRef, MAT_DIALOG_DATA } from '@angular/material/dialog';
import { DeleteModalComponent } from './delete-modal.component';
describe('DeleteModalComponent', () => {
let component: DeleteModalComponent;
let fixture: ComponentFixture<DeleteModalComponent>;
beforeEach(async () => {
await TestBed.configureTestingModule({
declarations: [DeleteModalComponent],
providers: [
{ provide: MatDialogRef, useValue: {} },
{ provide: MAT_DIALOG_DATA, useValue: { name: 'Test Name' } }
]
}).compileComponents();
});
beforeEach(() => {
fixture = TestBed.createComponent(DeleteModalComponent);
component = fixture.componentInstance;
fixture.detectChanges();
});
it('should create the component', () => {
expect(component).toBeTruthy();
});
});