aboutsummaryrefslogtreecommitdiff
path: root/test/settings/components/form/blacklist-form.test.jsx
blob: 1c46943a5537f53e6bce6352dec4e01bbd57574a (plain) (blame)
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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
import { h, render } from 'preact';
import BlacklistForm from 'settings/components/form/blacklist-form'

describe("settings/form/BlacklistForm", () => {
  beforeEach(() => {
    document.body.innerHTML = '';
  });

  describe('render', () => {
    it('renders BlacklistForm', () => {
      render(<BlacklistForm value={['*.slack.com', 'www.google.com/maps']} />, document.body);

      let inputs = document.querySelectorAll('input[type=text]');
      expect(inputs).to.have.lengthOf(2);
      expect(inputs[0].value).to.equal('*.slack.com');
      expect(inputs[1].value).to.equal('www.google.com/maps');
    });

    it('renders blank value', () => {
      render(<BlacklistForm />, document.body);

      let inputs = document.querySelectorAll('input[type=text]');
      expect(inputs).to.be.empty;
    });

    it('renders blank value', () => {
      render(<BlacklistForm />, document.body);

      let inputs = document.querySelectorAll('input[type=text]');
      expect(inputs).to.be.empty;
    });
  });

  describe('onChange', () => {
    it('invokes onChange event on edit', (done) => {
      render(<BlacklistForm
        value={['*.slack.com', 'www.google.com/maps*']}
        onChange={value => {
          expect(value).to.have.lengthOf(2)
            .and.have.members(['gitter.im', 'www.google.com/maps*']);

          done();
        }}
      />, document.body);

      let input = document.querySelectorAll('input[type=text]')[0];
      input.value = 'gitter.im';
      input.dispatchEvent(new Event('change'))
    });

    it('invokes onChange event on delete', (done) => {
      render(<BlacklistForm
        value={['*.slack.com', 'www.google.com/maps*']}
        onChange={value => {
          expect(value).to.have.lengthOf(1)
            .and.have.members(['www.google.com/maps*']);

          done();
        }}
      />, document.body);

      let button = document.querySelectorAll('input[type=button]')[0];
      button.click();
    });

    it('invokes onChange event on add', (done) => {
      render(<BlacklistForm
        value={['*.slack.com']}
        onChange={value => {
          expect(value).to.have.lengthOf(2)
            .and.have.members(['*.slack.com', '']);

          done();
        }}
      />, document.body);

      let button = document.querySelector('input[type=button].ui-add-button');
      button.click();
    });
  });
});