framadate-responsive/mocks/old-stuff/pages/voting/voting-choice/voting-choice.component.spec.ts

82 lines
2.8 KiB
TypeScript
Raw Normal View History

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';
2020-05-12 19:16:23 +02:00
import { mockChoice } from '../../../mocks/choice';
import { mockPoll3 } from '../../../mocks/mock-poll3';
2019-08-21 14:28:50 +02:00
2020-04-21 10:50:26 +02:00
const routerSpy = jest.fn({ navigateByUrl: jest.fn() });
2019-08-21 14:28:50 +02:00
describe('VotingChoiceComponent', () => {
2020-04-21 10:50:26 +02:00
let component: VotingChoiceComponent;
let fixture: ComponentFixture<VotingChoiceComponent>;
2019-08-21 14:28:50 +02:00
2020-04-21 10:50:26 +02: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-04-21 10:50:26 +02: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-04-21 10:50:26 +02: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
});