Skip to content

Commit

Permalink
Added unit tests fixes to remove console output [#553]
Browse files Browse the repository at this point in the history
  • Loading branch information
mcpierce committed Dec 15, 2020
1 parent 492430c commit e6cb318
Show file tree
Hide file tree
Showing 17 changed files with 123 additions and 57 deletions.
15 changes: 13 additions & 2 deletions comixed-web/src/app/app.component.spec.ts
Expand Up @@ -37,6 +37,12 @@ import {
import { USER_READER } from '@app/user/user.fixtures';
import { loadSessionUpdate } from '@app/actions/session.actions';
import { setImportingComicsState } from '@app/library/actions/comic-import.actions';
import { NavigationBarComponent } from '@app/components/navigation-bar/navigation-bar.component';
import { MatDialogModule } from '@angular/material/dialog';
import { MatToolbarModule } from '@angular/material/toolbar';
import { MatMenuModule } from '@angular/material/menu';
import { MatIconModule } from '@angular/material/icon';
import { MatTooltipModule } from '@angular/material/tooltip';

describe('AppComponent', () => {
const USER = USER_READER;
Expand All @@ -56,12 +62,17 @@ describe('AppComponent', () => {

beforeEach(async(() => {
TestBed.configureTestingModule({
declarations: [AppComponent, NavigationBarComponent],
imports: [
RouterTestingModule,
TranslateModule.forRoot(),
LoggerModule.forRoot()
LoggerModule.forRoot(),
MatToolbarModule,
MatDialogModule,
MatMenuModule,
MatIconModule,
MatTooltipModule
],
declarations: [AppComponent],
providers: [provideMockStore({ initialState })]
}).compileComponents();

Expand Down
Expand Up @@ -28,15 +28,18 @@ import { Confirmation } from '@app/core/models/confirmation';
import { logoutUser } from '@app/user/actions/user.actions';
import {
initialState as initialUserState,
USER_FEATURE_KEY,
USER_FEATURE_KEY
} from '@app/user/reducers/user.reducer';
import { USER_ADMIN, USER_READER } from '@app/user/user.fixtures';
import { MatDialogModule } from '@angular/material/dialog';
import { MatMenuModule } from '@angular/material/menu';
import { MatIconModule } from '@angular/material/icon';
import { MatToolbarModule } from '@angular/material/toolbar';
import { MatTooltipModule } from '@angular/material/tooltip';

describe('NavigationBarComponent', () => {
const initialState = {
[USER_FEATURE_KEY]: { ...initialUserState, user: USER_ADMIN },
[USER_FEATURE_KEY]: { ...initialUserState, user: USER_ADMIN }
};

let component: NavigationBarComponent;
Expand All @@ -47,15 +50,18 @@ describe('NavigationBarComponent', () => {

beforeEach(async(() => {
TestBed.configureTestingModule({
declarations: [NavigationBarComponent],
imports: [
RouterTestingModule.withRoutes([{ path: '*', redirectTo: '' }]),
TranslateModule.forRoot(),
LoggerModule.forRoot(),
MatDialogModule,
MatMenuModule,
MatIconModule,
MatToolbarModule,
MatTooltipModule
],
declarations: [NavigationBarComponent],
providers: [provideMockStore({ initialState })],
providers: [provideMockStore({ initialState })]
}).compileComponents();

fixture = TestBed.createComponent(NavigationBarComponent);
Expand Down
Expand Up @@ -20,7 +20,7 @@ import { async, ComponentFixture, TestBed } from '@angular/core/testing';
import { ComicDetailCardComponent } from './comic-detail-card.component';
import { MatCardModule } from '@angular/material/card';

fdescribe('ComicDetailCardComponent', () => {
describe('ComicDetailCardComponent', () => {
let component: ComicDetailCardComponent;
let fixture: ComponentFixture<ComicDetailCardComponent>;

Expand Down
Expand Up @@ -17,22 +17,23 @@
*/

import { async, ComponentFixture, TestBed } from '@angular/core/testing';
import { CoverImageComponent } from './comic-page.component';
import { ComicPageComponent } from './comic-page.component';
import { LoggerModule } from '@angular-ru/logger';
import { MatCardModule } from '@angular/material/card';

describe('CoverImageComponent', () => {
const SOURCE = {} as any;

let component: CoverImageComponent;
let fixture: ComponentFixture<CoverImageComponent>;
let component: ComicPageComponent;
let fixture: ComponentFixture<ComicPageComponent>;

beforeEach(async(() => {
TestBed.configureTestingModule({
imports: [LoggerModule.forRoot()],
declarations: [CoverImageComponent],
declarations: [ComicPageComponent],
imports: [LoggerModule.forRoot(), MatCardModule]
}).compileComponents();

fixture = TestBed.createComponent(CoverImageComponent);
fixture = TestBed.createComponent(ComicPageComponent);
component = fixture.componentInstance;
fixture.detectChanges();
}));
Expand All @@ -52,13 +53,13 @@ describe('CoverImageComponent', () => {
});

it('sends the source of the event', () => {
component.pageClicked.subscribe((response) =>
component.pageClicked.subscribe(response =>
expect(response.source).toEqual(SOURCE)
);
});

it('sends a true selected value', () => {
component.pageClicked.subscribe((response) =>
component.pageClicked.subscribe(response =>
expect(response.selected).toBeTruthy()
);
});
Expand All @@ -75,13 +76,13 @@ describe('CoverImageComponent', () => {
});

it('sends the source of the event', () => {
component.pageClicked.subscribe((response) =>
component.pageClicked.subscribe(response =>
expect(response.source).toEqual(SOURCE)
);
});

it('sends a false selected value', () => {
component.pageClicked.subscribe((response) =>
component.pageClicked.subscribe(response =>
expect(response.selected).toBeFalsy()
);
});
Expand Down
Expand Up @@ -26,7 +26,7 @@ import { PageClickEvent } from '@app/core';
templateUrl: './comic-page.component.html',
styleUrls: ['./comic-page.component.scss']
})
export class CoverImageComponent {
export class ComicPageComponent {
@Input() imageTitle: string;
@Input() source: any;
@Input() imageUrl: string;
Expand Down
Expand Up @@ -24,6 +24,8 @@ import {
MatDialogRef
} from '@angular/material/dialog';
import { MatButtonModule } from '@angular/material/button';
import { MatIconModule } from '@angular/material/icon';
import { MatFormFieldModule } from '@angular/material/form-field';

describe('ConfirmationComponent', () => {
let component: ConfirmationComponent;
Expand All @@ -32,8 +34,14 @@ describe('ConfirmationComponent', () => {

beforeEach(async(() => {
TestBed.configureTestingModule({
imports: [MatDialogModule, MatButtonModule],
declarations: [ConfirmationComponent],
imports: [
MatDialogModule,
MatButtonModule,
MatIconModule,
MatButtonModule,
MatFormFieldModule
],
providers: [
{
provide: MatDialogRef,
Expand Down
6 changes: 3 additions & 3 deletions comixed-web/src/app/core/core.module.ts
Expand Up @@ -23,7 +23,7 @@ import { ConfirmationComponent } from './components/confirmation/confirmation.co
import { MatDialogModule } from '@angular/material/dialog';
import { MatIconModule } from '@angular/material/icon';
import { MatFormFieldModule } from '@angular/material/form-field';
import { CoverImageComponent } from './components/comic-page/comic-page.component';
import { ComicPageComponent } from './components/comic-page/comic-page.component';
import { StoreModule } from '@ngrx/store';
import {
BUSY_FEATURE_KEY,
Expand All @@ -39,7 +39,7 @@ import { MatProgressSpinnerModule } from '@angular/material/progress-spinner';
@NgModule({
declarations: [
ConfirmationComponent,
CoverImageComponent,
ComicPageComponent,
ComicDetailCardComponent
],
imports: [
Expand All @@ -60,7 +60,7 @@ import { MatProgressSpinnerModule } from '@angular/material/progress-spinner';
MatDialogModule,
MatIconModule,
MatFormFieldModule,
CoverImageComponent,
ComicPageComponent,
ComicDetailCardComponent
],
providers: []
Expand Down
Expand Up @@ -26,6 +26,11 @@ import { MockStore, provideMockStore } from '@ngrx/store/testing';
import { MatDialogModule } from '@angular/material/dialog';
import { ConfirmationService } from '@app/core';
import { Confirmation } from '@app/core/models/confirmation';
import { MatFormFieldModule } from '@angular/material/form-field';
import { MatToolbarModule } from '@angular/material/toolbar';
import { MatIconModule } from '@angular/material/icon';
import { MatInputModule } from '@angular/material/input';
import { NoopAnimationsModule } from '@angular/platform-browser/animations';

describe('ComicEditComponent', () => {
const COMIC = COMIC_2;
Expand All @@ -40,11 +45,16 @@ describe('ComicEditComponent', () => {
TestBed.configureTestingModule({
declarations: [ComicEditComponent],
imports: [
NoopAnimationsModule,
LoggerModule.forRoot(),
TranslateModule.forRoot(),
FormsModule,
ReactiveFormsModule,
MatDialogModule
MatDialogModule,
MatFormFieldModule,
MatToolbarModule,
MatIconModule,
MatInputModule
],
providers: [provideMockStore({}), ConfirmationService]
}).compileComponents();
Expand Down
Expand Up @@ -34,17 +34,15 @@ describe('ComicFileDetailsComponent', () => {
TestBed.configureTestingModule({
imports: [LoggerModule.forRoot()],
declarations: [ComicFileDetailsComponent],
providers: [provideMockStore({})],
providers: [provideMockStore({})]
}).compileComponents();
}));

beforeEach(() => {
fixture = TestBed.createComponent(ComicFileDetailsComponent);
component = fixture.componentInstance;
store = TestBed.inject(MockStore);
spyOn(store, 'dispatch');
fixture.detectChanges();
});
}));

it('should create', () => {
expect(component).toBeTruthy();
Expand Down
Expand Up @@ -46,13 +46,13 @@ describe('ComicFileListComponent', () => {

beforeEach(async(() => {
TestBed.configureTestingModule({
declarations: [ComicFileListComponent],
imports: [
TranslateModule.forRoot(),
LoggerModule.forRoot(),
MatTableModule,
MatCheckboxModule,
],
declarations: [ComicFileListComponent],
providers: [provideMockStore({ initialState })],
}).compileComponents();

Expand Down
Expand Up @@ -20,6 +20,9 @@ import { async, ComponentFixture, TestBed } from '@angular/core/testing';
import { ComicPagesComponent } from './comic-pages.component';
import { COMIC_2 } from '@app/library/library.fixtures';
import { ComicPageUrlPipe } from '@app/library/pipes/comic-page-url.pipe';
import { ComicPageComponent } from '@app/core/components/comic-page/comic-page.component';
import { LoggerModule } from '@angular-ru/logger';
import { MatCardModule } from '@angular/material/card';

describe('ComicPagesComponent', () => {
const COMIC = COMIC_2;
Expand All @@ -29,7 +32,8 @@ describe('ComicPagesComponent', () => {

beforeEach(async(() => {
TestBed.configureTestingModule({
declarations: [ComicPagesComponent, ComicPageUrlPipe]
declarations: [ComicPagesComponent, ComicPageComponent, ComicPageUrlPipe],
imports: [LoggerModule.forRoot(), MatCardModule]
}).compileComponents();

fixture = TestBed.createComponent(ComicPagesComponent);
Expand Down
Expand Up @@ -21,6 +21,8 @@ import { ComicStoryComponent } from './comic-story.component';
import { LoggerModule } from '@angular-ru/logger';
import { TranslateModule } from '@ngx-translate/core';
import { COMIC_2 } from '@app/library/library.fixtures';
import { MatExpansionModule } from '@angular/material/expansion';
import { NoopAnimationsModule } from '@angular/platform-browser/animations';

describe('ComicStoryComponent', () => {
const COMIC = COMIC_2;
Expand All @@ -31,7 +33,12 @@ describe('ComicStoryComponent', () => {
beforeEach(async(() => {
TestBed.configureTestingModule({
declarations: [ComicStoryComponent],
imports: [LoggerModule.forRoot(), TranslateModule.forRoot()]
imports: [
NoopAnimationsModule,
LoggerModule.forRoot(),
TranslateModule.forRoot(),
MatExpansionModule
]
}).compileComponents();

fixture = TestBed.createComponent(ComicStoryComponent);
Expand Down
Expand Up @@ -47,6 +47,7 @@ describe('ImportToolbarComponent', () => {

beforeEach(async(() => {
TestBed.configureTestingModule({
declarations: [ImportToolbarComponent],
imports: [
BrowserAnimationsModule,
FormsModule,
Expand All @@ -58,7 +59,6 @@ describe('ImportToolbarComponent', () => {
MatSelectModule,
MatInputModule,
],
declarations: [ImportToolbarComponent],
providers: [provideMockStore({ initialState })],
}).compileComponents();

Expand Down
Expand Up @@ -20,8 +20,8 @@ import { async, ComponentFixture, TestBed } from '@angular/core/testing';
import { ComicDetailsComponent } from './comic-details.component';
import { LoggerModule } from '@angular-ru/logger';
import {
LIBRARY_FEATURE_KEY,
initialState as initialLibraryState
initialState as initialLibraryState,
LIBRARY_FEATURE_KEY
} from '@app/library/reducers/library.reducer';
import { provideMockStore } from '@ngrx/store/testing';
import { RouterTestingModule } from '@angular/router/testing';
Expand All @@ -43,6 +43,8 @@ import { ComicEditComponent } from '@app/library/components/comic-edit/comic-edi
import { BehaviorSubject } from 'rxjs';
import { QUERY_PARAM_TAB } from '@app/library/library.constants';
import { ConfirmationService } from '@app/core';
import { MatCardModule } from '@angular/material/card';
import { MatToolbarModule } from '@angular/material/toolbar';

describe('ComicDetailsComponent', () => {
const COMIC = COMIC_1;
Expand All @@ -69,7 +71,9 @@ describe('ComicDetailsComponent', () => {
imports: [
LoggerModule.forRoot(),
TranslateModule.forRoot(),
RouterTestingModule
RouterTestingModule,
MatCardModule,
MatToolbarModule
],
providers: [
provideMockStore({ initialState }),
Expand Down
Expand Up @@ -57,7 +57,7 @@ export class ComicDetailsComponent implements OnInit, OnDestroy {
) {
this.paramSubscription = this.activatedRoute.params.subscribe(params => {
this.comicId = +params.comicId;
this.logger.debug('Found comic id parameter:', params.comicId);
this.logger.trace('Comic id parameter:', params.comicId);
this.store.dispatch(loadComic({ id: this.comicId }));
});
this.queryParamSubscription = this.activatedRoute.queryParams.subscribe(
Expand Down

0 comments on commit e6cb318

Please sign in to comment.