summaryrefslogtreecommitdiff
path: root/spec/javascripts/issuable_spec.js
blob: 57bf746f080597db64c2ccb43ff29aca316d9564 (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
58
59
60
61
62
63
import $ from 'jquery';
import MockAdaptor from 'axios-mock-adapter';
import axios from '~/lib/utils/axios_utils';
import IssuableIndex from '~/issuable_index';

describe('Issuable', () => {
  let Issuable;
  describe('initBulkUpdate', () => {
    it('should not set bulkUpdateSidebar', () => {
      Issuable = new IssuableIndex('issue_');
      expect(Issuable.bulkUpdateSidebar).not.toBeDefined();
    });

    it('should set bulkUpdateSidebar', () => {
      const element = document.createElement('div');
      element.classList.add('issues-bulk-update');
      document.body.appendChild(element);

      Issuable = new IssuableIndex('issue_');
      expect(Issuable.bulkUpdateSidebar).toBeDefined();
    });
  });

  describe('resetIncomingEmailToken', () => {
    let mock;

    beforeEach(() => {
      const element = document.createElement('a');
      element.classList.add('incoming-email-token-reset');
      element.setAttribute('href', 'foo');
      document.body.appendChild(element);

      const input = document.createElement('input');
      input.setAttribute('id', 'issuable_email');
      document.body.appendChild(input);

      Issuable = new IssuableIndex('issue_');

      mock = new MockAdaptor(axios);

      mock.onPut('foo').reply(200, {
        new_address: 'testing123',
      });
    });

    afterEach(() => {
      mock.restore();
    });

    it('should send request to reset email token', (done) => {
      spyOn(axios, 'put').and.callThrough();
      document.querySelector('.incoming-email-token-reset').click();

      setTimeout(() => {
        expect(axios.put).toHaveBeenCalledWith('foo');
        expect($('#issuable_email').val()).toBe('testing123');

        done();
      });
    });
  });
});