Commit aba59df1 authored by Denys Mishunov's avatar Denys Mishunov

Minor refactoring of the spec

As per review
parent 2fffee26
...@@ -36,6 +36,11 @@ describe('Markdown Extension for Source Editor', () => { ...@@ -36,6 +36,11 @@ describe('Markdown Extension for Source Editor', () => {
const selectionToString = () => instance.getSelection().toString(); const selectionToString = () => instance.getSelection().toString();
const positionToString = () => instance.getPosition().toString(); const positionToString = () => instance.getPosition().toString();
const togglePreview = async () => {
instance.togglePreview();
await waitForPromises();
};
beforeEach(() => { beforeEach(() => {
setFixtures('<div id="editor" data-editor-loading></div>'); setFixtures('<div id="editor" data-editor-loading></div>');
editorEl = document.getElementById('editor'); editorEl = document.getElementById('editor');
...@@ -159,38 +164,32 @@ describe('Markdown Extension for Source Editor', () => { ...@@ -159,38 +164,32 @@ describe('Markdown Extension for Source Editor', () => {
}); });
it('toggles visibility of the preview DOM element', async () => { it('toggles visibility of the preview DOM element', async () => {
instance.togglePreview(); await togglePreview();
await waitForPromises();
expect(instance.previewEl.style.display).toBe('block'); expect(instance.previewEl.style.display).toBe('block');
instance.togglePreview(); await togglePreview();
await waitForPromises();
expect(instance.previewEl.style.display).toBe('none'); expect(instance.previewEl.style.display).toBe('none');
}); });
describe('hidden preview DOM element', () => { describe('hidden preview DOM element', () => {
it('shows error notification if fetching content fails', async () => { it('shows error notification if fetching content fails', async () => {
axios.post.mockImplementation(() => Promise.reject()); axios.post.mockImplementation(() => Promise.reject());
instance.togglePreview(); await togglePreview();
await waitForPromises();
expect(createFlash).toHaveBeenCalled(); expect(createFlash).toHaveBeenCalled();
}); });
it('fetches preview content and puts into the preview DOM element', async () => { it('fetches preview content and puts into the preview DOM element', async () => {
instance.togglePreview(); await togglePreview();
await waitForPromises();
expect(instance.previewEl.innerHTML).toEqual(responseData); expect(instance.previewEl.innerHTML).toEqual(responseData);
}); });
it('applies syntax highlighting to the preview content', async () => { it('applies syntax highlighting to the preview content', async () => {
instance.togglePreview(); await togglePreview();
await waitForPromises();
expect(syntaxHighlight).toHaveBeenCalled(); expect(syntaxHighlight).toHaveBeenCalled();
}); });
it('listens to model changes and re-fetches preview', async () => { it('listens to model changes and re-fetches preview', async () => {
expect(axios.post).not.toHaveBeenCalled(); expect(axios.post).not.toHaveBeenCalled();
instance.togglePreview(); await togglePreview();
await waitForPromises();
expect(axios.post).toHaveBeenCalledTimes(1); expect(axios.post).toHaveBeenCalledTimes(1);
instance.setValue('New Value'); instance.setValue('New Value');
...@@ -200,16 +199,14 @@ describe('Markdown Extension for Source Editor', () => { ...@@ -200,16 +199,14 @@ describe('Markdown Extension for Source Editor', () => {
it('stores disposable listener for model changes', async () => { it('stores disposable listener for model changes', async () => {
expect(instance.modelChangeListener).toBeUndefined(); expect(instance.modelChangeListener).toBeUndefined();
instance.togglePreview(); await togglePreview();
await waitForPromises();
expect(instance.modelChangeListener).toBeDefined(); expect(instance.modelChangeListener).toBeDefined();
}); });
}); });
describe('already visible preview', () => { describe('already visible preview', () => {
beforeEach(async () => { beforeEach(async () => {
instance.togglePreview(); await togglePreview();
await waitForPromises();
jest.clearAllMocks(); jest.clearAllMocks();
}); });
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment