summaryrefslogtreecommitdiff
path: root/ui/test/components/confirmation.js
blob: a563fb3f3073b87ec1e268ab64951963db85b6c6 (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
54
55
56
57
import React from 'react';
import {shallow} from 'enzyme';
import chaiEnzyme from 'chai-enzyme'
import Confirmation from '../../app/components/confirmation';
import chai, { expect } from 'chai'


describe('Confirmation Component', () => {

  const simpleFunction0 = () => {return 0}
  const simpleFunction1 = () => {return 1}

  it('Passed functionss run on click', () => {
    const confirmation = shallow(
      <Confirmation
          onAccept={simpleFunction0}
          onCancel={simpleFunction1}
      />
    )

    expect(confirmation.find('Button').get(0).props.onClick()).to.equal(simpleFunction0())
    expect(confirmation.find('Button').get(1).props.onClick()).to.equal(simpleFunction1())
  })

  it('sets defaults correctly', () => {
    const confirmation = shallow(
      <Confirmation
          onAccept={simpleFunction0}
          onCancel={simpleFunction1}
      />
    )

    expect(confirmation.find("ModalTitle").first().children()).to.have.text("Are you sure?")
    expect(confirmation.find('Button').at(0).children().first()).to.have.text("Accept")
    expect(confirmation.find('Button').at(1).children().first()).to.have.text("Cancel")
  })

  it('overwrites defaults correctly', () => {
    const testTitle = "Test Title"
    const testAcceptStr = "Test accept string"
    const testCancelStr = "Test cancel string"

    const confirmation = shallow(
      <Confirmation
          onAccept={simpleFunction0}
          onCancel={simpleFunction1}
          title={testTitle}
          acceptStr={testAcceptStr}
          cancelStr={testCancelStr}
      />
    )

    expect(confirmation.find("ModalTitle").first().children()).to.have.text(testTitle)
    expect(confirmation.find('Button').at(0).children().first()).to.have.text(testAcceptStr)
    expect(confirmation.find('Button').at(1).children().first()).to.have.text(testCancelStr)
  })
})