Skip to content

Commit

Permalink
UI: stabilize replication tests (#28384)
Browse files Browse the repository at this point in the history
* Add specificity to replication title selectors

* Use specific selectors for replication titles in tests
  • Loading branch information
hashishaw committed Sep 12, 2024
1 parent 84c58f6 commit 1c16994
Show file tree
Hide file tree
Showing 7 changed files with 36 additions and 28 deletions.
2 changes: 1 addition & 1 deletion ui/lib/core/addon/components/replication-header.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
{{/if}}
</p.top>
<p.levelLeft>
<h1 class="title is-3" data-test-replication-title>
<h1 class="title is-3" data-test-replication-title={{@title}}>
{{@title}}
{{#if @data.anyReplicationEnabled}}
<span class="tag is-light has-text-grey-dark" data-test-mode>
Expand Down
2 changes: 1 addition & 1 deletion ui/lib/replication/addon/components/page/mode-index.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
{{#if @replicationDisabled}}
<PageHeader as |p|>
<p.levelLeft>
<h1 class="title is-3" data-test-replication-title>
<h1 class="title is-3" data-test-replication-title={{@replicationMode}}>
{{#if (eq @replicationMode "dr")}}
Enable Disaster Recovery Replication
{{else if (eq @replicationMode "performance")}}
Expand Down
6 changes: 3 additions & 3 deletions ui/lib/replication/addon/templates/index.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
{{! Replication is unsupported in non-enterprise or when using non-transactional storage (eg inmem) }}
<PageHeader as |p|>
<p.levelLeft>
<h1 class="title is-3 has-text-grey" data-test-replication-title>
<h1 class="title is-3 has-text-grey" data-test-replication-title="Replication unsupported">
Replication unsupported
</h1>
</p.levelLeft>
Expand All @@ -20,7 +20,7 @@
{{else if this.model.allReplicationDisabled}}
<PageHeader as |p|>
<p.levelLeft>
<h1 class="title is-3" data-test-replication-title>
<h1 class="title is-3" data-test-replication-title="Enable Replication">
Enable Replication
</h1>
</p.levelLeft>
Expand Down Expand Up @@ -114,7 +114,7 @@
{{! Renders when at least one mode is not enabled }}
<PageHeader as |p|>
<p.levelLeft>
<h1 class="title is-3" data-test-replication-title>
<h1 class="title is-3" data-test-replication-title="Replication">
Replication
</h1>
</p.levelLeft>
Expand Down
2 changes: 1 addition & 1 deletion ui/lib/replication/addon/templates/mode.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
</Hds::Breadcrumb>
</p.top>
<p.levelLeft>
<h1 class="has-top-margin-m title is-3" data-test-replication-title>
<h1 class="has-top-margin-m title is-3" data-test-replication-title={{this.model.replicationModeForDisplay}}>
{{this.model.replicationModeForDisplay}}
<span class="tag is-light has-text-grey-dark" data-test-replication-mode-display>
{{this.model.replicationAttrs.modeForHeader}}
Expand Down
32 changes: 21 additions & 11 deletions ui/tests/acceptance/enterprise-replication-modes-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,21 @@ import { STATUS_DISABLED_RESPONSE, mockReplicationBlock } from 'vault/tests/help

const s = {
navLink: (title) => `[data-test-sidebar-nav-link="${title}"]`,
title: '[data-test-replication-title]',
title: (t) => `[data-test-replication-title="${t}"]`,
detailLink: (mode) => `[data-test-replication-details-link="${mode}"]`,
summaryCard: '[data-test-replication-summary-card]',
dashboard: '[data-test-replication-dashboard]',
enableForm: '[data-test-replication-enable-form]',
knownSecondary: (name) => `[data-test-secondaries-node="${name}"]`,
};

// wait for specific title selector as an attempt to stabilize flaky tests
async function assertTitle(assert, title, altSelector) {
const selector = altSelector || title;
await waitFor(s.title(selector));
assert.dom(s.title(selector)).hasText(title);
}

module('Acceptance | Enterprise | replication modes', function (hooks) {
setupApplicationTest(hooks);
setupMirage(hooks);
Expand All @@ -42,7 +49,8 @@ module('Acceptance | Enterprise | replication modes', function (hooks) {

await authPage.login();
await visit('/vault/replication');
assert.dom(s.title).hasText('Replication unsupported', 'it shows the unsupported view');

await assertTitle(assert, 'Replication unsupported');

// Nav links
assert.dom(s.navLink('Performance')).doesNotExist('hides performance link');
Expand All @@ -52,7 +60,8 @@ module('Acceptance | Enterprise | replication modes', function (hooks) {
test('replication page when disabled', async function (assert) {
await this.setupMocks(STATUS_DISABLED_RESPONSE);
await visit('/vault/replication');
assert.dom(s.title).hasText('Enable Replication', 'it shows the enable view');

await assertTitle(assert, 'Enable Replication');

// Nav links
assert.dom(s.navLink('Performance')).exists('shows performance link');
Expand All @@ -64,7 +73,8 @@ module('Acceptance | Enterprise | replication modes', function (hooks) {
assert.dom(s.enableForm).exists();

await click(s.navLink('Disaster Recovery'));
assert.dom(s.title).hasText('Enable Disaster Recovery Replication', 'it shows the enable view for dr');

await assertTitle(assert, 'Enable Disaster Recovery Replication', 'dr');
});

['primary', 'secondary'].forEach((mode) => {
Expand All @@ -75,7 +85,7 @@ module('Acceptance | Enterprise | replication modes', function (hooks) {
});
await visit('/vault/replication');

assert.dom(s.title).hasText('Replication', 'it shows default view');
await assertTitle(assert, 'Replication');
assert.dom(s.detailLink('performance')).hasText('Details', 'CTA to see performance details');
assert.dom(s.detailLink('dr')).hasText('Enable', 'CTA to enable dr');

Expand All @@ -89,7 +99,7 @@ module('Acceptance | Enterprise | replication modes', function (hooks) {
assert.dom(s.dashboard).exists(`it shows the replication dashboard`);

await click(s.navLink('Disaster Recovery'));
assert.dom(s.title).hasText('Enable Disaster Recovery Replication', 'it shows the dr title');
await assertTitle(assert, 'Enable Disaster Recovery Replication', 'dr');
assert.dom(s.enableForm).exists('it shows the enable view for dr');
});
});
Expand All @@ -100,7 +110,7 @@ module('Acceptance | Enterprise | replication modes', function (hooks) {
performance: mockReplicationBlock(),
});
await visit('/vault/replication');
assert.dom(s.title).hasText('Replication', 'it shows default view');
await assertTitle(assert, 'Replication');
assert.dom(s.detailLink('performance')).hasText('Enable', 'CTA to enable performance');
assert.dom(s.detailLink('dr')).hasText('Details', 'CTA to see dr details');

Expand All @@ -114,7 +124,7 @@ module('Acceptance | Enterprise | replication modes', function (hooks) {
assert.dom(s.enableForm).exists('it shows the enable view for performance');

await click(s.navLink('Disaster Recovery'));
assert.dom(s.title).hasText(`Disaster Recovery primary`, 'it shows the dr title');
await assertTitle(assert, 'Disaster Recovery primary', 'Disaster Recovery');
assert.dom(s.dashboard).exists(`it shows the replication dashboard`);
});

Expand All @@ -124,15 +134,15 @@ module('Acceptance | Enterprise | replication modes', function (hooks) {
performance: mockReplicationBlock('primary'),
});
await visit('/vault/replication');
assert.dom(s.title).hasText('Disaster Recovery & Performance primary', 'it shows primary view');
await assertTitle(assert, 'Disaster Recovery & Performance primary', 'Disaster Recovery & Performance');
assert.dom(s.summaryCard).exists({ count: 2 }, 'shows 2 summary cards');

await click(s.navLink('Performance'));
assert.dom(s.title).hasText(`Performance primary`, `it shows the performance mode details`);
await assertTitle(assert, 'Performance primary', 'Performance');
assert.dom(s.enableForm).doesNotExist();

await click(s.navLink('Disaster Recovery'));
assert.dom(s.title).hasText(`Disaster Recovery primary`, 'it shows the dr mode details');
await assertTitle(assert, 'Disaster Recovery primary', 'Disaster Recovery');
assert.dom(s.enableForm).doesNotExist();
});
});
14 changes: 6 additions & 8 deletions ui/tests/acceptance/enterprise-replication-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -165,14 +165,12 @@ module('Acceptance | Enterprise | replication', function (hooks) {
'shows the correct title of the empty state'
);

assert.ok(
find('[data-test-replication-title]').textContent.includes('Disaster Recovery'),
'it displays the replication type correctly'
);
assert.ok(
find('[data-test-replication-mode-display]').textContent.includes('primary'),
'it displays the cluster mode correctly'
);
assert
.dom('[data-test-replication-title="Disaster Recovery"]')
.includesText('Disaster Recovery', 'it displays the replication type correctly');
assert
.dom('[data-test-replication-mode-display]')
.includesText('primary', 'it displays the cluster mode correctly');

// add dr secondary
await click('[data-test-replication-link="secondaries"]');
Expand Down
6 changes: 3 additions & 3 deletions ui/tests/integration/components/replication-page-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,11 +62,11 @@ module('Integration | Component | replication-page', function (hooks) {
await render(
hbs`<ReplicationPage @model={{this.model}} as |Page|><Page.header @showTabs={{true}} /></ReplicationPage>`
);
await waitFor('[data-test-replication-title]');
await waitFor('[data-test-replication-title="dr"]');
// Title has spaces and newlines, so we can't use hasText because it won't match exactly
assert.dom('[data-test-replication-title]').includesText('Disaster Recovery');
assert.dom('[data-test-replication-title="dr"]').includesText('Disaster Recovery');
this.set('model', { ...MODEL, replicationMode: 'performance' });
await settled();
assert.dom('[data-test-replication-title]').includesText('Performance');
assert.dom('[data-test-replication-title="performance"]').includesText('Performance');
});
});

0 comments on commit 1c16994

Please sign in to comment.