summaryrefslogtreecommitdiff
path: root/spec/frontend/issuable_form_spec.js
blob: c77fde4261e0b73f847494bc6e5e55422916e687 (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
import $ from 'jquery';

import IssuableForm from '~/issuable_form';

function createIssuable() {
  const instance = new IssuableForm($(document.createElement('form')));

  instance.titleField = $(document.createElement('input'));

  return instance;
}

describe('IssuableForm', () => {
  let instance;

  beforeEach(() => {
    instance = createIssuable();
  });

  describe('removeWip', () => {
    it.each`
      prefix
      ${'draFT: '}
      ${'  [DRaft] '}
      ${'drAft:'}
      ${'[draFT]'}
      ${'(draft) '}
      ${' (DrafT)'}
      ${'draft: [draft] (draft)'}
    `('removes "$prefix" from the beginning of the title', ({ prefix }) => {
      instance.titleField.val(`${prefix}The Issuable's Title Value`);

      instance.removeWip();

      expect(instance.titleField.val()).toBe("The Issuable's Title Value");
    });
  });

  describe('addWip', () => {
    it("properly adds the work in progress prefix to the Issuable's title", () => {
      instance.titleField.val("The Issuable's Title Value");

      instance.addWip();

      expect(instance.titleField.val()).toBe("Draft: The Issuable's Title Value");
    });
  });

  describe('workInProgress', () => {
    it.each`
      title                                 | expected
      ${'draFT: something is happening'}    | ${true}
      ${'draft something is happening'}     | ${false}
      ${'something is happening to drafts'} | ${false}
      ${'something is happening'}           | ${false}
    `('returns $expected with "$title"', ({ title, expected }) => {
      instance.titleField.val(title);

      expect(instance.workInProgress()).toBe(expected);
    });
  });
});