summaryrefslogtreecommitdiff
path: root/spec/frontend/issuable_form_spec.js
blob: 009ca28ff78a7d08d3591ab4173629693cf82dcc (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
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
      ${'wip '}
      ${'    wIP: '}
      ${'[WIp] '}
      ${'wIP:'}
      ${'   [WIp]'}
      ${'drAft '}
      ${'draFT: '}
      ${'  [DRaft] '}
      ${'drAft:'}
      ${'[draFT]'}
      ${' dRaFt - '}
      ${'dRaFt -      '}
      ${'(draft) '}
      ${' (DrafT)'}
      ${'wip wip: [wip] 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");
    });
  });
});