This commit is contained in:
Nile Walker 2021-02-15 13:05:48 -05:00
commit f8e589e67a
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';

View File

@ -1,7 +1,9 @@
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 {

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', () => {