Skip to content

Commit

Permalink
fix container monitoring checkbox and add unit tests (rancher#11083)
Browse files Browse the repository at this point in the history
  • Loading branch information
mantis-toboggan-md authored May 23, 2024
1 parent daa137a commit a666ee9
Show file tree
Hide file tree
Showing 2 changed files with 67 additions and 6 deletions.
16 changes: 12 additions & 4 deletions pkg/aks/components/CruAks.vue
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,6 @@ export default defineComponent({
}
this.config = this.normanCluster.aksConfig;
this.nodePools = this.normanCluster.aksConfig.nodePools;
this.containerMonitoring = !!(this.config.logAnalyticsWorkspaceGroup || this.config.logAnalyticsWorkspaceName);
this.setAuthorizedIPRanges = !!(this.config?.authorizedIpRanges || []).length;
this.nodePools.forEach((pool: AKSNodePool) => {
this.$set(pool, '_id', randomStr());
Expand Down Expand Up @@ -201,7 +200,6 @@ export default defineComponent({
loadingVersions: false,
loadingVmSizes: false,
loadingVirtualNetworks: false,
containerMonitoring: false,
setAuthorizedIPRanges: false,
fvFormRuleSets: [{
path: 'name',
Expand Down Expand Up @@ -793,6 +791,13 @@ export default defineComponent({
delete this.config.privateDnsZone;
delete this.config.userAssignedIdentity;
}
},
'config.monitoring'(neu: boolean) {
if (!neu) {
this.$set(this.config, 'logAnalyticsWorkspaceGroup', null);
this.$set(this.config, 'logAnalyticsWorkspaceName', null);
}
}
},
Expand Down Expand Up @@ -1179,27 +1184,30 @@ export default defineComponent({
</div>
<div class="col span-3">
<Checkbox
v-model="containerMonitoring"
v-model="config.monitoring"
:mode="mode"
label-key="aks.containerMonitoring.label"
data-testid="aks-monitoring-checkbox"
/>
</div>
</div>

<div class="row mb-10">
<template v-if="containerMonitoring">
<template v-if="config.monitoring">
<div class="col span-3">
<LabeledInput
v-model="config.logAnalyticsWorkspaceGroup"
:mode="mode"
label-key="aks.logAnalyticsWorkspaceGroup.label"
data-testid="aks-log-analytics-workspace-group-input"
/>
</div>
<div class="col span-3">
<LabeledInput
v-model="config.logAnalyticsWorkspaceName"
:mode="mode"
label-key="aks.logAnalyticsWorkspaceName.label"
data-testid="aks-log-analytics-workspace-name-input"
/>
</div>
</template>
Expand Down
57 changes: 55 additions & 2 deletions pkg/aks/components/__tests__/CruAks.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -368,6 +368,37 @@ describe('aks provisioning form', () => {
expect(wrapper.vm.config.virtualNetworkResourceGroup).toBe(virtualNetworkResourceGroup);
});

it('should set config.monitoring to \'true\' and show log anaytics workspace name and log analytics workspace group inputs when the monitoring checkbox is checked', async() => {
const config = {
dnsPrefix: 'abc-123', resourceGroup: 'abc', clusterName: 'abc'
};
const wrapper = shallowMount(CruAks, {
propsData: {
value: {}, mode: 'edit', config
},
...requiredSetup()
});

await setCredential(wrapper, config);
let logAnalyticsWorkspaceNameInput = wrapper.find('[data-testid="aks-log-analytics-workspace-name-input"]');
let logAnalyticsWorkspaceGroupInput = wrapper.find('[data-testid="aks-log-analytics-workspace-group-input"]');
const monitoringCheckbox = wrapper.find('[data-testid="aks-monitoring-checkbox"]');

expect(monitoringCheckbox.props().value).toBe(false);
expect(logAnalyticsWorkspaceNameInput.exists()).toBe(false);
expect(logAnalyticsWorkspaceGroupInput.exists()).toBe(false);
expect(wrapper.vm.$data.config.monitoring).toBeFalsy();

monitoringCheckbox.vm.$emit('input', true);
await wrapper.vm.$nextTick();
expect(wrapper.vm.$data.config.monitoring).toBe(true);
logAnalyticsWorkspaceNameInput = wrapper.find('[data-testid="aks-log-analytics-workspace-name-input"]');
logAnalyticsWorkspaceGroupInput = wrapper.find('[data-testid="aks-log-analytics-workspace-group-input"]');
expect(monitoringCheckbox.props().value).toBe(true);
expect(logAnalyticsWorkspaceNameInput.isVisible()).toBe(true);
expect(logAnalyticsWorkspaceGroupInput.isVisible()).toBe(true);
});

it('should clear virtualNetwork, virtualNetworkResourceGroup, and subnet when the \'none\' virtual network option is selected', async() => {
const config = {
dnsPrefix: 'abc-123', resourceGroup: 'abc', clusterName: 'abc'
Expand Down Expand Up @@ -405,7 +436,6 @@ describe('aks provisioning form', () => {
const config = {
dnsPrefix: 'abc-123', resourceGroup: 'abc', clusterName: 'abc', kubernetesVersion: originalVersion, nodePools
};

const wrapper = shallowMount(CruAks, {
propsData: {
value: {}, mode: 'edit', config
Expand All @@ -414,7 +444,6 @@ describe('aks provisioning form', () => {
});

await setCredential(wrapper, config);

wrapper.setData({ config: { ...config, kubernetesVersion: newVersion } });
await wrapper.vm.$nextTick();
const pools = wrapper.vm.nodePools;
Expand All @@ -423,4 +452,28 @@ describe('aks provisioning form', () => {
expect(pool.orchestratorVersion).toBe(pool._isNewOrUnprovisioned ? newVersion : originalVersion);
});
});

it('should clear config.logAnalyticsWorkspaceName and config.logAnalyticsWorkspaceGroup when the monitoring checkbox is unchecked', async() => {
const config = {
dnsPrefix: 'abc-123', resourceGroup: 'abc', clusterName: 'abc', monitoring: true, logAnalyticsWorkspaceGroup: 'abc', logAnalyticsWorkspaceName: 'def'
};
const wrapper = shallowMount(CruAks, {
propsData: {
value: {}, mode: 'edit', config
},
...requiredSetup()
});

await setCredential(wrapper, config);

const monitoringCheckbox = wrapper.find('[data-testid="aks-monitoring-checkbox"]');

expect(monitoringCheckbox.props().value).toBe(true);

monitoringCheckbox.vm.$emit('input', false);
await wrapper.vm.$nextTick();
expect(wrapper.vm.$data.config.monitoring).toBeFalsy();
expect(wrapper.vm.$data.config.logAnalyticsWorkspaceGroup).toBeNull();
expect(wrapper.vm.$data.config.logAnalyticsWorkspaceName).toBeNull();
});
});

0 comments on commit a666ee9

Please sign in to comment.