Commit 414308a7 authored by Martin Wortschack's avatar Martin Wortschack

Merge branch...

Merge branch '224583-refactor-dag_spec-js-to-use-async-await-and-remove-repeated-code' into 'master'

Resolve "Refactor dag_spec.js to use async await"

See merge request gitlab-org/gitlab!35549
parents 2d3fc0b4 6a8eee14
...@@ -84,20 +84,19 @@ describe('Pipeline DAG graph wrapper', () => { ...@@ -84,20 +84,19 @@ describe('Pipeline DAG graph wrapper', () => {
describe('when there is a dataUrl', () => { describe('when there is a dataUrl', () => {
describe('but the data fetch fails', () => { describe('but the data fetch fails', () => {
beforeEach(() => { beforeEach(async () => {
mock.onGet(dataPath).replyOnce(500); mock.onGet(dataPath).replyOnce(500);
createComponent({ graphUrl: dataPath }); createComponent({ graphUrl: dataPath });
await wrapper.vm.$nextTick();
return waitForPromises();
}); });
it('shows the LOAD_FAILURE alert and not the graph', () => { it('shows the LOAD_FAILURE alert and not the graph', () => {
return wrapper.vm expect(getAlert().exists()).toBe(true);
.$nextTick() expect(getAlert().text()).toBe(getErrorText(LOAD_FAILURE));
.then(waitForPromises) expect(getGraph().exists()).toBe(false);
.then(() => {
expect(getAlert().exists()).toBe(true);
expect(getAlert().text()).toBe(getErrorText(LOAD_FAILURE));
expect(getGraph().exists()).toBe(false);
});
}); });
it('does not render the empty state', () => { it('does not render the empty state', () => {
...@@ -106,20 +105,19 @@ describe('Pipeline DAG graph wrapper', () => { ...@@ -106,20 +105,19 @@ describe('Pipeline DAG graph wrapper', () => {
}); });
describe('the data fetch succeeds but the parse fails', () => { describe('the data fetch succeeds but the parse fails', () => {
beforeEach(() => { beforeEach(async () => {
mock.onGet(dataPath).replyOnce(200, unparseableGraph); mock.onGet(dataPath).replyOnce(200, unparseableGraph);
createComponent({ graphUrl: dataPath }); createComponent({ graphUrl: dataPath });
await wrapper.vm.$nextTick();
return waitForPromises();
}); });
it('shows the PARSE_FAILURE alert and not the graph', () => { it('shows the PARSE_FAILURE alert and not the graph', () => {
return wrapper.vm expect(getAlert().exists()).toBe(true);
.$nextTick() expect(getAlert().text()).toBe(getErrorText(PARSE_FAILURE));
.then(waitForPromises) expect(getGraph().exists()).toBe(false);
.then(() => {
expect(getAlert().exists()).toBe(true);
expect(getAlert().text()).toBe(getErrorText(PARSE_FAILURE));
expect(getGraph().exists()).toBe(false);
});
}); });
it('does not render the empty state', () => { it('does not render the empty state', () => {
...@@ -128,133 +126,103 @@ describe('Pipeline DAG graph wrapper', () => { ...@@ -128,133 +126,103 @@ describe('Pipeline DAG graph wrapper', () => {
}); });
describe('and the data fetch and parse succeeds', () => { describe('and the data fetch and parse succeeds', () => {
beforeEach(() => { beforeEach(async () => {
mock.onGet(dataPath).replyOnce(200, mockBaseData); mock.onGet(dataPath).replyOnce(200, mockBaseData);
createComponent({ graphUrl: dataPath }, mount); createComponent({ graphUrl: dataPath }, mount);
await wrapper.vm.$nextTick();
return waitForPromises();
}); });
it('shows the graph and not the beta alert', () => { it('shows the graph and the beta alert', () => {
return wrapper.vm expect(getAllAlerts().length).toBe(1);
.$nextTick() expect(getAlert().text()).toContain('This feature is currently in beta.');
.then(waitForPromises) expect(getGraph().exists()).toBe(true);
.then(() => {
expect(getAllAlerts().length).toBe(1);
expect(getAlert().text()).toContain('This feature is currently in beta.');
expect(getGraph().exists()).toBe(true);
});
}); });
it('does not render the empty state', () => { it('does not render the empty state', () => {
return wrapper.vm expect(getEmptyState().exists()).toBe(false);
.$nextTick()
.then(waitForPromises)
.then(() => {
expect(getEmptyState().exists()).toBe(false);
});
}); });
}); });
describe('the data fetch and parse succeeds, but the resulting graph is too small', () => { describe('the data fetch and parse succeeds, but the resulting graph is too small', () => {
beforeEach(() => { beforeEach(async () => {
mock.onGet(dataPath).replyOnce(200, tooSmallGraph); mock.onGet(dataPath).replyOnce(200, tooSmallGraph);
createComponent({ graphUrl: dataPath }); createComponent({ graphUrl: dataPath });
await wrapper.vm.$nextTick();
return waitForPromises();
}); });
it('shows the UNSUPPORTED_DATA alert and not the graph', () => { it('shows the UNSUPPORTED_DATA alert and not the graph', () => {
return wrapper.vm expect(getAlert().exists()).toBe(true);
.$nextTick() expect(getAlert().text()).toBe(getErrorText(UNSUPPORTED_DATA));
.then(waitForPromises) expect(getGraph().exists()).toBe(false);
.then(() => {
expect(getAlert().exists()).toBe(true);
expect(getAlert().text()).toBe(getErrorText(UNSUPPORTED_DATA));
expect(getGraph().exists()).toBe(false);
});
}); });
it('does not show the empty dag graph state', () => { it('does not show the empty dag graph state', () => {
return wrapper.vm expect(getEmptyState().exists()).toBe(false);
.$nextTick()
.then(waitForPromises)
.then(() => {
expect(getEmptyState().exists()).toBe(false);
});
}); });
}); });
describe('the data fetch and parse succeeds, but the resulting graph is empty', () => { describe('the data fetch succeeds but the returned data is empty', () => {
beforeEach(() => { beforeEach(async () => {
mock.onGet(dataPath).replyOnce(200, graphWithoutDependencies); mock.onGet(dataPath).replyOnce(200, graphWithoutDependencies);
createComponent({ graphUrl: dataPath }, mount); createComponent({ graphUrl: dataPath }, mount);
await wrapper.vm.$nextTick();
return waitForPromises();
}); });
it('does not render an error alert or the graph', () => { it('does not render an error alert or the graph', () => {
return wrapper.vm expect(getAllAlerts().length).toBe(1);
.$nextTick() expect(getAlert().text()).toContain('This feature is currently in beta.');
.then(waitForPromises) expect(getGraph().exists()).toBe(false);
.then(() => {
expect(getAllAlerts().length).toBe(1);
expect(getAlert().text()).toContain('This feature is currently in beta.');
expect(getGraph().exists()).toBe(false);
});
}); });
it('shows the empty dag graph state', () => { it('shows the empty dag graph state', () => {
return wrapper.vm expect(getEmptyState().exists()).toBe(true);
.$nextTick()
.then(waitForPromises)
.then(() => {
expect(getEmptyState().exists()).toBe(true);
});
}); });
}); });
}); });
describe('annotations', () => { describe('annotations', () => {
beforeEach(() => { beforeEach(async () => {
mock.onGet(dataPath).replyOnce(200, mockBaseData); mock.onGet(dataPath).replyOnce(200, mockBaseData);
createComponent({ graphUrl: dataPath }, mount); createComponent({ graphUrl: dataPath }, mount);
await wrapper.vm.$nextTick();
return waitForPromises();
}); });
it('toggles on link mouseover and mouseout', () => { it('toggles on link mouseover and mouseout', async () => {
const currentNote = singleNote['dag-link103']; const currentNote = singleNote['dag-link103'];
expect(getNotes().exists()).toBe(false); expect(getNotes().exists()).toBe(false);
return wrapper.vm getGraph().vm.$emit('update-annotation', { type: ADD_NOTE, data: currentNote });
.$nextTick() await wrapper.vm.$nextTick();
.then(waitForPromises) expect(getNotes().exists()).toBe(true);
.then(() => {
getGraph().vm.$emit('update-annotation', { type: ADD_NOTE, data: currentNote }); getGraph().vm.$emit('update-annotation', { type: REMOVE_NOTE, data: currentNote });
return wrapper.vm.$nextTick(); await wrapper.vm.$nextTick();
}) expect(getNotes().exists()).toBe(false);
.then(() => {
expect(getNotes().exists()).toBe(true);
getGraph().vm.$emit('update-annotation', { type: REMOVE_NOTE, data: currentNote });
return wrapper.vm.$nextTick();
})
.then(() => {
expect(getNotes().exists()).toBe(false);
});
}); });
it('toggles on node and link click', () => { it('toggles on node and link click', async () => {
expect(getNotes().exists()).toBe(false); expect(getNotes().exists()).toBe(false);
return wrapper.vm getGraph().vm.$emit('update-annotation', { type: REPLACE_NOTES, data: multiNote });
.$nextTick() await wrapper.vm.$nextTick();
.then(waitForPromises) expect(getNotes().exists()).toBe(true);
.then(() => {
getGraph().vm.$emit('update-annotation', { type: REPLACE_NOTES, data: multiNote }); getGraph().vm.$emit('update-annotation', { type: REPLACE_NOTES, data: {} });
return wrapper.vm.$nextTick(); await wrapper.vm.$nextTick();
}) expect(getNotes().exists()).toBe(false);
.then(() => {
expect(getNotes().exists()).toBe(true);
getGraph().vm.$emit('update-annotation', { type: REPLACE_NOTES, data: {} });
return wrapper.vm.$nextTick();
})
.then(() => {
expect(getNotes().exists()).toBe(false);
});
}); });
}); });
}); });
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