Commit 32445387 authored by Savas Vedova's avatar Savas Vedova

Merge branch '355132-graphql-polling' into 'master'

Add polling to security training service graphql query

See merge request gitlab-org/gitlab!82653
parents b8709555 85fbea43
...@@ -52,13 +52,14 @@ export default { ...@@ -52,13 +52,14 @@ export default {
}, },
vulnerability: { vulnerability: {
query: securityTrainingVulnerabilityQuery, query: securityTrainingVulnerabilityQuery,
pollInterval: 5000,
update({ vulnerability }) { update({ vulnerability }) {
const allUrlsAreReady = vulnerability?.securityTrainingUrls?.every( const allUrlsAreReady = vulnerability?.securityTrainingUrls?.every(
({ status }) => status === SECURITY_TRAINING_URL_STATUS_COMPLETED, ({ status }) => status === SECURITY_TRAINING_URL_STATUS_COMPLETED,
); );
if (allUrlsAreReady) { if (allUrlsAreReady) {
// note: once we add polling, we can call `.stopPolling` here this.$apollo.queries.vulnerability.stopPolling();
this.isUrlsLoading = false; this.isUrlsLoading = false;
} }
......
...@@ -195,6 +195,28 @@ describe('VulnerabilityTraining component', () => { ...@@ -195,6 +195,28 @@ describe('VulnerabilityTraining component', () => {
}); });
}); });
describe('polling', () => {
beforeEach(() => {
createApolloProvider();
createComponent();
});
it('sets polling at 5000 ms', () => {
expect(wrapper.vm.$apollo.queries.vulnerability.options.pollInterval).toBe(5000);
});
it('stops polling when every training url status is completed', async () => {
jest
.spyOn(wrapper.vm.$apollo.queries.vulnerability, 'stopPolling')
.mockImplementation(jest.fn());
await waitForQueryToBeLoaded();
await nextTick();
expect(wrapper.vm.$apollo.queries.vulnerability.stopPolling).toHaveBeenCalled();
});
});
describe('training item', () => { describe('training item', () => {
it('displays correct number of training items', async () => { it('displays correct number of training items', async () => {
createApolloProvider(); createApolloProvider();
......
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