2023-03-15 16:00:52 +00:00
|
|
|
/**
|
|
|
|
* Copyright (c) HashiCorp, Inc.
|
|
|
|
* SPDX-License-Identifier: MPL-2.0
|
|
|
|
*/
|
|
|
|
|
2018-11-14 00:55:07 +00:00
|
|
|
import { addMinutes } from 'date-fns';
|
2018-10-12 19:03:01 +00:00
|
|
|
import { module, test } from 'qunit';
|
|
|
|
import { setupRenderingTest } from 'ember-qunit';
|
|
|
|
import { render } from '@ember/test-helpers';
|
|
|
|
import hbs from 'htmlbars-inline-precompile';
|
|
|
|
import { create } from 'ember-cli-page-object';
|
|
|
|
import license from '../../pages/components/license-info';
|
2018-11-05 16:56:59 +00:00
|
|
|
import { allFeatures } from 'vault/helpers/all-features';
|
|
|
|
|
|
|
|
const FEATURES = allFeatures();
|
2018-10-12 19:03:01 +00:00
|
|
|
|
|
|
|
const component = create(license);
|
|
|
|
|
2021-12-17 03:44:29 +00:00
|
|
|
module('Integration | Component | license info', function (hooks) {
|
2018-10-12 19:03:01 +00:00
|
|
|
setupRenderingTest(hooks);
|
|
|
|
|
2021-12-17 03:44:29 +00:00
|
|
|
test('it renders feature status properly for features associated with license', async function (assert) {
|
2018-11-14 00:55:07 +00:00
|
|
|
const now = Date.now();
|
2018-10-12 19:03:01 +00:00
|
|
|
this.set('licenseId', 'temporary');
|
2018-11-14 00:55:07 +00:00
|
|
|
this.set('expirationTime', addMinutes(now, 30));
|
|
|
|
this.set('startTime', now);
|
2018-10-12 19:03:01 +00:00
|
|
|
this.set('features', ['HSM', 'Namespaces']);
|
|
|
|
await render(
|
|
|
|
hbs`<LicenseInfo @licenseId={{this.licenseId}} @expirationTime={{this.expirationTime}} @startTime={{this.startTime}} @features={{this.features}}/>`
|
|
|
|
);
|
2022-10-18 15:46:02 +00:00
|
|
|
assert.strictEqual(
|
|
|
|
component.detailRows.length,
|
|
|
|
3,
|
|
|
|
'Shows License ID, Valid from, and License State rows'
|
|
|
|
);
|
|
|
|
assert.strictEqual(component.featureRows.length, FEATURES.length, 'it renders all of the features');
|
2022-11-09 23:15:31 +00:00
|
|
|
const activeFeatures = component.featureRows.filter((f) => f.featureStatus === 'Active');
|
2022-10-18 15:46:02 +00:00
|
|
|
assert.strictEqual(activeFeatures.length, 2, 'Has two features listed as active');
|
2018-10-12 19:03:01 +00:00
|
|
|
});
|
|
|
|
|
2021-12-17 03:44:29 +00:00
|
|
|
test('it renders properly for autoloaded license', async function (assert) {
|
2018-11-14 00:55:07 +00:00
|
|
|
const now = Date.now();
|
2018-10-12 19:03:01 +00:00
|
|
|
this.set('licenseId', 'test');
|
2018-11-14 00:55:07 +00:00
|
|
|
this.set('expirationTime', addMinutes(now, 30));
|
2021-06-07 17:44:39 +00:00
|
|
|
this.set('autoloaded', true);
|
2018-11-14 00:55:07 +00:00
|
|
|
this.set('startTime', now);
|
2018-10-12 19:03:01 +00:00
|
|
|
this.set('features', ['HSM', 'Namespaces']);
|
|
|
|
await render(
|
2021-06-07 17:44:39 +00:00
|
|
|
hbs`<LicenseInfo
|
|
|
|
@licenseId={{this.licenseId}}
|
|
|
|
@expirationTime={{this.expirationTime}}
|
|
|
|
@startTime={{this.startTime}}
|
|
|
|
@features={{this.features}}
|
|
|
|
@autoloaded={{true}}
|
|
|
|
/>`
|
2018-10-12 19:03:01 +00:00
|
|
|
);
|
2022-11-09 23:15:31 +00:00
|
|
|
const row = component.detailRows.filterBy('rowName', 'License state')[0];
|
2022-10-18 15:46:02 +00:00
|
|
|
assert.strictEqual(row.rowValue, 'Autoloaded', 'Shows autoloaded status');
|
2018-10-12 19:03:01 +00:00
|
|
|
});
|
|
|
|
|
2021-12-17 03:44:29 +00:00
|
|
|
test('it renders Performance Standby as inactive if count is 0', async function (assert) {
|
2018-12-18 17:01:12 +00:00
|
|
|
const now = Date.now();
|
|
|
|
this.set('licenseId', 'temporary');
|
|
|
|
this.set('expirationTime', addMinutes(now, 30));
|
|
|
|
this.set('startTime', now);
|
|
|
|
this.set('model', { performanceStandbyCount: 0 });
|
|
|
|
this.set('features', ['Performance Standby', 'Namespaces']);
|
|
|
|
|
|
|
|
await render(
|
|
|
|
hbs`<LicenseInfo @licenseId={{this.licenseId}} @expirationTime={{this.expirationTime}} @startTime={{this.startTime}} @features={{this.features}} @model={{this.model}}/>`
|
|
|
|
);
|
|
|
|
|
2022-11-09 23:15:31 +00:00
|
|
|
const row = component.featureRows.filterBy('featureName', 'Performance Standby')[0];
|
2022-10-18 15:46:02 +00:00
|
|
|
assert.strictEqual(
|
|
|
|
row.featureStatus,
|
|
|
|
'Not Active',
|
|
|
|
'renders feature as inactive because when count is 0'
|
|
|
|
);
|
2018-12-18 17:01:12 +00:00
|
|
|
});
|
|
|
|
|
2021-12-17 03:44:29 +00:00
|
|
|
test('it renders Performance Standby as active and shows count', async function (assert) {
|
2018-12-18 17:01:12 +00:00
|
|
|
const now = Date.now();
|
|
|
|
this.set('licenseId', 'temporary');
|
|
|
|
this.set('expirationTime', addMinutes(now, 30));
|
|
|
|
this.set('startTime', now);
|
|
|
|
this.set('model', { performanceStandbyCount: 4 });
|
|
|
|
this.set('features', ['Performance Standby', 'Namespaces']);
|
|
|
|
|
|
|
|
await render(
|
2021-06-07 17:44:39 +00:00
|
|
|
hbs`<LicenseInfo
|
|
|
|
@licenseId={{this.licenseId}}
|
|
|
|
@expirationTime={{this.expirationTime}}
|
|
|
|
@startTime={{this.startTime}}
|
|
|
|
@features={{this.features}}
|
|
|
|
@performanceStandbyCount={{this.model.performanceStandbyCount}}
|
|
|
|
/>`
|
2018-12-18 17:01:12 +00:00
|
|
|
);
|
|
|
|
|
2022-11-09 23:15:31 +00:00
|
|
|
const row = component.featureRows.filterBy('featureName', 'Performance Standby')[0];
|
2022-10-18 15:46:02 +00:00
|
|
|
assert.strictEqual(
|
|
|
|
row.featureStatus,
|
|
|
|
'Active — 4 standby nodes allotted',
|
|
|
|
'renders active and displays count'
|
|
|
|
);
|
2018-12-18 17:01:12 +00:00
|
|
|
});
|
2018-10-12 19:03:01 +00:00
|
|
|
});
|