BigW Consortium Gitlab

issuable_spec.js 1.68 KB
Newer Older
Phil Hughes committed
1 2
import MockAdaptor from 'axios-mock-adapter';
import axios from '~/lib/utils/axios_utils';
3 4 5 6 7 8 9 10
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();
11 12
    });

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

18 19
      Issuable = new IssuableIndex('issue_');
      expect(Issuable.bulkUpdateSidebar).toBeDefined();
20
    });
21
  });
22

23
  describe('resetIncomingEmailToken', () => {
Phil Hughes committed
24 25
    let mock;

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

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

36
      Issuable = new IssuableIndex('issue_');
Phil Hughes committed
37 38 39 40 41 42

      mock = new MockAdaptor(axios);

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

Phil Hughes committed
45 46 47 48 49 50
    afterEach(() => {
      mock.restore();
    });

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

Phil Hughes committed
53 54 55 56 57 58
      setTimeout(() => {
        expect(axios.put).toHaveBeenCalledWith('foo');
        expect($('#issuable_email').val()).toBe('testing123');

        done();
      });
59 60
    });
  });
61 62
});