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 {
},
vulnerability: {
query: securityTrainingVulnerabilityQuery,
pollInterval: 5000,
update({ vulnerability }) {
const allUrlsAreReady = vulnerability?.securityTrainingUrls?.every(
({ status }) => status === SECURITY_TRAINING_URL_STATUS_COMPLETED,
);
if (allUrlsAreReady) {
// note: once we add polling, we can call `.stopPolling` here
this.$apollo.queries.vulnerability.stopPolling();
this.isUrlsLoading = false;
}
......
......@@ -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', () => {
it('displays correct number of training items', async () => {
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