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 {
},
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