Skip to content

Commit

Permalink
add e2e test for issue 9923 (#10899)
Browse files Browse the repository at this point in the history
* add e2e test for issue 9923

* add code comment
  • Loading branch information
aalves08 committed Apr 30, 2024
1 parent 943445a commit bc7d33a
Show file tree
Hide file tree
Showing 4 changed files with 84 additions and 0 deletions.
21 changes: 21 additions & 0 deletions cypress/e2e/po/other-products/v2-monitoring.po.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import TabbedPo from '@/cypress/e2e/po/components/tabbed.po';
import LabeledInputPo from '@/cypress/e2e/po/components/labeled-input.po';
import NameNsDescription from '@/cypress/e2e/po/components/name-ns-description.po';
import UnitInputPo from '@/cypress/e2e/po/components/unit-input.po';
import LabeledSelectPo from '@/cypress/e2e/po/components/labeled-select.po';

export default class V2MonitoringPo extends PagePo {
static createPath(clusterId: string) {
Expand All @@ -25,6 +26,10 @@ export default class V2MonitoringPo extends PagePo {
return this.list().masthead().actions().contains('Create');
}

createChinese(): Cypress.Chainable {
return this.list().masthead().actions().contains('创建');
}

createFromYaml(): Cypress.Chainable {
return this.list().masthead().actions().contains('Create from YAML');
}
Expand Down Expand Up @@ -83,6 +88,22 @@ export default class V2MonitoringPo extends PagePo {
return CodeMirrorPo.bySelector(cy.get(`body [id=group-${ index }]`), '[data-testid="v2-monitoring-prom-rules-recording-promql"]');
}

prometheusRulesAddAlert(index: number) {
return cy.get(`[id=group-${ index }] [data-testid="v2-monitoring-add-alert"]`);
}

alertingRuleSeveritySelect(index: number) {
return new LabeledSelectPo(`[id=group-${ index }] [data-testid="v2-monitoring-alerting-rules-severity"]`, this.self());
}

prometheusRulesAlertName(index: number) {
return new LabeledInputPo(cy.get(`[id=group-${ index }] [data-testid="v2-monitoring-alerting-rules-alert-name"]`));
}

prometheusRulesAlertPromQl(index: number): CodeMirrorPo {
return CodeMirrorPo.bySelector(cy.get(`body [id=group-${ index }]`), '[data-testid="v2-monitoring-alerting-rules-promql"]');
}

goToDetailsPage(elemName: string) {
const resourceTable = new ResourceTablePo(this.self());

Expand Down
59 changes: 59 additions & 0 deletions cypress/e2e/tests/pages/charts/v2-monitoring.spec.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { generateV2MonitoringForLocalCluster } from '@/cypress/e2e/blueprints/other-products/v2-monitoring.js';
import V2Monitoring from '@/cypress/e2e/po/other-products/v2-monitoring.po';
import PreferencesPagePo from '@/cypress/e2e/po/pages/preferences.po';

describe('V2 monitoring Chart', { tags: ['@charts', '@adminUser'] }, () => {
beforeEach(() => {
Expand Down Expand Up @@ -131,5 +132,63 @@ describe('V2 monitoring Chart', { tags: ['@charts', '@adminUser'] }, () => {
});
});
});

// testing https://github.com/rancher/dashboard/issues/9923
it('Alerting Rules "Severity" select should NOT be translating the values to Chinese', () => {
// this intercept is for the payload of the creation of prometheusrules, which is what we want to test
cy.intercept('POST', 'k8s/clusters/local/v1/monitoring.coreos.com.prometheusrules', (req: any) => {
req.reply({
statusCode: 201,
body: {}
});
}).as('prometheusRulesCreation');

const prefPage = new PreferencesPagePo();

// change language to chinese
prefPage.goTo();
prefPage.languageDropdownMenu().checkVisible();
prefPage.languageDropdownMenu().toggle();
prefPage.languageDropdownMenu().isOpened();
prefPage.languageDropdownMenu().getOptions().should('have.length', 2);
prefPage.languageDropdownMenu().clickOption(2);
prefPage.languageDropdownMenu().isClosed();

const v2Monitoring = new V2Monitoring('local');

// go to v2 monitoring on local cluster
v2Monitoring.goTo();
v2Monitoring.waitForPage();

// // open Advanced group (default is PrometheusRules)
v2Monitoring.navToSideMenuGroupByLabel('Advanced');
v2Monitoring.waitForPage();

// create a new PrometheusRule
v2Monitoring.createChinese().click();
v2Monitoring.waitForPage();

v2Monitoring.nameNsDescription().name().set('some-prom-rules');

v2Monitoring.prometheusRuleGroupName(0).self().scrollIntoView();
v2Monitoring.prometheusRuleGroupName(0).set('group-name-0');
v2Monitoring.prometheusRuleGroupInterval(0).setValue('60');

v2Monitoring.prometheusRulesAddAlert(0).click();
v2Monitoring.prometheusRulesAlertName(0).self().scrollIntoView();
v2Monitoring.prometheusRulesAlertName(0).set('record-0');
v2Monitoring.prometheusRulesAlertPromQl(0).self().scrollIntoView();
v2Monitoring.prometheusRulesAlertPromQl(0).set('promql-0');

// critical option
v2Monitoring.alertingRuleSeveritySelect(0).toggle();
v2Monitoring.alertingRuleSeveritySelect(0).clickOption(1);

v2Monitoring.saveCreateForm().click();

cy.wait('@prometheusRulesCreation', { requestTimeout: 4000 }).then((req) => {
expect(req.request.body.spec.groups[0].rules[0].labels.severity).to.equal('critical');
});
});
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -285,6 +285,7 @@ export default {
:label="t('prometheusRule.alertingRules.name')"
:required="true"
:mode="mode"
data-testid="v2-monitoring-alerting-rules-alert-name"
/>
</div>
<div class="col span-6">
Expand Down Expand Up @@ -314,6 +315,7 @@ export default {
foldGutter: false,
readOnly: mode === 'view',
}"
data-testid="v2-monitoring-alerting-rules-promql"
@onInput="queueUpdate"
/>
</template>
Expand Down Expand Up @@ -353,6 +355,7 @@ export default {
:label="t('prometheusRule.alertingRules.labels.severity.choices.label')"
:localized-label="false"
:options="severityOptions"
data-testid="v2-monitoring-alerting-rules-severity"
/>
</div>
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,7 @@ export default {
:disabled="disableAddAlert"
type="button"
class="btn role-tertiary"
data-testid="v2-monitoring-add-alert"
@click="addRule('alert')"
>
<t k="prometheusRule.alertingRules.addLabel" />
Expand Down

0 comments on commit bc7d33a

Please sign in to comment.