summaryrefslogtreecommitdiff
path: root/web-ui/src/login/page.spec.js
blob: 05607ecb9a033ebfb9cbb4259a101ae04f8f3a2c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
import { shallow } from 'enzyme';
import expect from 'expect';
import React from 'react';
import { Page } from 'src/login/page';
import AuthError from 'src/login/error/auth_error';
import GenericError from 'src/login/error/generic_error';
import Welcome from 'src/login/about/welcome';

describe('Login', () => {
  let page;
  const mockTranslations = key => key;

  it('renders login form', () => {
    page = shallow(<Page t={mockTranslations} />);
    expect(page.find('form').props().action).toEqual('/login');
  });

  it('renders welcome message when no error', () => {
    page = shallow(<Page t={mockTranslations} />);
    expect(page.find(Welcome).length).toEqual(1);
  });

  it('renders auth error message', () => {
    page = shallow(<Page t={mockTranslations} authError />);
    expect(page.find(AuthError).length).toEqual(1);
  });

  it('renders generic error message when error', () => {
    page = shallow(<Page t={mockTranslations} error />);
    expect(page.find(GenericError).length).toEqual(1);
  });

  it('does not render welcome message when error', () => {
    page = shallow(<Page t={mockTranslations} error />);
    expect(page.find(Welcome).length).toEqual(0);
  });

  it('does not render error message', () => {
    page = shallow(<Page t={mockTranslations} />);
    expect(page.find(AuthError).length).toEqual(0);
    expect(page.find(GenericError).length).toEqual(0);
  });

  it('adds small logo class when error', () => {
    page = shallow(<Page t={mockTranslations} error />);
    expect(page.find('.logo').props().className).toEqual('logo small-logo');
  });

  it('does not add small logo class when no error', () => {
    page = shallow(<Page t={mockTranslations} />);
    expect(page.find('.logo').props().className).toEqual('logo');
  });
});