2020-02-05 15:21:28 +01:00
|
|
|
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";
|
2019-08-21 14:28:50 +02:00
|
|
|
|
2020-02-05 15:21:28 +01:00
|
|
|
const routerSpy = jasmine.createSpyObj('Router', ['navigateByUrl']);
|
2019-08-21 14:28:50 +02:00
|
|
|
|
2020-02-05 15:21:28 +01:00
|
|
|
fdescribe('VotingChoiceComponent', () => {
|
|
|
|
let component: VotingChoiceComponent;
|
|
|
|
let fixture: ComponentFixture<VotingChoiceComponent>;
|
2019-08-21 14:28:50 +02:00
|
|
|
|
2020-02-05 15:21:28 +01:00
|
|
|
beforeEach(async(() => {
|
|
|
|
TestBed.configureTestingModule({
|
|
|
|
imports: [FormsModule,
|
|
|
|
BrowserModule,
|
|
|
|
CommonModule,
|
|
|
|
HttpClientModule],
|
|
|
|
declarations: [VotingChoiceComponent]
|
|
|
|
, providers: [HttpClient,
|
|
|
|
MessageService,
|
|
|
|
ConfirmationService,
|
|
|
|
ConfigService,
|
|
|
|
{provide: Router, useValue: routerSpy}]
|
|
|
|
})
|
|
|
|
.compileComponents();
|
|
|
|
}));
|
2019-08-21 14:28:50 +02:00
|
|
|
|
2020-02-05 15:21:28 +01:00
|
|
|
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();
|
|
|
|
});
|
2019-08-21 14:28:50 +02:00
|
|
|
|
2020-02-05 15:21:28 +01:00
|
|
|
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();
|
|
|
|
});
|
2019-08-21 14:28:50 +02:00
|
|
|
});
|