2022-09-07 16:21:23 +00:00
|
|
|
import { module, test } from 'qunit';
|
|
|
|
import { setupRenderingTest } from 'ember-qunit';
|
2022-09-23 14:18:20 +00:00
|
|
|
import { click, render } from '@ember/test-helpers';
|
2022-09-07 16:21:23 +00:00
|
|
|
import { hbs } from 'ember-cli-htmlbars';
|
|
|
|
import { setupMirage } from 'ember-cli-mirage/test-support';
|
2022-09-19 20:37:40 +00:00
|
|
|
import { statuses } from '../../../mirage/handlers/hcp-link';
|
|
|
|
|
2022-09-07 16:21:23 +00:00
|
|
|
module('Integration | Component | link-status', function (hooks) {
|
|
|
|
setupRenderingTest(hooks);
|
|
|
|
setupMirage(hooks);
|
|
|
|
|
|
|
|
// this can be removed once feature is released for OSS
|
|
|
|
hooks.beforeEach(function () {
|
|
|
|
this.owner.lookup('service:version').set('isEnterprise', true);
|
2022-09-19 20:37:40 +00:00
|
|
|
this.statuses = statuses;
|
2022-09-07 16:21:23 +00:00
|
|
|
});
|
|
|
|
|
2022-09-23 14:18:20 +00:00
|
|
|
test('it does not render banner when status is not present', async function (assert) {
|
|
|
|
await render(hbs`
|
|
|
|
<div id="modal-wormhole"></div>
|
|
|
|
<LinkStatus @status={{undefined}} />
|
|
|
|
`);
|
2022-09-20 18:57:32 +00:00
|
|
|
|
2022-09-23 14:18:20 +00:00
|
|
|
assert.dom('.navbar-status').doesNotExist('Banner is hidden for missing status message');
|
2022-09-20 18:57:32 +00:00
|
|
|
});
|
|
|
|
|
2022-09-23 14:18:20 +00:00
|
|
|
test('it does not render banner in oss version', async function (assert) {
|
2022-09-20 18:57:32 +00:00
|
|
|
this.owner.lookup('service:version').set('isEnterprise', false);
|
|
|
|
|
2022-09-23 14:18:20 +00:00
|
|
|
await render(hbs`
|
|
|
|
<div id="modal-wormhole"></div>
|
|
|
|
<LinkStatus @status={{get this.statuses 0}} />
|
|
|
|
`);
|
2022-09-20 18:57:32 +00:00
|
|
|
|
2022-09-23 14:18:20 +00:00
|
|
|
assert.dom('.navbar-status').doesNotExist('Banner is hidden in oss');
|
2022-09-20 18:57:32 +00:00
|
|
|
});
|
|
|
|
|
2022-09-07 16:21:23 +00:00
|
|
|
test('it renders connected status', async function (assert) {
|
2022-09-23 14:18:20 +00:00
|
|
|
await render(hbs`
|
|
|
|
<div id="modal-wormhole"></div>
|
|
|
|
<LinkStatus @status={{get this.statuses 0}} />
|
|
|
|
`);
|
2022-09-07 16:21:23 +00:00
|
|
|
|
2022-09-23 14:18:20 +00:00
|
|
|
assert.dom('.navbar-status').hasClass('connected', 'Correct banner class renders for connected state');
|
2022-09-07 16:21:23 +00:00
|
|
|
assert
|
|
|
|
.dom('[data-test-link-status]')
|
2022-09-23 14:18:20 +00:00
|
|
|
.hasText('This self-managed Vault is linked to HCP.', 'Banner copy renders for connected state');
|
2022-09-07 16:21:23 +00:00
|
|
|
assert
|
|
|
|
.dom('[data-test-link-status] a')
|
|
|
|
.hasAttribute('href', 'https://portal.cloud.hashicorp.com/sign-in', 'HCP sign in link renders');
|
|
|
|
});
|
2022-09-19 20:37:40 +00:00
|
|
|
|
2022-09-23 14:18:20 +00:00
|
|
|
test('it should render error states', async function (assert) {
|
|
|
|
// disconnected error
|
|
|
|
await render(hbs`
|
|
|
|
<div id="modal-wormhole"></div>
|
|
|
|
<LinkStatus @status={{get this.statuses 1}} />
|
|
|
|
`);
|
2022-09-19 20:37:40 +00:00
|
|
|
|
2022-09-23 14:18:20 +00:00
|
|
|
assert.dom('.navbar-status').hasClass('warning', 'Correct banner class renders for error state');
|
2022-09-19 20:37:40 +00:00
|
|
|
assert
|
|
|
|
.dom('[data-test-link-status]')
|
|
|
|
.hasText(
|
2022-09-23 14:18:20 +00:00
|
|
|
'There was an error connecting to HCP. Click here for more information.',
|
|
|
|
'Banner copy renders for error state'
|
2022-09-19 20:37:40 +00:00
|
|
|
);
|
|
|
|
|
2022-09-23 14:18:20 +00:00
|
|
|
await click('[data-test-link-status] button');
|
2022-09-19 20:37:40 +00:00
|
|
|
assert
|
2022-09-23 14:18:20 +00:00
|
|
|
.dom('[data-test-link-status-timestamp]')
|
|
|
|
.hasText('2022-09-21T11:25:02.196835-07:00', 'Timestamp renders');
|
2022-09-19 20:37:40 +00:00
|
|
|
assert
|
2022-09-23 14:18:20 +00:00
|
|
|
.dom('[data-test-link-status-error]')
|
|
|
|
.hasText('unable to establish a connection with HCP', 'Error renders');
|
|
|
|
|
|
|
|
// connecting error
|
|
|
|
await render(hbs`
|
|
|
|
<div id="modal-wormhole"></div>
|
|
|
|
<LinkStatus @status={{get this.statuses 3}} />
|
|
|
|
`);
|
2022-09-20 18:57:32 +00:00
|
|
|
assert
|
2022-09-23 14:18:20 +00:00
|
|
|
.dom('[data-test-link-status-error]')
|
|
|
|
.hasText('principal does not have the permission to register as a provider', 'Error renders');
|
|
|
|
|
|
|
|
// this shouldn't happen but placeholders should render if disconnected/connecting status is returned without timestamp and/or error
|
|
|
|
await render(hbs`
|
|
|
|
<div id="modal-wormhole"></div>
|
|
|
|
<LinkStatus @status="connecting" />
|
|
|
|
`);
|
|
|
|
assert.dom('[data-test-link-status-timestamp]').hasText('Not available', 'Timestamp placeholder renders');
|
|
|
|
assert.dom('[data-test-link-status-error]').hasText('Not available', 'Error placeholder renders');
|
2022-09-19 20:37:40 +00:00
|
|
|
});
|
2022-09-07 16:21:23 +00:00
|
|
|
});
|