summaryrefslogtreecommitdiff
path: root/spec/javascripts/importer_status_spec.js
blob: bb49c576e9104bb26310e01f5cb6b68c1827e300 (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
import { ImporterStatus } from '~/importer_status';
import axios from '~/lib/utils/axios_utils';
import MockAdapter from 'axios-mock-adapter';

describe('Importer Status', () => {
  describe('addToImport', () => {
    let instance;
    let mock;
    const importUrl = '/import_url';

    beforeEach(() => {
      setFixtures(`
        <tr id="repo_123">
          <td class="import-target"></td>
          <td class="import-actions job-status">
            <button name="button" type="submit" class="btn btn-import js-add-to-import">
            </button>
          </td>
        </tr>
      `);
      spyOn(ImporterStatus.prototype, 'initStatusPage').and.callFake(() => {});
      spyOn(ImporterStatus.prototype, 'setAutoUpdate').and.callFake(() => {});
      instance = new ImporterStatus('', importUrl);
      mock = new MockAdapter(axios);
    });

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

    it('sets table row to active after post request', (done) => {
      mock.onPost(importUrl).reply(200, {
        id: 1,
        full_path: '/full_path',
      });

      instance.addToImport({
        currentTarget: document.querySelector('.js-add-to-import'),
      })
      .then(() => {
        expect(document.querySelector('tr').classList.contains('active')).toEqual(true);
        done();
      })
      .catch(done.fail);
    });
  });
});