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 {MatPaginatorModule} from '@angular/material/paginator';
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 {MatDividerModule} from '@angular/material/divider';
import { SidebarComponent } from './sidebar/sidebar.component';
@ -130,7 +130,7 @@ export function getBaseHref(platformLocation: PlatformLocation): string {
ApiService,
GraphService,
CacheService,
SettingsService,
SettingsService,
MatDatepickerModule,
{provide: DateAdapter, useClass: CustomDateAdapter },
{provide: 'APP_ENVIRONMENT', useClass: ThisEnvironment},

View File

@ -1,11 +1,13 @@
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. */
@Injectable()
export class CustomDateAdapter extends NativeDateAdapter {
getFirstDayOfWeek(): number {
return 1;
}
}
}

View File

@ -1,19 +1,43 @@
import { ComponentFixture, TestBed } from '@angular/core/testing';
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', () => {
let component: GraphsComponent;
let fixture: ComponentFixture<GraphsComponent>;
beforeEach(async () => {
await TestBed.configureTestingModule({
declarations: [ GraphsComponent ]
})
.compileComponents();
});
let httpMock: HttpTestingController;
const mockEnvironment = new MockEnvironment();
const mockRouter = {
createUrlTree: jasmine.createSpy('createUrlTree'),
navigate: jasmine.createSpy('navigate')
};
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);
component = fixture.componentInstance;
fixture.detectChanges();

View File

@ -1,13 +1,43 @@
import { TestBed } from '@angular/core/testing';
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', () => {
let httpMock: HttpTestingController;
let location: Location;
let service: GraphService;
const mockEnvironment = new MockEnvironment();
const mockRouter = {
createUrlTree: jasmine.createSpy('createUrlTree'),
navigate: jasmine.createSpy('navigate')
};
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);
location = TestBed.inject(Location);
});
it('should be created', () => {