Skip to content

Commit

Permalink
Test for #17
Browse files Browse the repository at this point in the history
  • Loading branch information
JoshuaHamann committed Apr 7, 2020
1 parent c9ec108 commit 5a531c4
Show file tree
Hide file tree
Showing 2 changed files with 59 additions and 28 deletions.
85 changes: 58 additions & 27 deletions client/src/app/notes/note-card.component.spec.ts
Original file line number Diff line number Diff line change
@@ -1,38 +1,69 @@
import { async, ComponentFixture, TestBed } from '@angular/core/testing';

import { NoteCardComponent } from './note-card.component';
import { BrowserAnimationsModule } from '@angular/platform-browser/animations';
import { FormsModule } from '@angular/forms';
import { MatButtonModule } from '@angular/material/button';
import { MatCardModule } from '@angular/material/card';
import { MatOptionModule } from '@angular/material/core';
import { MatDividerModule } from '@angular/material/divider';
import { MatExpansionModule } from '@angular/material/expansion';
import { MatFormFieldModule } from '@angular/material/form-field';
import { MatInputModule } from '@angular/material/input';
import { MatListModule } from '@angular/material/list';
import { MatRadioModule } from '@angular/material/radio';
import { MatSelectModule } from '@angular/material/select';
import { MatTooltipModule } from '@angular/material/tooltip';
import { BrowserAnimationsModule } from '@angular/platform-browser/animations';
import { RouterTestingModule } from '@angular/router/testing';
import { Observable } from 'rxjs';
import { MockNoteService } from '../../testing/note.service.mock';
import { Note } from './note';
import { NoteCardComponent } from './note-card.component';
import { NoteService } from './note.service';
import { MatIconModule } from '@angular/material/icon';
import { splitClasses } from '@angular/compiler';

const COMMON_IMPORTS: any[] = [
FormsModule,
MatCardModule,
MatFormFieldModule,
MatSelectModule,
MatOptionModule,
MatButtonModule,
MatInputModule,
MatExpansionModule,
MatTooltipModule,
MatListModule,
MatDividerModule,
MatRadioModule,
MatIconModule,
BrowserAnimationsModule,
RouterTestingModule,
];

describe('NoteCardComponent', () => {
let component: NoteCardComponent;
let noteCard: NoteCardComponent;
let fixture: ComponentFixture<NoteCardComponent>;

beforeEach(async(() => {
beforeEach(() => {
TestBed.configureTestingModule({
imports: [
BrowserAnimationsModule,
MatCardModule
],
declarations: [ NoteCardComponent ]
})
.compileComponents();
imports: [COMMON_IMPORTS],
declarations: [NoteCardComponent],
providers: [{ provide: NoteService, useValue: new MockNoteService() }]
});
});

beforeEach(async(() => {
TestBed.compileComponents().then(() => {
fixture = TestBed.createComponent(NoteCardComponent);
noteCard = fixture.componentInstance;
fixture.detectChanges();
});
}));
/* Create a mock note here and create some more tests
beforeEach(() => {
fixture = TestBed.createComponent(NoteCardComponent);
component = fixture.componentInstance;
component.note = {
_id: '588935f57546a2daea44de7c',
name: 'Rachael Johnson',
officeID: '1310',
email: '[email protected]',
building: 'Science'
};
fixture.detectChanges();

it('contains all the notes', () => {
expect(noteCard.serverFilteredNotes.length).toBe(3);
});
*/
it('should create', () => {
expect(component).toBeTruthy();

it('contains a message \'Spirate pur, Spirate\'', () => {
expect(noteCard.serverFilteredNotes.some((note: Note) => note.message === 'Spirate pur, Spirate')).toBe(true);
});
});
2 changes: 1 addition & 1 deletion client/src/app/notes/note.service.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ describe('Note service: ', () => {
});

it('getOwnerNotes() calls api/notes', () => {
noteService.getOwnerNotes({ owner_id: '588935f57546a2daea44de7c' }).subscribe(
noteService.getNotes({ owner_id: '588935f57546a2daea44de7c' }).subscribe(
notes => expect(notes).toEqual(testNotes)
);
// not sure about this test
Expand Down

0 comments on commit 5a531c4

Please sign in to comment.