2019-08-01 01:54:52 -04:00
|
|
|
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;
|
2019-10-22 23:06:01 -04:00
|
|
|
const CREATE = true;
|
|
|
|
const UPDATE = false;
|
2019-08-01 01:54:52 -04:00
|
|
|
|
2019-10-22 23:06:01 -04:00
|
|
|
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>`;
|
2019-08-01 01:54:52 -04:00
|
|
|
|
2019-10-22 23:06:01 -04:00
|
|
|
const init = newPage => {
|
|
|
|
setHTMLFixture(editFormHtmlFixture(newPage));
|
|
|
|
titleInput = document.getElementById('wiki_page_title');
|
|
|
|
messageInput = document.getElementById('wiki_page_message');
|
|
|
|
wikis = new Wikis();
|
|
|
|
};
|
2019-08-01 01:54:52 -04:00
|
|
|
|
2019-10-22 23:06:01 -04:00
|
|
|
describe('when the wiki page is being created', () => {
|
|
|
|
beforeEach(() => init(CREATE));
|
2019-08-01 01:54:52 -04:00
|
|
|
|
|
|
|
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', () => {
|
2019-10-22 23:06:01 -04:00
|
|
|
beforeEach(() => init(UPDATE));
|
2019-08-01 01:54:52 -04:00
|
|
|
|
|
|
|
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');
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|