Welcome to mirror list, hosted at ThFree Co, Russian Federation.

wikis_spec.js « frontend « spec - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: a2b68bf866e3c73995f96b9992b6a0f9126717ec (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
64
65
66
import Wikis from '~/pages/projects/wikis/wikis';
import { setHTMLFixture } from './helpers/fixtures';

describe('Wikis', () => {
  describe('setting the commit message when the title changes', () => {
    let wikis;
    let titleInput;
    let messageInput;
    const CREATE = true;
    const UPDATE = false;

    const editFormHtmlFixture = newPage =>
      `<form class="wiki-form ${newPage ? 'js-new-wiki-page' : ''}">
        <input type="text" id="wiki_page_title" value="My title" />
        <input type="text" id="wiki_page_message" />
      </form>`;

    const init = newPage => {
      setHTMLFixture(editFormHtmlFixture(newPage));
      titleInput = document.getElementById('wiki_page_title');
      messageInput = document.getElementById('wiki_page_message');
      wikis = new Wikis();
    };

    describe('when the wiki page is being created', () => {
      beforeEach(() => init(CREATE));

      it('binds an event listener to the title input', () => {
        wikis.handleWikiTitleChange = jest.fn();

        titleInput.dispatchEvent(new Event('keyup'));

        expect(wikis.handleWikiTitleChange).toHaveBeenCalled();
      });

      it('sets the commit message when title changes', () => {
        titleInput.value = 'My title';
        messageInput.value = '';

        titleInput.dispatchEvent(new Event('keyup'));

        expect(messageInput.value).toEqual('Create My title');
      });

      it('replaces hyphens with spaces', () => {
        titleInput.value = 'my-hyphenated-title';
        titleInput.dispatchEvent(new Event('keyup'));

        expect(messageInput.value).toEqual('Create my hyphenated title');
      });
    });

    describe('when the wiki page is being updated', () => {
      beforeEach(() => init(UPDATE));

      it('sets the commit message when title changes, prefixing with "Update"', () => {
        titleInput.value = 'My title';
        messageInput.value = '';

        titleInput.dispatchEvent(new Event('keyup'));

        expect(messageInput.value).toEqual('Update My title');
      });
    });
  });
});