mirror of
https://github.com/GNS3/gns3-web-ui.git
synced 2024-12-29 17:28:51 +00:00
Write a unit test case for export project dialog box.
This commit is contained in:
parent
06ed79ec78
commit
50f6cd2191
@ -1,16 +1,45 @@
|
||||
import { NO_ERRORS_SCHEMA } from '@angular/core';
|
||||
import { ComponentFixture, TestBed } from '@angular/core/testing';
|
||||
|
||||
import { FormsModule, ReactiveFormsModule } from '@angular/forms';
|
||||
import { MatCheckboxModule } from '@angular/material/checkbox';
|
||||
import { MatDialogModule, MatDialogRef, MAT_DIALOG_DATA } from '@angular/material/dialog';
|
||||
import { MatFormFieldModule } from '@angular/material/form-field';
|
||||
import { MatInputModule } from '@angular/material/input';
|
||||
import { MatSelectModule } from '@angular/material/select';
|
||||
import { BrowserAnimationsModule } from '@angular/platform-browser/animations';
|
||||
import { ProjectService } from '../../services/project.service';
|
||||
import { MockedProjectService } from '../../services/project.service.spec';
|
||||
import { ToasterService } from '../../services/toaster.service';
|
||||
import { MockedToasterService } from '../../services/toaster.service.spec';
|
||||
import { ExportPortableProjectComponent } from './export-portable-project.component';
|
||||
|
||||
describe('ExportPortableProjectComponent', () => {
|
||||
let component: ExportPortableProjectComponent;
|
||||
let fixture: ComponentFixture<ExportPortableProjectComponent>;
|
||||
let mockedToasterService = new MockedToasterService();
|
||||
let mockedProjectService = new MockedProjectService();
|
||||
|
||||
beforeEach(async () => {
|
||||
await TestBed.configureTestingModule({
|
||||
declarations: [ ExportPortableProjectComponent ]
|
||||
})
|
||||
.compileComponents();
|
||||
declarations: [ExportPortableProjectComponent],
|
||||
imports: [
|
||||
MatDialogModule,
|
||||
ReactiveFormsModule,
|
||||
FormsModule,
|
||||
MatSelectModule,
|
||||
MatCheckboxModule,
|
||||
MatFormFieldModule,
|
||||
MatInputModule,
|
||||
BrowserAnimationsModule
|
||||
],
|
||||
providers: [
|
||||
{ provide: MatDialogRef, useValue: {} },
|
||||
{ provide: MAT_DIALOG_DATA, useValue: {} },
|
||||
{ provide: ToasterService, useValue: mockedToasterService },
|
||||
{ provide: ProjectService, useValue: mockedProjectService },
|
||||
],
|
||||
schemas: [NO_ERRORS_SCHEMA],
|
||||
}).compileComponents();
|
||||
});
|
||||
|
||||
beforeEach(() => {
|
||||
@ -20,6 +49,11 @@ describe('ExportPortableProjectComponent', () => {
|
||||
});
|
||||
|
||||
it('should create', () => {
|
||||
let compression_methods_Value = mockedProjectService.getCompression;
|
||||
let compression_level_value = mockedProjectService.getCompressionLevel;
|
||||
component.compression_methods = compression_methods_Value[4];
|
||||
component.compression_level = compression_level_value;
|
||||
component.selectCompression(component.compression_methods);
|
||||
expect(component).toBeTruthy();
|
||||
});
|
||||
});
|
||||
|
@ -19,6 +19,7 @@ export class ExportPortableProjectComponent implements OnInit {
|
||||
compression_level: any = [];
|
||||
compression_filter_value: any = [];
|
||||
server: Server;
|
||||
index: number = 4;
|
||||
|
||||
constructor(
|
||||
public dialogRef: MatDialogRef<ExportPortableProjectComponent>,
|
||||
@ -28,10 +29,9 @@ export class ExportPortableProjectComponent implements OnInit {
|
||||
private _fb: FormBuilder
|
||||
) {}
|
||||
|
||||
ngOnInit(): void {
|
||||
async ngOnInit() {
|
||||
this.server = this.data;
|
||||
|
||||
this.formControls();
|
||||
await this.formControls();
|
||||
this.compression_methods = this.projectService.getCompression();
|
||||
this.compression_level = this.projectService.getCompressionLevel();
|
||||
this.uploader = new FileUploader({});
|
||||
@ -52,9 +52,8 @@ export class ExportPortableProjectComponent implements OnInit {
|
||||
};
|
||||
|
||||
this.uploader.onProgressItem = (progress: any) => {};
|
||||
|
||||
this.selectCompression({ value: this.compression_methods[4] });
|
||||
this.export_project_form.get('compression').setValue(this.compression_methods[4]);
|
||||
this.selectCompression({ value: this.compression_methods[this.index] });
|
||||
this.export_project_form.get('compression').setValue(this.compression_methods[this.index]);
|
||||
}
|
||||
|
||||
formControls() {
|
||||
@ -72,20 +71,21 @@ export class ExportPortableProjectComponent implements OnInit {
|
||||
uploadImageFile(event) {}
|
||||
|
||||
selectCompression(event) {
|
||||
this.compression_level.map((_) => {
|
||||
if (event.value.value === _.name) {
|
||||
this.export_project_form.get('compression_level').setValue(_.value);
|
||||
this.compression_filter_value = _.selectionValues;
|
||||
}
|
||||
});
|
||||
if (this.compression_level.length > 0) {
|
||||
this.compression_level.map((_) => {
|
||||
if (event.value.value === _.name) {
|
||||
this.export_project_form.get('compression_level').setValue(_.value);
|
||||
this.compression_filter_value = _.selectionValues;
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
exportPortableProject() {
|
||||
let response
|
||||
let response;
|
||||
this.export_project_form.value.compression = this.export_project_form.value.compression.value;
|
||||
this.projectService.exportPortableProject(this.server, this.export_project_form.value)
|
||||
.subscribe((res) => {
|
||||
response = res
|
||||
this.projectService.exportPortableProject(this.server, this.export_project_form.value).subscribe((res) => {
|
||||
response = res;
|
||||
});
|
||||
}
|
||||
}
|
||||
|
@ -3,7 +3,7 @@ import { NO_ERRORS_SCHEMA } from '@angular/core';
|
||||
import { ComponentFixture, TestBed } from '@angular/core/testing';
|
||||
import { MatBottomSheetModule } from '@angular/material/bottom-sheet';
|
||||
import { MatCheckboxModule } from '@angular/material/checkbox';
|
||||
import { MatDialogModule } from '@angular/material/dialog';
|
||||
import { MatDialogModule, MatDialogRef, MAT_DIALOG_DATA } from '@angular/material/dialog';
|
||||
import { MatIconModule } from '@angular/material/icon';
|
||||
import { MatMenuModule } from '@angular/material/menu';
|
||||
import { MatToolbarModule } from '@angular/material/toolbar';
|
||||
@ -319,6 +319,10 @@ xdescribe('ProjectMapComponent', () => {
|
||||
{ provide: MapSymbolsDataSource, useClass: MapSymbolsDataSource },
|
||||
{ provide: MapSettingsService, useClass: MapSettingsService },
|
||||
{ provide: NotificationService },
|
||||
{ provide: MatDialogRef, useValue: {}},
|
||||
{ provide: MAT_DIALOG_DATA, useValue: {}},
|
||||
|
||||
|
||||
],
|
||||
declarations: [ProjectMapComponent, ProjectMapMenuComponent, D3MapComponent, ...ANGULAR_MAP_DECLARATIONS],
|
||||
schemas: [NO_ERRORS_SCHEMA],
|
||||
|
@ -49,6 +49,15 @@ export class MockedProjectService {
|
||||
getStatistics(server: Server, project_id: string) {
|
||||
return of({});
|
||||
}
|
||||
exportPortableProject(server: Server, formData:{}) {
|
||||
return of({});
|
||||
}
|
||||
getCompression() {
|
||||
return of([]);
|
||||
}
|
||||
getCompressionLevel() {
|
||||
return of([]);
|
||||
}
|
||||
}
|
||||
|
||||
describe('ProjectService', () => {
|
||||
|
@ -129,10 +129,10 @@ export class ProjectService {
|
||||
return false;
|
||||
}
|
||||
|
||||
getCompression = () => {
|
||||
getCompression() {
|
||||
return this.compression_methods;
|
||||
};
|
||||
getCompressionLevel = () => {
|
||||
getCompressionLevel() {
|
||||
return this.compression_level_default_value;
|
||||
};
|
||||
exportPortableProject(server:Server,formData:any={}) {
|
||||
|
Loading…
Reference in New Issue
Block a user