Trying to get the tests to pass, but still more work to do.

This commit is contained in:
Dan 2021-02-15 12:44:29 -05:00
parent 3b80d8dd89
commit 262dd0f198
4 changed files with 68 additions and 12 deletions

View File

@ -49,7 +49,7 @@ import { MatDatepickerModule } from '@angular/material/datepicker';
import { MatNativeDateModule, DateAdapter } from '@angular/material/core'; import { MatNativeDateModule, DateAdapter } from '@angular/material/core';
import {MatPaginatorModule} from '@angular/material/paginator'; import {MatPaginatorModule} from '@angular/material/paginator';
import { CustomDateAdapter } from './custom-date-adapter'; import { CustomDateAdapter } from './custom-date-adapter';
import { MatTableModule } from '@angular/material/table' import { MatTableModule } from '@angular/material/table';
import {MatGridListModule} from '@angular/material/grid-list'; import {MatGridListModule} from '@angular/material/grid-list';
import {MatDividerModule} from '@angular/material/divider'; import {MatDividerModule} from '@angular/material/divider';
import { SidebarComponent } from './sidebar/sidebar.component'; import { SidebarComponent } from './sidebar/sidebar.component';
@ -130,7 +130,7 @@ export function getBaseHref(platformLocation: PlatformLocation): string {
ApiService, ApiService,
GraphService, GraphService,
CacheService, CacheService,
SettingsService, SettingsService,
MatDatepickerModule, MatDatepickerModule,
{provide: DateAdapter, useClass: CustomDateAdapter }, {provide: DateAdapter, useClass: CustomDateAdapter },
{provide: 'APP_ENVIRONMENT', useClass: ThisEnvironment}, {provide: 'APP_ENVIRONMENT', useClass: ThisEnvironment},

View File

@ -1,11 +1,13 @@
import { NativeDateAdapter } from '@angular/material/core'; import { NativeDateAdapter } from '@angular/material/core';
import {Injectable} from '@angular/core';
/** Adapts the native JS Date for use with cdk-based components that work with dates. */ /** Adapts the native JS Date for use with cdk-based components that work with dates. */
@Injectable()
export class CustomDateAdapter extends NativeDateAdapter { export class CustomDateAdapter extends NativeDateAdapter {
getFirstDayOfWeek(): number { getFirstDayOfWeek(): number {
return 1; return 1;
} }
} }

View File

@ -1,19 +1,43 @@
import { ComponentFixture, TestBed } from '@angular/core/testing'; import { ComponentFixture, TestBed } from '@angular/core/testing';
import { GraphsComponent } from './graphs.component'; import { GraphsComponent } from './graphs.component';
import {HttpClientTestingModule, HttpTestingController} from '@angular/common/http/testing';
import {MatBottomSheetModule} from '@angular/material/bottom-sheet';
import {RouterTestingModule} from '@angular/router/testing';
import {ApiService} from '../services/api.service';
import {APP_BASE_HREF} from '@angular/common';
import {Router} from '@angular/router';
import {MockEnvironment} from '../testing/environment.mock';
import {DateAdapter} from '@angular/material/core';
import {CustomDateAdapter} from '../custom-date-adapter';
describe('GraphsComponent', () => { describe('GraphsComponent', () => {
let component: GraphsComponent; let component: GraphsComponent;
let fixture: ComponentFixture<GraphsComponent>; let fixture: ComponentFixture<GraphsComponent>;
let httpMock: HttpTestingController;
beforeEach(async () => { const mockEnvironment = new MockEnvironment();
await TestBed.configureTestingModule({ const mockRouter = {
declarations: [ GraphsComponent ] createUrlTree: jasmine.createSpy('createUrlTree'),
}) navigate: jasmine.createSpy('navigate')
.compileComponents(); };
});
beforeEach(() => { beforeEach(() => {
TestBed.configureTestingModule({
imports: [
HttpClientTestingModule,
MatBottomSheetModule,
RouterTestingModule.withRoutes([]),
],
providers: [
ApiService,
{provide: 'APP_ENVIRONMENT', useValue: mockEnvironment},
{provide: APP_BASE_HREF, useValue: '/'},
{provide: Router, useValue: mockRouter},
{provide: Location, useValue: location},
{provide: DateAdapter, useClass: CustomDateAdapter }
]
});
httpMock = TestBed.inject(HttpTestingController);
fixture = TestBed.createComponent(GraphsComponent); fixture = TestBed.createComponent(GraphsComponent);
component = fixture.componentInstance; component = fixture.componentInstance;
fixture.detectChanges(); fixture.detectChanges();

View File

@ -1,13 +1,43 @@
import { TestBed } from '@angular/core/testing'; import { TestBed } from '@angular/core/testing';
import { GraphService } from './graph.service'; import { GraphService } from './graph.service';
import {HttpClientTestingModule, HttpTestingController} from '@angular/common/http/testing';
import {MatBottomSheetModule} from '@angular/material/bottom-sheet';
import {RouterTestingModule} from '@angular/router/testing';
import {ApiService} from './api.service';
import {APP_BASE_HREF} from '@angular/common';
import {Router} from '@angular/router';
import {MockEnvironment} from '../testing/environment.mock';
describe('GraphService', () => { describe('GraphService', () => {
let httpMock: HttpTestingController;
let location: Location;
let service: GraphService; let service: GraphService;
const mockEnvironment = new MockEnvironment();
const mockRouter = {
createUrlTree: jasmine.createSpy('createUrlTree'),
navigate: jasmine.createSpy('navigate')
};
beforeEach(() => { beforeEach(() => {
TestBed.configureTestingModule({}); TestBed.configureTestingModule({
imports: [
HttpClientTestingModule,
MatBottomSheetModule,
RouterTestingModule.withRoutes([]),
],
providers: [
ApiService,
{provide: 'APP_ENVIRONMENT', useValue: mockEnvironment},
{provide: APP_BASE_HREF, useValue: '/'},
{provide: Router, useValue: mockRouter},
{provide: Location, useValue: location},
]
});
httpMock = TestBed.inject(HttpTestingController);
service = TestBed.inject(GraphService); service = TestBed.inject(GraphService);
location = TestBed.inject(Location);
}); });
it('should be created', () => { it('should be created', () => {