mirror of
https://github.com/Mueller-Patrick/Betterzon.git
synced 2026-04-27 15:50:11 +00:00
BETTERZON-83: FE unit testing (#35)
* BETTERZON-83: Making pre-generated unit tests work * BETTERZON-83: Writing unit tests for angular to improve code coverage
This commit is contained in:
@@ -1,25 +1,75 @@
|
||||
import { ComponentFixture, TestBed } from '@angular/core/testing';
|
||||
import {ComponentFixture, TestBed} from '@angular/core/testing';
|
||||
|
||||
import { ProductDetailsComponent } from './product-details.component';
|
||||
import {ProductDetailsComponent} from './product-details.component';
|
||||
import {RouterTestingModule} from "@angular/router/testing";
|
||||
import {AbstractMockObservableService} from "../../mocks/mock.service";
|
||||
import {ApiService} from "../../services/api.service";
|
||||
import {ChartComponent, NgApexchartsModule} from "ng-apexcharts";
|
||||
|
||||
class MockApiService extends AbstractMockObservableService {
|
||||
getProduct() {
|
||||
this.content = {};
|
||||
return this;
|
||||
}
|
||||
|
||||
getLowestPrices() {
|
||||
const price = {
|
||||
price_id: 1,
|
||||
product_id: 1,
|
||||
vendor_id: 1,
|
||||
price_in_cents: 123,
|
||||
timestamp: new Date()
|
||||
};
|
||||
this.content = [price];
|
||||
return this;
|
||||
}
|
||||
|
||||
getAmazonPrice() {
|
||||
this.content = {};
|
||||
return this;
|
||||
}
|
||||
|
||||
getVendors() {
|
||||
const vendor = {
|
||||
vendor_id: 1,
|
||||
name: 'Max Mustermann',
|
||||
streetname: 'Musterstraße 69',
|
||||
zip_code: '12345',
|
||||
city: 'Musterhausen',
|
||||
country_code: 'DE',
|
||||
phone: '+49 123 4567890',
|
||||
website: 'https://www.amazon.de',
|
||||
}
|
||||
this.content = [vendor];
|
||||
return this;
|
||||
}
|
||||
}
|
||||
|
||||
describe('ProductDetailsComponent', () => {
|
||||
let component: ProductDetailsComponent;
|
||||
let fixture: ComponentFixture<ProductDetailsComponent>;
|
||||
let component: ProductDetailsComponent;
|
||||
let fixture: ComponentFixture<ProductDetailsComponent>;
|
||||
let mockService;
|
||||
|
||||
beforeEach(async () => {
|
||||
await TestBed.configureTestingModule({
|
||||
declarations: [ ProductDetailsComponent ]
|
||||
})
|
||||
.compileComponents();
|
||||
});
|
||||
beforeEach(async () => {
|
||||
mockService = new MockApiService();
|
||||
await TestBed.configureTestingModule({
|
||||
providers: [{provide: ApiService, useValue: mockService}],
|
||||
declarations: [ProductDetailsComponent],
|
||||
imports: [
|
||||
RouterTestingModule,
|
||||
NgApexchartsModule
|
||||
]
|
||||
})
|
||||
.compileComponents();
|
||||
});
|
||||
|
||||
beforeEach(() => {
|
||||
fixture = TestBed.createComponent(ProductDetailsComponent);
|
||||
component = fixture.componentInstance;
|
||||
fixture.detectChanges();
|
||||
});
|
||||
beforeEach(() => {
|
||||
fixture = TestBed.createComponent(ProductDetailsComponent);
|
||||
component = fixture.componentInstance;
|
||||
fixture.detectChanges();
|
||||
});
|
||||
|
||||
it('should create', () => {
|
||||
expect(component).toBeTruthy();
|
||||
});
|
||||
it('should create', () => {
|
||||
expect(component).toBeTruthy();
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user