Commits

lotte authored 00039436b6f
more tests
No tags

src/app/entity-groups/research-entities/submission/item-list-elements/org-unit/org-unit-suggestions/org-unit-input-suggestions.component.spec.ts

Added
1 +import { async, ComponentFixture, TestBed } from '@angular/core/testing';
2 +import { ChangeDetectionStrategy, NO_ERRORS_SCHEMA } from '@angular/core';
3 +import { OrgUnitInputSuggestionsComponent } from './org-unit-input-suggestions.component';
4 +import { FormsModule } from '@angular/forms';
5 +
6 +let component: OrgUnitInputSuggestionsComponent;
7 +let fixture: ComponentFixture<OrgUnitInputSuggestionsComponent>;
8 +
9 +let suggestions: string[];
10 +let testValue;
11 +
12 +function init() {
13 + suggestions = ['test', 'suggestion', 'example']
14 + testValue = 'bla';
15 +}
16 +
17 +describe('OrgUnitInputSuggestionsComponent', () => {
18 + beforeEach(async(() => {
19 + init();
20 + TestBed.configureTestingModule({
21 + declarations: [OrgUnitInputSuggestionsComponent],
22 + imports: [
23 + FormsModule,
24 + ],
25 + providers: [
26 + ],
27 + schemas: [NO_ERRORS_SCHEMA]
28 + }).overrideComponent(OrgUnitInputSuggestionsComponent, {
29 + set: { changeDetection: ChangeDetectionStrategy.Default }
30 + }).compileComponents();
31 + }));
32 +
33 + beforeEach(async(() => {
34 + fixture = TestBed.createComponent(OrgUnitInputSuggestionsComponent);
35 + component = fixture.componentInstance;
36 + component.suggestions = suggestions;
37 + fixture.detectChanges();
38 + }));
39 +
40 + it('should create', () => {
41 + expect(component).toBeTruthy();
42 + });
43 +
44 + describe('When the component is initialized', () => {
45 + it('should set the value to the first value of the suggestions', () => {
46 + expect(component.value).toEqual('test');
47 + });
48 + });
49 +
50 + describe('When onSubmit is called', () => {
51 + it('should set the value to parameter of the method', () => {
52 + component.onSubmit(testValue);
53 + expect(component.value).toEqual(testValue);
54 + });
55 + });
56 +
57 + describe('When onClickSuggestion is called', () => {
58 + it('should set the value to parameter of the method', () => {
59 + component.onClickSuggestion(testValue);
60 + expect(component.value).toEqual(testValue);
61 + });
62 + });
63 +
64 +});

Everything looks good. We'll let you know here if there's anything you should know about.

Add shortcut