Skip to content

Commit

Permalink
feat:add test ts file
Browse files Browse the repository at this point in the history
Signed-off-by: wei.jin <wei.jin@thundersoft.com>
  • Loading branch information
wei.jin committed Sep 4, 2023
1 parent a321165 commit e1eb71e
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 16 deletions.
Original file line number Diff line number Diff line change
@@ -1,14 +1,28 @@
import { NO_ERRORS_SCHEMA } from '@angular/core';
import { ComponentFixture, TestBed } from '@angular/core/testing';
import { RouterTestingModule } from '@angular/router/testing';
import { FormsModule } from '@angular/forms';
import { of } from 'rxjs';

import { AddProvisionWatcherComponent } from './add-provision-watcher.component';

import { MetadataService } from '../../../services/metadata.service';
describe('AddProvisionWatcherComponent', () => {
let component: AddProvisionWatcherComponent;
let fixture: ComponentFixture<AddProvisionWatcherComponent>;
let mockMetadataService: MetadataService

beforeEach(async () => {
mockMetadataService = jasmine.createSpyObj('MetadataService', {
ping: of({})
})

await TestBed.configureTestingModule({
declarations: [ AddProvisionWatcherComponent ]
imports: [RouterTestingModule, FormsModule],
declarations: [ AddProvisionWatcherComponent ],
providers: [
{provide: MetadataService, useValue: mockMetadataService}
],
schemas: [NO_ERRORS_SCHEMA]
})
.compileComponents();
});
Expand Down
Original file line number Diff line number Diff line change
@@ -1,19 +1,26 @@
import { ComponentFixture, TestBed } from '@angular/core/testing';
import { FormsModule } from '@angular/forms';
import { RouterTestingModule } from '@angular/router/testing';
import { of } from 'rxjs';

import { EditProvisionWatcherComponent } from './edit-provision-watcher.component';

import { MetadataService } from '../../../services/metadata.service';
describe('EditProvisionWatcherComponent', () => {
let component: EditProvisionWatcherComponent;
let fixture: ComponentFixture<EditProvisionWatcherComponent>;
let mockMetadataService: MetadataService

beforeEach(async () => {
await TestBed.configureTestingModule({
declarations: [ EditProvisionWatcherComponent ]
mockMetadataService = jasmine.createSpyObj('MetadataService', {
ping: of({})
})
.compileComponents();
});

beforeEach(() => {
await TestBed.configureTestingModule({
declarations: [ EditProvisionWatcherComponent ],
imports: [RouterTestingModule, FormsModule],
providers: [{provide: MetadataService, useValue: mockMetadataService}]
}).compileComponents();

fixture = TestBed.createComponent(EditProvisionWatcherComponent);
component = fixture.componentInstance;
fixture.detectChanges();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,25 +1,41 @@
import { NO_ERRORS_SCHEMA} from '@angular/core';
import { ComponentFixture, TestBed } from '@angular/core/testing';
import { RouterTestingModule } from '@angular/router/testing';
import { FormsModule } from '@angular/forms';
import { of } from 'rxjs';

import { ProvisionWatcherListComponent } from './provision-watcher-list.component';
import { MetadataService } from '../../../services/metadata.service';

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

let mockMetadataService: MetadataService
beforeEach(async () => {
await TestBed.configureTestingModule({
declarations: [ ProvisionWatcherListComponent ]
mockMetadataService = jasmine.createSpyObj('MetadataService', {
allProvisionWatchersPagination: of({provisionWatchers:[]}),
findProvisionWatcherByName: undefined
})
.compileComponents();
});
await TestBed.configureTestingModule({
declarations: [ ProvisionWatcherListComponent ],
imports: [RouterTestingModule, FormsModule],
providers: [{provide: MetadataService, useValue: mockMetadataService},],
schemas: [NO_ERRORS_SCHEMA]
}).compileComponents();

beforeEach(() => {
fixture = TestBed.createComponent(ProvisionWatcherListComponent);
component = fixture.componentInstance;
fixture.detectChanges();
});

it('should create', () => {
it('renders without errors', () => {
expect(component).toBeTruthy();
});

it('finds provision watcher pagination',() => {
expect(mockMetadataService.allProvisionWatchersPagination).toHaveBeenCalledWith(0,5);
})

it('not find provision watcher by profileName',() => {
expect(mockMetadataService.findProvisionWatcherByName).not.toHaveBeenCalledWith('sample-provision-name');
})
});

0 comments on commit e1eb71e

Please sign in to comment.