funky-framadate-front/src/app/pages/voting/voting-choice/voting-choice.component.spe...

85 lines
3.2 KiB
TypeScript

import {async, ComponentFixture, TestBed} from '@angular/core/testing';
import {FormsModule} from "@angular/forms";
import {HttpClient, HttpClientModule} from "@angular/common/http";
import {BrowserModule} from "@angular/platform-browser";
import {CommonModule} from "@angular/common";
import {ConfirmationService, MessageService} from "primeng";
import {Router} from "@angular/router";
import {ConfigService} from "../../../services/config.service";
import {VotingChoiceComponent} from './voting-choice.component';
import {mockChoice} from "../../../config/mocks/choice";
import {mockPoll3} from "../../../config/mocks/mock-poll3";
const routerSpy = jasmine.createSpyObj('Router', ['navigateByUrl']);
fdescribe('VotingChoiceComponent', () => {
let component: VotingChoiceComponent;
let fixture: ComponentFixture<VotingChoiceComponent>;
beforeEach(async(() => {
TestBed.configureTestingModule({
imports: [FormsModule,
BrowserModule,
CommonModule,
HttpClientModule],
declarations: [VotingChoiceComponent]
, providers: [HttpClient,
MessageService,
ConfirmationService,
ConfigService,
{provide: Router, useValue: routerSpy}]
})
.compileComponents();
}));
beforeEach(() => {
fixture = TestBed.createComponent(VotingChoiceComponent);
component = fixture.componentInstance;
component.choice = {...mockChoice};
component.choices_count = mockPoll3.choices_count;
component.choice_id = mockChoice.id;
component.poll = mockPoll3.poll;
fixture.detectChanges();
});
it('should create', () => {
expect(component).toBeTruthy();
});
it('should have nothing specified as an answer by default', () => {
expect(component.choice.answer).toBeFalsy();
});
it('should set answer to yes', () => {
component.setAnswserTo('yes');
expect(component.choice.answer).toBe('yes');
});
it('should set answer to maybe', () => {
component.setAnswserTo('maybe');
expect(component.choice.answer).toBe('maybe');
});
it('should set answer to no', () => {
component.setAnswserTo('no');
expect(component.choice.answer).toBe('no');
});
it('should set answer to no after 2 set on yes', () => {
component.setAnswserTo('yes');
component.setAnswserTo('yes');
expect(component.choice.answer).toBe('no');
});
it('should stay on maybe after 2 set on maybe', () => {
component.setAnswserTo('maybe');
component.setAnswserTo('maybe');
expect(component.choice.answer).toBe('maybe');
});
it('should stay on no after 2 set on no', () => {
component.setAnswserTo('no');
component.setAnswserTo('no');
expect(component.choice.answer).toBe('no');
});
it('should consider to have simple answer when allowedAnswers is only one answer long, which is yes', () => {
expect(component.poll.allowedAnswers[0]).toBe('yes');
expect(component.poll.allowedAnswers.length).toBe(1);
expect(component.simpleAnswer).toBeTruthy();
});
});