Skip to content

Commit 3ffc985

Browse files
test: [M3-10369] - Add tests to linode alerts edit page on when "Save Changes?" dialog should appear (linode#12707)
* init commit * cleanup * Added changeset: Add tests on confirm dialog in linode details page * Delete packages/manager/.changeset/pr-12707-tests-1755204665364.md recd an error while running the changeset cmd locally, so i didnt realize i uploaded the file * Delete packages/manager/.changeset/pr-12707-tests-1755204624282.md recd an error while running the changeset cmd locally, so i didnt realize i uploaded the file * edits after review * reverted title
1 parent cad8e00 commit 3ffc985

File tree

4 files changed

+138
-23
lines changed

4 files changed

+138
-23
lines changed
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@linode/manager": Tests
3+
---
4+
5+
Add tests on confirm dialog in linode details page ([#12707](https://github.com/linode/manager/pull/12707))

packages/manager/cypress/e2e/core/linodes/alerts-edit.spec.ts

Lines changed: 126 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import { alertFactory } from 'src/factories';
1414
import {
1515
ALERTS_BETA_MODE_BANNER_TEXT,
1616
ALERTS_BETA_MODE_BUTTON_TEXT,
17+
ALERTS_BETA_PROMPT,
1718
ALERTS_LEGACY_MODE_BANNER_TEXT,
1819
ALERTS_LEGACY_MODE_BUTTON_TEXT,
1920
ALERTS_LEGACY_PROMPT,
@@ -240,26 +241,6 @@ describe('region enables alerts', function () {
240241
.should('be.enabled')
241242
.click();
242243
});
243-
244-
// TODO: this test passes but modal behavior may change when properly implemented in api (M3-10195)
245-
// ui.dialog
246-
// .findByTitle('Save Alerts?')
247-
// .should('be.visible')
248-
// .within(() => {
249-
// ui.button.findByTitle('Save').should('be.visible')
250-
// .click();
251-
// });
252-
// TODO: content of request.body not match prod, 'alerts' attribute missing here
253-
// cy.wait('@updateLinode').then((xhr) => {
254-
// // can save changes. new beta alerts added in assertLinodeAlertsEnabled tests
255-
// const edits = xhr.request.body;
256-
// expect(JSON.stringify(edits.system)).to.equal(
257-
// JSON.stringify([])
258-
// );
259-
// expect(JSON.stringify(edits.user)).to.equal(
260-
// JSON.stringify([])
261-
// );
262-
// });
263244
});
264245

265246
it('Legacy alerts = 0, Beta alerts > 0, => beta enabled', function () {
@@ -401,6 +382,131 @@ describe('region enables alerts', function () {
401382
ui.button.findByTitle('Confirm').should('be.visible').click();
402383
});
403384
});
385+
386+
it('in default beta mode, edits to beta alerts do not trigger confirmation modal', function () {
387+
const mockLinode = linodeFactory.build({
388+
id: 2,
389+
label: randomLabel(),
390+
region: this.mockEnabledRegion.id,
391+
alerts: {
392+
...mockEnabledBetaAlerts,
393+
},
394+
});
395+
mockGetLinodeDetails(mockLinode.id, mockLinode).as('getLinode');
396+
cy.visitWithLogin(`/linodes/${mockLinode.id}/alerts`);
397+
cy.wait(['@getFeatureFlags', '@getRegions', '@getLinode']);
398+
ui.tabList.findTabByTitle('Alerts').within(() => {
399+
cy.get('[data-testid="betaChip"]').should('be.visible');
400+
});
401+
cy.get('[data-reach-tab-panels]')
402+
.should('be.visible')
403+
.within(() => {
404+
cy.contains('Alerts').should('be.visible');
405+
cy.get('[data-testid="notice-info"]')
406+
.should('be.visible')
407+
.within(() => {
408+
cy.contains(ALERTS_BETA_MODE_BANNER_TEXT);
409+
});
410+
cy.wait(['@getAlertDefinitions']);
411+
// toggles in table are on but can be turned off
412+
assertLinodeAlertsEnabled(this.alertDefinitions);
413+
414+
mockUpdateLinode(mockLinode.id).as('updateLinode');
415+
ui.button
416+
.findByTitle('Save')
417+
.should('be.visible')
418+
.should('be.enabled')
419+
.click();
420+
});
421+
// M3-10369: "Save Alerts?" prompt does not appear bc beta is already default mode
422+
ui.dialog.find().should('not.exist');
423+
});
424+
425+
it('in default legacy mode, edits to beta alerts trigger confirmation modal ', function () {
426+
const mockLinode = linodeFactory.build({
427+
id: 2,
428+
label: randomLabel(),
429+
region: this.mockEnabledRegion.id,
430+
alerts: {
431+
...mockEnabledLegacyAlerts,
432+
},
433+
});
434+
mockGetLinodeDetails(mockLinode.id, mockLinode).as('getLinode');
435+
cy.visitWithLogin(`/linodes/${mockLinode.id}/alerts`);
436+
cy.wait(['@getFeatureFlags', '@getRegions', '@getLinode']);
437+
ui.tabList.findTabByTitle('Alerts').within(() => {
438+
cy.get('[data-testid="betaChip"]').should('not.exist');
439+
});
440+
cy.get('[data-reach-tab-panels]')
441+
.should('be.visible')
442+
.within(() => {
443+
cy.contains('Alerts').should('be.visible');
444+
cy.get('[data-testid="notice-info"]')
445+
.should('be.visible')
446+
.within(() => {
447+
cy.contains(ALERTS_LEGACY_MODE_BANNER_TEXT);
448+
});
449+
});
450+
451+
// upgrade from legacy alerts to ACLP alerts
452+
ui.button
453+
.findByTitle(ALERTS_LEGACY_MODE_BUTTON_TEXT)
454+
.should('be.visible')
455+
.should('be.enabled')
456+
.click();
457+
458+
ui.tabList.findTabByTitle('Alerts').within(() => {
459+
cy.get('[data-testid="betaChip"]').should('be.visible');
460+
});
461+
cy.get('[data-reach-tab-panels]')
462+
.should('be.visible')
463+
.within(() => {
464+
cy.contains('Alerts').should('be.visible');
465+
cy.get('[data-testid="notice-info"]')
466+
.should('be.visible')
467+
.within(() => {
468+
cy.contains(ALERTS_BETA_MODE_BANNER_TEXT);
469+
});
470+
cy.wait(['@getAlertDefinitions']);
471+
cy.get('table[data-testid="alert-table"]')
472+
.should('be.visible')
473+
.get('tbody > tr')
474+
.should('have.length', 3)
475+
.each((row, index) => {
476+
// match alert definitions to table cell contents
477+
cy.wrap(row).within(() => {
478+
cy.get('td')
479+
.eq(0)
480+
.within(() => {
481+
// each alert's toggle should be enabled/on/true and editable
482+
ui.toggle
483+
.find()
484+
.should('have.attr', 'data-qa-toggle', 'true')
485+
.should('be.visible')
486+
.should('be.enabled')
487+
.click();
488+
ui.toggle
489+
.find()
490+
.should('have.attr', 'data-qa-toggle', 'false');
491+
});
492+
});
493+
});
494+
495+
mockUpdateLinode(mockLinode.id).as('updateLinode');
496+
ui.button
497+
.findByTitle('Save')
498+
.should('be.visible')
499+
.should('be.enabled')
500+
.click();
501+
});
502+
// M3-10369: "Save Alerts?" prompt appears bc of edits to beta alerts but linode was previously in legacy mode
503+
ui.dialog
504+
.findByTitle(ALERTS_BETA_PROMPT)
505+
.should('be.visible')
506+
.within(() => {
507+
ui.button.findByTitle('Confirm').should('be.visible').click();
508+
});
509+
});
404510
});
405511

406512
describe('region disables alerts. beta alerts not available regardless of linode settings', function () {

packages/manager/src/features/CloudPulse/Alerts/ContextualView/AlertInformationActionTable.tsx

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import { TableCell } from 'src/components/TableCell';
1212
import { TableContentWrapper } from 'src/components/TableContentWrapper/TableContentWrapper';
1313
import { TableRow } from 'src/components/TableRow';
1414
import { TableSortCell } from 'src/components/TableSortCell';
15+
import { ALERTS_BETA_PROMPT } from 'src/features/Linodes/constants';
1516
import { useServiceAlertsMutation } from 'src/queries/cloudpulse/alerts';
1617
import { getAPIErrorOrDefault } from 'src/utilities/errorUtils';
1718

@@ -347,12 +348,12 @@ export const AlertInformationActionTable = (
347348
isOpen={isDialogOpen}
348349
message={
349350
<>
350-
Are you sure you want to save (Beta) Alerts? <b>Legacy</b> settings
351-
will be disabled and replaced by (Beta) Alerts settings.
351+
{ALERTS_BETA_PROMPT} <b>Legacy</b> settings will be disabled and
352+
replaced by (Beta) Alerts settings.
352353
</>
353354
}
354355
primaryButtonLabel="Confirm"
355-
title="Are you sure you want to save (Beta) Alerts? "
356+
title={ALERTS_BETA_PROMPT}
356357
/>
357358
</>
358359
);

packages/manager/src/features/Linodes/constants.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,3 +29,6 @@ export const ALERTS_BETA_MODE_BUTTON_TEXT = 'Switch to legacy Alerts';
2929

3030
export const ALERTS_LEGACY_PROMPT =
3131
'Are you sure you want to save legacy Alerts?';
32+
33+
export const ALERTS_BETA_PROMPT =
34+
'Are you sure you want to save (Beta) Alerts?';

0 commit comments

Comments
 (0)