Commit 99ccc8a6 authored by Alexander Turinske's avatar Alexander Turinske

Update no agent installed alert implementation

- account for scenario where an alert was added, but
  an agent was removed
- add tests
parent 8c7bf965
...@@ -31,7 +31,7 @@ export default { ...@@ -31,7 +31,7 @@ export default {
policyAlert: { type: Boolean, required: true }, policyAlert: { type: Boolean, required: true },
}, },
apollo: { apollo: {
isAgentInstalled: { agentCount: {
query: getAgentCount, query: getAgentCount,
variables() { variables() {
return { return {
...@@ -39,29 +39,31 @@ export default { ...@@ -39,29 +39,31 @@ export default {
}; };
}, },
update(data) { update(data) {
return Boolean(data?.project?.clusterAgents?.count); return data?.project?.clusterAgents?.count || 0;
}, },
}, },
}, },
data() { data() {
return { return {
isAgentInstalled: false, agentCount: 0,
}; };
}, },
computed: {
agentLoading() {
return this.$apollo.queries.agentCount.loading;
},
isAgentInstalled() {
return Boolean(this.agentCount) && !this.agentLoading;
},
spacingClass() {
return { 'gl-mt-5': !this.policyAlert && this.isAgentInstalled };
},
},
}; };
</script> </script>
<template> <template>
<div> <div>
<gl-alert
v-if="policyAlert"
variant="warning"
:dismissible="false"
class="gl-mt-5"
data-testid="policy-alert-high-volume"
>
{{ $options.i18n.HIGH_VOLUME_WARNING }}
</gl-alert>
<gl-alert <gl-alert
v-if="!isAgentInstalled" v-if="!isAgentInstalled"
variant="danger" variant="danger"
...@@ -82,9 +84,18 @@ export default { ...@@ -82,9 +84,18 @@ export default {
</template> </template>
</gl-sprintf> </gl-sprintf>
</gl-alert> </gl-alert>
<gl-alert
v-else-if="policyAlert"
variant="warning"
:dismissible="false"
class="gl-mt-5"
data-testid="policy-alert-high-volume"
>
{{ $options.i18n.HIGH_VOLUME_WARNING }}
</gl-alert>
<div <div
class="gl-bg-gray-10 gl-border-solid gl-border-1 gl-border-gray-100 gl-rounded-base gl-p-5" class="gl-bg-gray-10 gl-border-solid gl-border-1 gl-border-gray-100 gl-rounded-base gl-p-5"
:class="{ 'gl-mt-5': !policyAlert && isAgentInstalled }" :class="spacingClass"
> >
<gl-button <gl-button
v-if="!policyAlert" v-if="!policyAlert"
......
...@@ -21,11 +21,11 @@ describe('PolicyAlertPicker component', () => { ...@@ -21,11 +21,11 @@ describe('PolicyAlertPicker component', () => {
const defaultProps = { policyAlert: false }; const defaultProps = { policyAlert: false };
const findAddAlertButton = () => wrapper.find("[data-testid='add-alert']"); const findAddAlertButton = () => wrapper.findByTestId('add-alert');
const findAlertMessage = () => wrapper.findByTestId('policy-alert-message'); const findAlertMessage = () => wrapper.findByTestId('policy-alert-message');
const findHighVolumeAlert = () => wrapper.findByTestId('policy-alert-high-volume'); const findHighVolumeAlert = () => wrapper.findByTestId('policy-alert-high-volume');
const findNoAgentAlert = () => wrapper.findByTestId('policy-alert-no-agent'); const findNoAgentAlert = () => wrapper.findByTestId('policy-alert-no-agent');
const findRemoveAlertButton = () => wrapper.find("[data-testid='remove-alert']"); const findRemoveAlertButton = () => wrapper.findByTestId('remove-alert');
const createWrapper = async ({ propsData = defaultProps, agentCount = 1 } = {}) => { const createWrapper = async ({ propsData = defaultProps, agentCount = 1 } = {}) => {
const apolloProvider = createMockApolloProvider({ agentCount }); const apolloProvider = createMockApolloProvider({ agentCount });
...@@ -52,77 +52,129 @@ describe('PolicyAlertPicker component', () => { ...@@ -52,77 +52,129 @@ describe('PolicyAlertPicker component', () => {
wrapper = null; wrapper = null;
}); });
describe('default state', () => { describe('loading', () => {
beforeEach(async () => { describe('default state', () => {
await createWrapper(); beforeEach(async () => {
}); createWrapper();
});
it('does render the add alert button', () => { it('does render the enabled add alert button ', () => {
expect(findAddAlertButton().exists()).toBe(true); expect(findAddAlertButton().exists()).toBe(true);
}); expect(findAddAlertButton().props('disabled')).toBe(false);
});
it('does not render the high volume warning', () => {
expect(findHighVolumeAlert().exists()).toBe(false);
});
it('does not render the alert message', () => { it('does not render the "no agent" alert', () => {
expect(findAlertMessage().exists()).toBe(false); expect(findNoAgentAlert().exists()).toBe(false);
});
}); });
it('does not render the remove alert button', () => { describe('alert enabled', () => {
expect(findRemoveAlertButton().exists()).toBe(false); beforeEach(async () => {
}); createWrapper({ propsData: { policyAlert: true } });
});
it('does not show the "no agent" alert when there is an agent, ', () => { it('does render the "high volume" alert', () => {
expect(findNoAgentAlert().exists()).toBe(false); expect(findHighVolumeAlert().exists()).toBe(true);
}); });
it('does emit an event to add the alert', () => { it('does not render the "no agent" alert', () => {
findAddAlertButton().vm.$emit('click'); expect(findNoAgentAlert().exists()).toBe(false);
expect(wrapper.emitted('update-alert')).toEqual([[true]]); });
}); });
}); });
describe('alert enabled', () => { describe('default state', () => {
beforeEach(async () => { describe('agent installed', () => {
await createWrapper({ propsData: { policyAlert: true } }); beforeEach(async () => {
}); await createWrapper();
});
it('does not render the add alert button', () => { it('does render the enabled add alert button ', () => {
expect(findAddAlertButton().exists()).toBe(false); expect(findAddAlertButton().exists()).toBe(true);
}); expect(findAddAlertButton().props('disabled')).toBe(false);
});
it('does render the high volume warning', () => { it('does not render the "high volume" alert', () => {
expect(findHighVolumeAlert().exists()).toBe(true); expect(findHighVolumeAlert().exists()).toBe(false);
}); });
it('does render the alert message', () => { it('does not render the alert message', () => {
expect(findAlertMessage().exists()).toBe(true); expect(findAlertMessage().exists()).toBe(false);
}); });
it('does render the remove alert button', () => { it('does not render the remove alert button', () => {
expect(findRemoveAlertButton().exists()).toBe(true); expect(findRemoveAlertButton().exists()).toBe(false);
}); });
it('does not show the "no agent" alert when there is an agent, ', () => { it('does not render the "no agent" alert when there is an agent, ', () => {
expect(findNoAgentAlert().exists()).toBe(false); expect(findNoAgentAlert().exists()).toBe(false);
}); });
it('does emit an event to remove the alert', () => { it('does emit an event to add the alert', () => {
findRemoveAlertButton().vm.$emit('click'); findAddAlertButton().vm.$emit('click');
expect(wrapper.emitted('update-alert')).toEqual([[false]]); expect(wrapper.emitted('update-alert')).toEqual([[true]]);
});
}); });
});
describe('no agent installed', () => { describe('no agent installed', () => {
it('add alert button is there and there is NOT an agent', async () => { beforeEach(async () => {
await createWrapper({ agentCount: 0 }); await createWrapper({ agentCount: 0 });
expect(findNoAgentAlert().exists()).toBe(true); });
it('does render the "no agent" alert', () => {
expect(findNoAgentAlert().exists()).toBe(true);
});
it('does render the disabled add alert button ', async () => {
expect(findAddAlertButton().exists()).toBe(true);
expect(findAddAlertButton().props('disabled')).toBe(true);
});
}); });
});
it('add alert button is NOT there and there is NOT an agent', async () => { describe('alert enabled', () => {
await createWrapper({ propsData: { policyAlert: true }, agentCount: 0 }); describe('agent installed', () => {
expect(findNoAgentAlert().exists()).toBe(true); beforeEach(async () => {
await createWrapper({ propsData: { policyAlert: true } });
});
it('does not render the add alert button', () => {
expect(findAddAlertButton().exists()).toBe(false);
});
it('does render the "high volume" alert', () => {
expect(findHighVolumeAlert().exists()).toBe(true);
});
it('does render the alert message', () => {
expect(findAlertMessage().exists()).toBe(true);
});
it('does render the remove alert button', () => {
expect(findRemoveAlertButton().exists()).toBe(true);
});
it('does not render the "no agent" alert', () => {
expect(findNoAgentAlert().exists()).toBe(false);
});
it('does emit an event to remove the alert', () => {
findRemoveAlertButton().vm.$emit('click');
expect(wrapper.emitted('update-alert')).toEqual([[false]]);
});
});
describe('no agent installed', () => {
beforeEach(async () => {
await createWrapper({ propsData: { policyAlert: true }, agentCount: 0 });
});
it('does render the "no agent" alert', () => {
expect(findNoAgentAlert().exists()).toBe(true);
});
it('does not render the "high volume" alert', async () => {
expect(findHighVolumeAlert().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