Commit 85fbea43 authored by Samantha Ming's avatar Samantha Ming

Add polling to security training url

Issue: https://gitlab.com/gitlab-org/gitlab/-/issues/355132
parent b6008e3f
...@@ -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