| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134 |
- import { expect } from 'chai';
- import deepFreeze from 'deep-freeze';
- import {
- SHORTENER_ERROR,
- DOMAIN_ERROR,
- SET_DOMAIN,
- SHOW_DOMAIN_INPUT,
- ADD_URL,
- UPDATE_URL,
- AUTH_ERROR,
- AUTH_USER,
- HIDE_PAGE_LOADING
- } from '../../actions/actionTypes';
- import reducer from '../error';
- describe('error reducer', () => {
- const initialState = {
- auth: '',
- domain: '',
- shortener: '',
- urlOptions: ''
- };
- beforeEach(() => {
- deepFreeze(initialState);
- });
- it('should return the initial state', () => {
- expect(reducer(undefined, {})).to.deep.equal(initialState);
- });
- it('should handle SHORTENER_ERROR', () => {
- const error = 'SHORTENER_ERROR';
- const state = reducer(initialState, {
- type: SHORTENER_ERROR,
- payload: error
- });
- expect(state).not.to.be.undefined;
- expect(state.shortener).to.be.equal(error);
- });
- it('should handle DOMAIN_ERROR', () => {
- const error = 'DOMAIN_ERROR';
- const state = reducer(initialState, {
- type: DOMAIN_ERROR,
- payload: error
- });
- expect(state).not.to.be.undefined;
- expect(state.domain).to.be.equal(error);
- });
- it('should handle SET_DOMAIN', () => {
- const state = reducer(initialState, {
- type: SET_DOMAIN
- });
- expect(state).not.to.be.undefined;
- expect(state.domain).to.be.empty;
- });
- it('should handle SHOW_DOMAIN_INPUT', () => {
- const state = reducer(initialState, {
- type: SHOW_DOMAIN_INPUT
- });
- expect(state).not.to.be.undefined;
- expect(state.domain).to.be.empty;
- });
- it('should handle ADD_URL', () => {
- const state = reducer(initialState, {
- type: ADD_URL
- });
- expect(state).not.to.be.undefined;
- expect(state.shortener).to.be.empty;
- });
- it('should handle UPDATE_URL', () => {
- const state = reducer(initialState, {
- type: UPDATE_URL
- });
- expect(state).not.to.be.undefined;
- expect(state.urlOptions).to.be.empty;
- });
- it('should handle AUTH_ERROR', () => {
- const error = 'AUTH_ERROR';
- const state = reducer(initialState, {
- type: AUTH_ERROR,
- payload: error
- });
- expect(state).not.to.be.undefined;
- expect(state.auth).to.be.equal(error);
- });
- it('should handle AUTH_USER', () => {
- const state = reducer(initialState, {
- type: AUTH_USER
- });
- expect(state).not.to.be.undefined;
- expect(state.auth).to.be.empty;
- });
- it('should handle HIDE_PAGE_LOADING', () => {
- const state = reducer(initialState, {
- type: HIDE_PAGE_LOADING
- });
- expect(state).not.to.be.undefined;
- expect(state.auth).to.be.empty;
- expect(state.shortener).to.be.empty;
- expect(state.urlOptions).to.be.empty;
- });
- it('should not handle other action types', () => {
- const state = reducer(initialState, {
- type: 'ANOTHER_ACTION'
- });
- expect(state).not.to.be.undefined;
- expect(state).to.deep.equal(initialState);
- });
- });
|