framadate-responsive/mocks/old-stuff/pages/voting/voting-choice/voting-choice.component.spec.ts
2021-04-29 10:41:47 +02:00

82 lines
2.8 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 '../../../mocks/choice';
import { mockPoll3 } from '../../../mocks/mock-poll3';
const routerSpy = jest.fn({ navigateByUrl: jest.fn() });
describe('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();
});
});