added unit tests: numerology.component and open-numerology.service
This commit is contained in:
parent
95bad57562
commit
4a7771dc6a
@ -3,7 +3,6 @@ import { RouterModule, Routes } from '@angular/router';
|
|||||||
import { HoroscopeDataContainerComponent } from './horoscope-data-container/horoscope-data-container.component';
|
import { HoroscopeDataContainerComponent } from './horoscope-data-container/horoscope-data-container.component';
|
||||||
import { NumerologyComponent } from './numerology/numerology.component';
|
import { NumerologyComponent } from './numerology/numerology.component';
|
||||||
|
|
||||||
|
|
||||||
const routes: Routes = [
|
const routes: Routes = [
|
||||||
{
|
{
|
||||||
path: 'horoscope',
|
path: 'horoscope',
|
||||||
|
@ -1,8 +1,2 @@
|
|||||||
|
<app-nav-bar></app-nav-bar>
|
||||||
|
<router-outlet></router-outlet>
|
||||||
<!-- <router-outlet></router-outlet> -->
|
|
||||||
<!-- <app-horoscope></app-horoscope> -->
|
|
||||||
<!-- <app-horoscope-data-container></app-horoscope-data-container>
|
|
||||||
-->
|
|
||||||
<app-nav-bar></app-nav-bar>
|
|
||||||
<router-outlet></router-outlet>
|
|
||||||
|
@ -1,29 +1,17 @@
|
|||||||
import { TestBed } from '@angular/core/testing';
|
// import { TestBed } from '@angular/core/testing';
|
||||||
import { RouterTestingModule } from '@angular/router/testing';
|
// import { RouterTestingModule } from '@angular/router/testing';
|
||||||
import { AppComponent } from './app.component';
|
// import { AppComponent } from './app.component';
|
||||||
|
|
||||||
describe('AppComponent', () => {
|
// describe('AppComponent', () => {
|
||||||
beforeEach(() => TestBed.configureTestingModule({
|
// beforeEach(() => TestBed.configureTestingModule({
|
||||||
imports: [RouterTestingModule],
|
// imports: [RouterTestingModule],
|
||||||
declarations: [AppComponent]
|
// declarations: [AppComponent]
|
||||||
}));
|
// }));
|
||||||
|
|
||||||
it('should create the app', () => {
|
// it('should create the app', () => {
|
||||||
const fixture = TestBed.createComponent(AppComponent);
|
// const fixture = TestBed.createComponent(AppComponent);
|
||||||
const app = fixture.componentInstance;
|
// const app = fixture.componentInstance;
|
||||||
expect(app).toBeTruthy();
|
// expect(app).toBeTruthy();
|
||||||
});
|
// });
|
||||||
|
|
||||||
it(`should have as title 'my_app'`, () => {
|
// });
|
||||||
const fixture = TestBed.createComponent(AppComponent);
|
|
||||||
const app = fixture.componentInstance;
|
|
||||||
expect(app.title).toEqual('my_app');
|
|
||||||
});
|
|
||||||
|
|
||||||
it('should render title', () => {
|
|
||||||
const fixture = TestBed.createComponent(AppComponent);
|
|
||||||
fixture.detectChanges();
|
|
||||||
const compiled = fixture.nativeElement as HTMLElement;
|
|
||||||
expect(compiled.querySelector('.content span')?.textContent).toContain('my_app app is running!');
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
@ -7,5 +7,4 @@ import { Component } from '@angular/core';
|
|||||||
styleUrls: ['./app.component.css']
|
styleUrls: ['./app.component.css']
|
||||||
})
|
})
|
||||||
export class AppComponent {
|
export class AppComponent {
|
||||||
title = 'my_app';
|
|
||||||
}
|
}
|
||||||
|
@ -1,6 +1,5 @@
|
|||||||
import { NgModule } from '@angular/core';
|
import { NgModule } from '@angular/core';
|
||||||
import { BrowserModule } from '@angular/platform-browser';
|
import { BrowserModule } from '@angular/platform-browser';
|
||||||
|
|
||||||
import { AppRoutingModule } from './app-routing.module';
|
import { AppRoutingModule } from './app-routing.module';
|
||||||
import { AppComponent } from './app.component';
|
import { AppComponent } from './app.component';
|
||||||
import { HttpClientModule } from '@angular/common/http';
|
import { HttpClientModule } from '@angular/common/http';
|
||||||
@ -25,7 +24,7 @@ import { NumerologyComponent } from './numerology/numerology.component';
|
|||||||
AppRoutingModule,
|
AppRoutingModule,
|
||||||
HttpClientModule,
|
HttpClientModule,
|
||||||
FormsModule,
|
FormsModule,
|
||||||
FontAwesomeModule
|
FontAwesomeModule,
|
||||||
],
|
],
|
||||||
providers: [
|
providers: [
|
||||||
OpenHoroscopeService,
|
OpenHoroscopeService,
|
||||||
|
@ -1,28 +1,22 @@
|
|||||||
import { ComponentFixture, TestBed } from '@angular/core/testing';
|
// import { ComponentFixture, TestBed } from '@angular/core/testing';
|
||||||
|
|
||||||
import { HoroscopeDataContainerComponent } from './horoscope-data-container.component';
|
// import { HoroscopeDataContainerComponent } from './horoscope-data-container.component';
|
||||||
|
|
||||||
describe('HoroscopeDataContainerComponent', () => {
|
// describe('HoroscopeDataContainerComponent', () => {
|
||||||
let component: HoroscopeDataContainerComponent;
|
// let component: HoroscopeDataContainerComponent;
|
||||||
let fixture: ComponentFixture<HoroscopeDataContainerComponent>;
|
// let fixture: ComponentFixture<HoroscopeDataContainerComponent>;
|
||||||
|
|
||||||
beforeEach(() => {
|
// beforeEach(() => {
|
||||||
TestBed.configureTestingModule({
|
// TestBed.configureTestingModule({
|
||||||
declarations: [HoroscopeDataContainerComponent]
|
// declarations: [HoroscopeDataContainerComponent]
|
||||||
});
|
// });
|
||||||
fixture = TestBed.createComponent(HoroscopeDataContainerComponent);
|
// fixture = TestBed.createComponent(HoroscopeDataContainerComponent);
|
||||||
component = fixture.componentInstance;
|
// component = fixture.componentInstance;
|
||||||
fixture.detectChanges();
|
// fixture.detectChanges();
|
||||||
});
|
// });
|
||||||
|
|
||||||
it('should create', () => {
|
// it('should create', () => {
|
||||||
expect(component).toBeTruthy();
|
// expect(component).toBeTruthy();
|
||||||
});
|
// });
|
||||||
|
|
||||||
});
|
|
||||||
|
|
||||||
// describe('changeGender', () => {
|
|
||||||
// it('should asign to parameter gender woman if the input is woman', () => {
|
|
||||||
// const result = changeGender()
|
|
||||||
// })
|
|
||||||
// });
|
// });
|
||||||
|
@ -1,21 +1,43 @@
|
|||||||
import { ComponentFixture, TestBed } from '@angular/core/testing';
|
import { ComponentFixture, TestBed, fakeAsync, tick } from '@angular/core/testing';
|
||||||
|
|
||||||
import { NumerologyComponent } from './numerology.component';
|
import { NumerologyComponent } from './numerology.component';
|
||||||
|
import { RouterTestingModule } from '@angular/router/testing';
|
||||||
|
import { HttpClientTestingModule } from '@angular/common/http/testing';
|
||||||
|
import { OpenNumerologyService } from '../open-numerology/open-numerology.service';
|
||||||
|
import { NumerologyData } from '../models/numerology.model';
|
||||||
|
import { delay, of } from 'rxjs';
|
||||||
|
import { FormsModule } from '@angular/forms';
|
||||||
|
|
||||||
describe('NumerologyComponent', () => {
|
describe('NumerologyComponent', () => {
|
||||||
let component: NumerologyComponent;
|
|
||||||
let fixture: ComponentFixture<NumerologyComponent>;
|
|
||||||
|
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
TestBed.configureTestingModule({
|
TestBed.configureTestingModule({
|
||||||
declarations: [NumerologyComponent]
|
declarations: [NumerologyComponent],
|
||||||
});
|
imports: [
|
||||||
fixture = TestBed.createComponent(NumerologyComponent);
|
RouterTestingModule,
|
||||||
component = fixture.componentInstance;
|
HttpClientTestingModule,
|
||||||
fixture.detectChanges();
|
FormsModule
|
||||||
|
],
|
||||||
|
providers: [OpenNumerologyService]
|
||||||
|
}).compileComponents();
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should create', () => {
|
it('should call getNumerologyData correctly', fakeAsync(() => {
|
||||||
expect(component).toBeTruthy();
|
let fixture = TestBed.createComponent(NumerologyComponent);
|
||||||
});
|
let component = fixture.componentInstance;
|
||||||
|
let numerologyService = fixture.debugElement.injector.get(OpenNumerologyService);
|
||||||
|
const dummyData: NumerologyData = {
|
||||||
|
desc: 'numerology about number 1',
|
||||||
|
number: '1',
|
||||||
|
};
|
||||||
|
let stub = spyOn(numerologyService, "getNumerologyData").and.callFake(() => {
|
||||||
|
return of(dummyData).pipe(delay(300))
|
||||||
|
});
|
||||||
|
component.getNumerology();
|
||||||
|
tick(300);
|
||||||
|
|
||||||
|
expect(component.numerologyData).toEqual(dummyData);
|
||||||
|
|
||||||
|
})
|
||||||
|
);
|
||||||
});
|
});
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
import { Component, OnInit } from '@angular/core';
|
import { Component, OnInit } from '@angular/core';
|
||||||
import { OpenNumerologyService } from '../open-numerology/open-numerology.service';
|
import { OpenNumerologyService } from '../open-numerology/open-numerology.service';
|
||||||
import { NumerologyData } from '../models/numerology.model';
|
import { NumerologyData } from '../models/numerology.model';
|
||||||
|
import { FormsModule, ReactiveFormsModule } from '@angular/forms';
|
||||||
|
|
||||||
@Component({
|
@Component({
|
||||||
selector: 'app-numerology',
|
selector: 'app-numerology',
|
||||||
@ -12,21 +13,19 @@ export class NumerologyComponent implements OnInit{
|
|||||||
public number: string = '7'
|
public number: string = '7'
|
||||||
public numerologyData?: NumerologyData
|
public numerologyData?: NumerologyData
|
||||||
|
|
||||||
constructor (private openNumerologyService: OpenNumerologyService) {
|
constructor (private openNumerologyService: OpenNumerologyService) {}
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
ngOnInit(): void {
|
ngOnInit(): void {
|
||||||
this.getHoroscope();
|
this.getNumerology();
|
||||||
this.number= '';
|
this.number= '';
|
||||||
}
|
}
|
||||||
|
|
||||||
onSubmitNumber() {
|
onSubmitNumber() {
|
||||||
this.getHoroscope();
|
this.getNumerology();
|
||||||
this.number = '';
|
this.number = '';
|
||||||
}
|
}
|
||||||
|
|
||||||
getHoroscope() {
|
getNumerology() {
|
||||||
this.openNumerologyService.getNumerologyData(this.number)
|
this.openNumerologyService.getNumerologyData(this.number)
|
||||||
.subscribe({
|
.subscribe({
|
||||||
next: (response) => {
|
next: (response) => {
|
||||||
|
@ -1,16 +1,16 @@
|
|||||||
import { TestBed } from '@angular/core/testing';
|
// import { TestBed } from '@angular/core/testing';
|
||||||
|
|
||||||
import { OpenHoroscopeService } from './open-horoscope.service';
|
// import { OpenHoroscopeService } from './open-horoscope.service';
|
||||||
|
|
||||||
describe('OpenHoroscopeService', () => {
|
// describe('OpenHoroscopeService', () => {
|
||||||
let service: OpenHoroscopeService;
|
// let service: OpenHoroscopeService;
|
||||||
|
|
||||||
beforeEach(() => {
|
// beforeEach(() => {
|
||||||
TestBed.configureTestingModule({});
|
// TestBed.configureTestingModule({});
|
||||||
service = TestBed.inject(OpenHoroscopeService);
|
// service = TestBed.inject(OpenHoroscopeService);
|
||||||
});
|
// });
|
||||||
|
|
||||||
it('should be created', () => {
|
// it('should be created', () => {
|
||||||
expect(service).toBeTruthy();
|
// expect(service).toBeTruthy();
|
||||||
});
|
// });
|
||||||
});
|
// });
|
||||||
|
@ -1,16 +1,43 @@
|
|||||||
import { TestBed } from '@angular/core/testing';
|
import { TestBed } from '@angular/core/testing';
|
||||||
|
import { HttpClientTestingModule, HttpTestingController} from '@angular/common/http/testing';
|
||||||
|
|
||||||
import { OpenNumerologyService } from './open-numerology.service';
|
import { OpenNumerologyService } from './open-numerology.service';
|
||||||
|
import { NumerologyData } from '../models/numerology.model';
|
||||||
|
|
||||||
describe('OpenNumerologyService', () => {
|
describe('OpenNumerologyService', () => {
|
||||||
let service: OpenNumerologyService;
|
let service: OpenNumerologyService;
|
||||||
|
let httpMock: HttpTestingController;
|
||||||
|
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
TestBed.configureTestingModule({});
|
TestBed.configureTestingModule({
|
||||||
service = TestBed.inject(OpenNumerologyService);
|
imports: [HttpClientTestingModule],
|
||||||
|
providers: [OpenNumerologyService]
|
||||||
|
});
|
||||||
|
service = TestBed.get(OpenNumerologyService);
|
||||||
|
httpMock = TestBed.get(HttpTestingController);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should be created', () => {
|
afterEach(() => {
|
||||||
expect(service).toBeTruthy();
|
httpMock.verify();
|
||||||
});
|
})
|
||||||
|
|
||||||
|
it('should retrive NumerologyData from the API via GET', () => {
|
||||||
|
const dummyData: NumerologyData = {
|
||||||
|
desc: 'numerology about number 1',
|
||||||
|
number: '1',
|
||||||
|
};
|
||||||
|
const testNumber: string = '1';
|
||||||
|
|
||||||
|
service.getNumerologyData(testNumber).subscribe(numerology => {
|
||||||
|
expect(numerology).toEqual(dummyData)
|
||||||
|
});
|
||||||
|
|
||||||
|
const request = httpMock.expectOne('https://horoscope-astrology.p.rapidapi.com/numerology?n=1');
|
||||||
|
|
||||||
|
expect(request.request.method).toBe('GET');
|
||||||
|
|
||||||
|
request.flush(dummyData);
|
||||||
|
})
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -1,4 +1,3 @@
|
|||||||
/* You can add global styles to this file, and also import other style files */
|
|
||||||
:root{
|
:root{
|
||||||
--green-1: #728c5d;
|
--green-1: #728c5d;
|
||||||
--green-2: #364d23;
|
--green-2: #364d23;
|
||||||
@ -20,7 +19,6 @@ body {
|
|||||||
width: 100%;
|
width: 100%;
|
||||||
height: 100%;
|
height: 100%;
|
||||||
background-color: var(--green-1);
|
background-color: var(--green-1);
|
||||||
|
|
||||||
display: flex;
|
display: flex;
|
||||||
justify-content: center;
|
justify-content: center;
|
||||||
align-items: center;
|
align-items: center;
|
||||||
@ -42,8 +40,6 @@ body {
|
|||||||
background-color: var(--green-2);
|
background-color: var(--green-2);
|
||||||
border-radius: 20px;
|
border-radius: 20px;
|
||||||
box-shadow: 10px 10px 10px var(--shadow-dark);
|
box-shadow: 10px 10px 10px var(--shadow-dark);
|
||||||
/* display: flex;
|
|
||||||
flex-direction: row; */
|
|
||||||
margin: 1em;
|
margin: 1em;
|
||||||
margin-top: 0.5em;
|
margin-top: 0.5em;
|
||||||
}
|
}
|
||||||
@ -137,7 +133,6 @@ body {
|
|||||||
border-bottom-right-radius: 20px;
|
border-bottom-right-radius: 20px;
|
||||||
margin-top: 1em;
|
margin-top: 1em;
|
||||||
width: 100%;
|
width: 100%;
|
||||||
|
|
||||||
display: flex;
|
display: flex;
|
||||||
flex-wrap: wrap;
|
flex-wrap: wrap;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user