mirror of https://github.com/status-im/consul.git
Hide the hcp link banner behind an env variable (#20392)
This commit is contained in:
parent
9f90060b0f
commit
da42f7a00b
|
@ -3,17 +3,19 @@
|
|||
* SPDX-License-Identifier: BUSL-1.1
|
||||
*/
|
||||
|
||||
import Service from '@ember/service';
|
||||
import Service, { inject as service } from '@ember/service';
|
||||
import { tracked } from '@glimmer/tracking';
|
||||
|
||||
const LOCAL_STORAGE_KEY = 'consul:hideHcpLinkBanner';
|
||||
|
||||
export default class HcpLinkStatus extends Service {
|
||||
@service('env') env;
|
||||
@tracked
|
||||
userDismissedBanner = false;
|
||||
|
||||
get shouldDisplayBanner() {
|
||||
return !this.userDismissedBanner;
|
||||
const hcpLinkEnabled = this.env.var('CONSUL_HCP_LINK_ENABLED');
|
||||
return !this.userDismissedBanner && hcpLinkEnabled;
|
||||
}
|
||||
|
||||
constructor() {
|
||||
|
|
|
@ -146,7 +146,7 @@ export default function (config = {}, win = window, doc = document) {
|
|||
case 'CONSUL_API_PREFIX':
|
||||
// we want API prefix to look like an env var for if we ever change
|
||||
// operator config to be an API request, we need this variable before we
|
||||
// make and API request so this specific variable should never be be
|
||||
// make and API request so this specific variable should never be
|
||||
// retrived via an API request
|
||||
return operatorConfig.APIPrefix;
|
||||
case 'CONSUL_HCP_URL':
|
||||
|
|
|
@ -6,6 +6,7 @@
|
|||
import { module, test } from 'qunit';
|
||||
import { click, visit } from '@ember/test-helpers';
|
||||
import { setupApplicationTest } from 'ember-qunit';
|
||||
import { EnvStub } from 'consul-ui/services/env';
|
||||
|
||||
const bannerSelector = '[data-test-link-to-hcp-banner]';
|
||||
module('Acceptance | link to hcp banner', function (hooks) {
|
||||
|
@ -14,9 +15,14 @@ module('Acceptance | link to hcp banner', function (hooks) {
|
|||
hooks.beforeEach(function () {
|
||||
// clear local storage so we don't have any settings
|
||||
window.localStorage.clear();
|
||||
// setupTestEnv(this.owner, {
|
||||
// CONSUL_ACLS_ENABLED: true,
|
||||
// });
|
||||
this.owner.register(
|
||||
'service:env',
|
||||
class Stub extends EnvStub {
|
||||
stubEnv = {
|
||||
CONSUL_HCP_LINK_ENABLED: true,
|
||||
};
|
||||
}
|
||||
);
|
||||
});
|
||||
|
||||
test('the banner is initially displayed on services page', async function (assert) {
|
||||
|
@ -32,4 +38,17 @@ module('Acceptance | link to hcp banner', function (hooks) {
|
|||
await visit('/');
|
||||
assert.dom(bannerSelector).doesNotExist('Banner is still gone after refresh');
|
||||
});
|
||||
|
||||
test('the banner is not displayed if the env var is not set', async function (assert) {
|
||||
this.owner.register(
|
||||
'service:env',
|
||||
class Stub extends EnvStub {
|
||||
stubEnv = {};
|
||||
}
|
||||
);
|
||||
// default route is services page so we're good here
|
||||
await visit('/');
|
||||
// Expect the banner to be visible by default
|
||||
assert.dom(bannerSelector).doesNotExist('Banner is not here');
|
||||
});
|
||||
});
|
||||
|
|
|
@ -31,7 +31,7 @@ module('Integration | Component | link-to-hcp-banner', function (hooks) {
|
|||
'service:env',
|
||||
class Stub extends EnvStub {
|
||||
stubEnv = {
|
||||
isEnterprise: false,
|
||||
CONSUL_HCP_LINK_ENABLED: true,
|
||||
};
|
||||
}
|
||||
);
|
||||
|
|
Loading…
Reference in New Issue