Fakultas Ilmu Komputer UI

CompanyRegisterModal-test.jsx 1.95 KB
Newer Older
1
2
3
4
5
6
7
8
9
import React from 'react';
import ReactTestUtils from 'react-addons-test-utils';
import CompanyRegisterModal from '../../components/CompanyRegisterModal';

describe('CompanyRegisterModal', () => {
    function validatePassword(password) {
        const lowerCaseLetters = /[a-z]/g;
        const upperCaseLetters = /[A-Z]/g;
        const numbers = /[0-9]/g;
Muhammad Ilham Peruzzi's avatar
Muhammad Ilham Peruzzi committed
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
        if(password.length < 8) { 
            return "Password less than 8";
        } else {
            if(!lowerCaseLetters.test(password)) {
                return "Password at least one lowercase letter";
            } 

            if(!upperCaseLetters.test(password)) { 
                return "Password at least one uppercase letter";
            }

            if(!numbers.test(password)) {
                return "Password at least one number";
            }
            
            return true
        }
27
28
29
30
31
32
33
34
    }

    it('renders without problem', () => {
        const companyRegister = ReactTestUtils.renderIntoDocument(
          <CompanyRegisterModal />);
        expect(companyRegister).to.exist;
    });

35
36
37
38
39
40
41
42
43
44
45
46
47
    it('renders form without problem', () => {
        const companyRegister = ReactTestUtils.renderIntoDocument(
          <CompanyRegisterModal />);
          const registerForm = ReactTestUtils.scryRenderedDOMComponentsWithTag(companyRegister, 'Form');
        expect(registerForm).to.exist;
    });

    it('renders category options without problem', () => {
        const companyRegister = ReactTestUtils.renderIntoDocument(
            <CompanyRegisterModal />);
        expect(companyRegister.categoryOptions).to.exist;
    });

48
49
50
51
    it('handle password validation', () => {
        const password = '3s24Aasd';
        expect(validatePassword(password)).to.equal(true);
    });
Vitosavero Avila Wibisono's avatar
Vitosavero Avila Wibisono committed
52
53
54
55
56
57

    it('Register modals state contain benefits', () => {
        const companyRegister = ReactTestUtils.renderIntoDocument(
            <CompanyRegisterModal />);
        expect(companyRegister.state.benefits).to.exist;
    });
58
});