mirror of https://github.com/status-im/consul.git
Cc 7146/convert consul hcp to a simpler component for some upcoming changes (#20344)
* Convert consul-hcp to a simpler component * update existing test to use envStub helper * Add missing copyright - weird no one yelled about this * remove consul-hcp from load * remove this test that doesn't run anymore
This commit is contained in:
parent
1c1df4530c
commit
75af5b15d9
|
@ -11,7 +11,7 @@
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"doc:toc": "doctoc README.md",
|
"doc:toc": "doctoc README.md",
|
||||||
"compliance": "npm-run-all compliance:*",
|
"compliance": "npm-run-all compliance:*",
|
||||||
"compliance:licenses": "license-checker --summary --onlyAllow 'Python-2.0;Apache*;Apache License, Version 2.0;Apache-2.0;Apache 2.0;Artistic-2.0;BSD;BSD-3-Clause;CC-BY-3.0;CC-BY-4.0;CC0-1.0;ISC;MIT;MPL-2.0;Public Domain;Unicode-TOU;Unlicense;WTFPL' --excludePackages 'consul-ui@2.2.0;consul-acls@0.1.0;consul-lock-sessions@0.1.0;consul-partitions@0.1.0;consul-nspaces@0.1.0;consul-hcp@0.1.0;consul-peerings@0.1.0'"
|
"compliance:licenses": "license-checker --summary --onlyAllow 'Python-2.0;Apache*;Apache License, Version 2.0;Apache-2.0;Apache 2.0;Artistic-2.0;BSD;BSD-3-Clause;CC-BY-3.0;CC-BY-4.0;CC0-1.0;ISC;MIT;MPL-2.0;Public Domain;Unicode-TOU;Unlicense;WTFPL' --excludePackages 'consul-ui@2.2.0;consul-acls@0.1.0;consul-lock-sessions@0.1.0;consul-partitions@0.1.0;consul-nspaces@0.1.0;consul-peerings@0.1.0'"
|
||||||
|
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
|
|
|
@ -1,15 +0,0 @@
|
||||||
{{!
|
|
||||||
Copyright (c) HashiCorp, Inc.
|
|
||||||
SPDX-License-Identifier: BUSL-1.1
|
|
||||||
}}
|
|
||||||
|
|
||||||
{{#let @list (env "CONSUL_HCP_URL") as |SNL hcpUrl|}}
|
|
||||||
{{#if (and SNL hcpUrl)}}
|
|
||||||
<SNL.BackLink
|
|
||||||
@text={{t "components.hashicorp-consul.side-nav.hcp"}}
|
|
||||||
@href={{hcpUrl}}
|
|
||||||
@isHrefExternal={{true}}
|
|
||||||
data-test-back-to-hcp
|
|
||||||
/>
|
|
||||||
{{/if}}
|
|
||||||
{{/let}}
|
|
|
@ -1,80 +0,0 @@
|
||||||
/**
|
|
||||||
* Copyright (c) HashiCorp, Inc.
|
|
||||||
* SPDX-License-Identifier: BUSL-1.1
|
|
||||||
*/
|
|
||||||
|
|
||||||
import { module, test } from 'qunit';
|
|
||||||
import { setupRenderingTest } from 'ember-qunit';
|
|
||||||
import { render } from '@ember/test-helpers';
|
|
||||||
import hbs from 'htmlbars-inline-precompile';
|
|
||||||
|
|
||||||
import ConsulHcpHome from 'consul-ui/components/consul/hcp/home';
|
|
||||||
|
|
||||||
module('Integration | Component | consul hcp home', function(hooks) {
|
|
||||||
setupRenderingTest(hooks);
|
|
||||||
|
|
||||||
test('it prints the value of CONSUL_HCP_URL', async function(assert) {
|
|
||||||
// temporary registration until we are running as separate applications
|
|
||||||
this.owner.register(
|
|
||||||
'component:consul/hcp/home',
|
|
||||||
ConsulHcpHome
|
|
||||||
);
|
|
||||||
//
|
|
||||||
|
|
||||||
const Helper = this.owner.resolveRegistration('helper:env');
|
|
||||||
this.owner.register(
|
|
||||||
'helper:env',
|
|
||||||
class extends Helper {
|
|
||||||
compute([name, def]) {
|
|
||||||
switch(name) {
|
|
||||||
case 'CONSUL_HCP_URL':
|
|
||||||
return 'http://hcp';
|
|
||||||
}
|
|
||||||
return super.compute(...arguments);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
);
|
|
||||||
|
|
||||||
await render(hbs`
|
|
||||||
<Hds::SideNav::List as |SNL|>
|
|
||||||
<Consul::Hcp::Home @list={{SNL}} />
|
|
||||||
</Hds::SideNav::List>
|
|
||||||
`);
|
|
||||||
|
|
||||||
assert.dom('[data-test-back-to-hcp]').isVisible();
|
|
||||||
assert.dom('a').hasAttribute('href', 'http://hcp');
|
|
||||||
|
|
||||||
});
|
|
||||||
|
|
||||||
test('it does not output the Back to HCP link if CONSUL_HCP_URL is not present', async function(assert) {
|
|
||||||
// temporary registration until we are running as separate applications
|
|
||||||
this.owner.register(
|
|
||||||
'component:consul/hcp/home',
|
|
||||||
ConsulHcpHome
|
|
||||||
);
|
|
||||||
//
|
|
||||||
|
|
||||||
const Helper = this.owner.resolveRegistration('helper:env');
|
|
||||||
this.owner.register(
|
|
||||||
'helper:env',
|
|
||||||
class extends Helper {
|
|
||||||
compute([name, def]) {
|
|
||||||
switch(name) {
|
|
||||||
case 'CONSUL_HCP_URL':
|
|
||||||
return undefined;
|
|
||||||
}
|
|
||||||
return super.compute(...arguments);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
);
|
|
||||||
|
|
||||||
await render(hbs`
|
|
||||||
<Hds::SideNav::List as |SNL|>
|
|
||||||
<Consul::Hcp::Home @list={{SNL}} />
|
|
||||||
</Hds::SideNav::List>
|
|
||||||
`);
|
|
||||||
|
|
||||||
assert.dom('[data-test-back-to-hcp]').doesNotExist();
|
|
||||||
assert.dom('a').doesNotExist();
|
|
||||||
});
|
|
||||||
});
|
|
|
@ -1,5 +0,0 @@
|
||||||
{
|
|
||||||
"name": "consul-hcp",
|
|
||||||
"version": "0.1.0",
|
|
||||||
"private": true
|
|
||||||
}
|
|
|
@ -1,14 +0,0 @@
|
||||||
/**
|
|
||||||
* Copyright (c) HashiCorp, Inc.
|
|
||||||
* SPDX-License-Identifier: BUSL-1.1
|
|
||||||
*/
|
|
||||||
|
|
||||||
(routes => routes({
|
|
||||||
dc: {
|
|
||||||
show: null
|
|
||||||
},
|
|
||||||
}))(
|
|
||||||
(json, data = (typeof document !== 'undefined' ? document.currentScript.dataset : module.exports)) => {
|
|
||||||
data[`routes`] = JSON.stringify(json);
|
|
||||||
}
|
|
||||||
);
|
|
|
@ -1,14 +0,0 @@
|
||||||
/**
|
|
||||||
* Copyright (c) HashiCorp, Inc.
|
|
||||||
* SPDX-License-Identifier: BUSL-1.1
|
|
||||||
*/
|
|
||||||
|
|
||||||
(services => services({
|
|
||||||
'component:consul/hcp/home': {
|
|
||||||
class: 'consul-ui/components/consul/hcp/home',
|
|
||||||
},
|
|
||||||
}))(
|
|
||||||
(json, data = (typeof document !== 'undefined' ? document.currentScript.dataset : module.exports)) => {
|
|
||||||
data[`services`] = JSON.stringify(json);
|
|
||||||
}
|
|
||||||
);
|
|
|
@ -122,7 +122,7 @@
|
||||||
class='hds-side-nav-hide-when-minimized consul-side-nav__selector-group'
|
class='hds-side-nav-hide-when-minimized consul-side-nav__selector-group'
|
||||||
as |SNL|
|
as |SNL|
|
||||||
>
|
>
|
||||||
<Consul::Hcp::Home @list={{SNL}} />
|
<HcpNavItem @list={{SNL}}/>
|
||||||
<Consul::Datacenter::Selector
|
<Consul::Datacenter::Selector
|
||||||
@list={{SNL}}
|
@list={{SNL}}
|
||||||
@dc={{@dc}}
|
@dc={{@dc}}
|
||||||
|
|
|
@ -0,0 +1,15 @@
|
||||||
|
{{!
|
||||||
|
Copyright (c) HashiCorp, Inc.
|
||||||
|
SPDX-License-Identifier: BUSL-1.1
|
||||||
|
}}
|
||||||
|
|
||||||
|
{{#let @list (env "CONSUL_HCP_URL") as |SNL hcpUrl|}}
|
||||||
|
{{#if this.shouldShowBackToHcpItem}}
|
||||||
|
<SNL.BackLink
|
||||||
|
@text={{t "components.hashicorp-consul.side-nav.hcp"}}
|
||||||
|
@href={{hcpUrl}}
|
||||||
|
@isHrefExternal={{true}}
|
||||||
|
data-test-back-to-hcp
|
||||||
|
/>
|
||||||
|
{{/if}}
|
||||||
|
{{/let}}
|
|
@ -0,0 +1,21 @@
|
||||||
|
/**
|
||||||
|
* Copyright (c) HashiCorp, Inc.
|
||||||
|
* SPDX-License-Identifier: BUSL-1.1
|
||||||
|
*/
|
||||||
|
|
||||||
|
import Component from '@glimmer/component';
|
||||||
|
import { inject as service } from '@ember/service';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* If the user has accessed consul from HCP managed consul, we do NOT want to display the
|
||||||
|
* "HCP Consul Central↗️" link in the nav bar. As we're already displaying a BackLink to HCP.
|
||||||
|
*/
|
||||||
|
export default class HcpLinkItemComponent extends Component {
|
||||||
|
@service env;
|
||||||
|
|
||||||
|
get shouldShowBackToHcpItem() {
|
||||||
|
const isConsulHcpUrlDefined = !!this.env.var('CONSUL_HCP_URL');
|
||||||
|
const isConsulHcpEnabled = !!this.env.var('CONSUL_HCP_ENABLED');
|
||||||
|
return isConsulHcpEnabled && isConsulHcpUrlDefined;
|
||||||
|
}
|
||||||
|
}
|
|
@ -39,7 +39,6 @@ module.exports = function (defaults, $ = process.env) {
|
||||||
'consul-peerings',
|
'consul-peerings',
|
||||||
'consul-partitions',
|
'consul-partitions',
|
||||||
'consul-nspaces',
|
'consul-nspaces',
|
||||||
'consul-hcp',
|
|
||||||
].map((item) => {
|
].map((item) => {
|
||||||
return {
|
return {
|
||||||
name: item,
|
name: item,
|
||||||
|
|
|
@ -75,10 +75,6 @@ ${
|
||||||
{{if .NamespacesEnabled}}
|
{{if .NamespacesEnabled}}
|
||||||
<script src="${rootURL}assets/consul-nspaces/routes.js"></script>
|
<script src="${rootURL}assets/consul-nspaces/routes.js"></script>
|
||||||
{{end}}
|
{{end}}
|
||||||
{{if .HCPEnabled}}
|
|
||||||
<script src="${rootURL}assets/consul-hcp/services.js"></script>
|
|
||||||
<script src="${rootURL}assets/consul-hcp/routes.js"></script>
|
|
||||||
{{end}}
|
|
||||||
`
|
`
|
||||||
: `
|
: `
|
||||||
<script>
|
<script>
|
||||||
|
@ -112,10 +108,6 @@ ${
|
||||||
name: 'consul-nspaces',
|
name: 'consul-nspaces',
|
||||||
default: ${config.operatorConfig.NamespacesEnabled}
|
default: ${config.operatorConfig.NamespacesEnabled}
|
||||||
},
|
},
|
||||||
'CONSUL_HCP_ENABLE': {
|
|
||||||
name: 'consul-hcp',
|
|
||||||
default: ${config.operatorConfig.HCPEnabled}
|
|
||||||
},
|
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
</script>
|
</script>
|
||||||
|
|
|
@ -91,7 +91,6 @@
|
||||||
"chalk": "^4.1.0",
|
"chalk": "^4.1.0",
|
||||||
"clipboard": "^2.0.11",
|
"clipboard": "^2.0.11",
|
||||||
"consul-acls": "*",
|
"consul-acls": "*",
|
||||||
"consul-hcp": "*",
|
|
||||||
"consul-lock-sessions": "*",
|
"consul-lock-sessions": "*",
|
||||||
"consul-nspaces": "*",
|
"consul-nspaces": "*",
|
||||||
"consul-partitions": "*",
|
"consul-partitions": "*",
|
||||||
|
|
|
@ -1,7 +0,0 @@
|
||||||
/**
|
|
||||||
* Copyright (c) HashiCorp, Inc.
|
|
||||||
* SPDX-License-Identifier: BUSL-1.1
|
|
||||||
*/
|
|
||||||
|
|
||||||
// temporary import until we are running as separate applications
|
|
||||||
import 'consul-ui/components/consul/hcp/home/index.test';
|
|
|
@ -0,0 +1,76 @@
|
||||||
|
/**
|
||||||
|
* Copyright (c) HashiCorp, Inc.
|
||||||
|
* SPDX-License-Identifier: BUSL-1.1
|
||||||
|
*/
|
||||||
|
|
||||||
|
import { module, test } from 'qunit';
|
||||||
|
import { setupRenderingTest } from 'ember-qunit';
|
||||||
|
import { render } from '@ember/test-helpers';
|
||||||
|
import hbs from 'htmlbars-inline-precompile';
|
||||||
|
import { EnvStub } from 'consul-ui/services/env';
|
||||||
|
|
||||||
|
module('Integration | Component | hcp nav item', function (hooks) {
|
||||||
|
setupRenderingTest(hooks);
|
||||||
|
|
||||||
|
test('it prints the value of CONSUL_HCP_URL', async function (assert) {
|
||||||
|
this.owner.register(
|
||||||
|
'service:env',
|
||||||
|
class Stub extends EnvStub {
|
||||||
|
stubEnv = {
|
||||||
|
CONSUL_HCP_URL: 'http://hcp.com',
|
||||||
|
CONSUL_HCP_ENABLED: true,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
|
await render(hbs`
|
||||||
|
<Hds::SideNav::List as |SNL|>
|
||||||
|
<HcpNavItem @list={{SNL}} />
|
||||||
|
</Hds::SideNav::List>
|
||||||
|
`);
|
||||||
|
|
||||||
|
assert.dom('[data-test-back-to-hcp]').isVisible();
|
||||||
|
assert.dom('a').hasAttribute('href', 'http://hcp.com');
|
||||||
|
});
|
||||||
|
|
||||||
|
test('it does not output the Back to HCP link if CONSUL_HCP_URL is not present', async function (assert) {
|
||||||
|
this.owner.register(
|
||||||
|
'service:env',
|
||||||
|
class Stub extends EnvStub {
|
||||||
|
stubEnv = {
|
||||||
|
CONSUL_HCP_ENABLED: true,
|
||||||
|
CONSUL_HCP_URL: undefined,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
|
await render(hbs`
|
||||||
|
<Hds::SideNav::List as |SNL|>
|
||||||
|
<HcpNavItem @list={{SNL}} />
|
||||||
|
</Hds::SideNav::List>
|
||||||
|
`);
|
||||||
|
|
||||||
|
assert.dom('[data-test-back-to-hcp]').doesNotExist();
|
||||||
|
assert.dom('a').doesNotExist();
|
||||||
|
});
|
||||||
|
test('it does not output the Back to HCP link if CONSUL_HCP_ENABLED is not present', async function (assert) {
|
||||||
|
this.owner.register(
|
||||||
|
'service:env',
|
||||||
|
class Stub extends EnvStub {
|
||||||
|
stubEnv = {
|
||||||
|
CONSUL_HCP_URL: 'http://hcp.com',
|
||||||
|
CONSUL_HCP_ENABLED: undefined,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
|
await render(hbs`
|
||||||
|
<Hds::SideNav::List as |SNL|>
|
||||||
|
<HcpNavItem @list={{SNL}} />
|
||||||
|
</Hds::SideNav::List>
|
||||||
|
`);
|
||||||
|
|
||||||
|
assert.dom('[data-test-back-to-hcp]').doesNotExist();
|
||||||
|
assert.dom('a').doesNotExist();
|
||||||
|
});
|
||||||
|
});
|
|
@ -9,6 +9,7 @@ import { click, render } from '@ember/test-helpers';
|
||||||
import hbs from 'htmlbars-inline-precompile';
|
import hbs from 'htmlbars-inline-precompile';
|
||||||
import Service from '@ember/service';
|
import Service from '@ember/service';
|
||||||
import sinon from 'sinon';
|
import sinon from 'sinon';
|
||||||
|
import { EnvStub } from 'consul-ui/services/env';
|
||||||
|
|
||||||
const userDismissedBannerStub = sinon.stub();
|
const userDismissedBannerStub = sinon.stub();
|
||||||
const dismissHcpLinkBannerStub = sinon.stub();
|
const dismissHcpLinkBannerStub = sinon.stub();
|
||||||
|
@ -24,16 +25,16 @@ module('Integration | Component | link-to-hcp-banner', function (hooks) {
|
||||||
dismissHcpLinkBanner = dismissHcpLinkBannerStub;
|
dismissHcpLinkBanner = dismissHcpLinkBannerStub;
|
||||||
}
|
}
|
||||||
|
|
||||||
class EnvStub extends Service {
|
|
||||||
isEnterprise = false;
|
|
||||||
var(key) {
|
|
||||||
return key;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
hooks.beforeEach(function () {
|
hooks.beforeEach(function () {
|
||||||
this.owner.register('service:hcp-link-status', HcpLinkStatusStub);
|
this.owner.register('service:hcp-link-status', HcpLinkStatusStub);
|
||||||
this.owner.register('service:env', EnvStub);
|
this.owner.register(
|
||||||
|
'service:env',
|
||||||
|
class Stub extends EnvStub {
|
||||||
|
stubEnv = {
|
||||||
|
isEnterprise: false,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
test('it renders banner when hcp-link-status says it should', async function (assert) {
|
test('it renders banner when hcp-link-status says it should', async function (assert) {
|
||||||
|
@ -96,14 +97,16 @@ module('Integration | Component | link-to-hcp-banner', function (hooks) {
|
||||||
});
|
});
|
||||||
|
|
||||||
test('it displays different banner text when consul is enterprise', async function (assert) {
|
test('it displays different banner text when consul is enterprise', async function (assert) {
|
||||||
class EnvStub extends Service {
|
this.owner.register(
|
||||||
isEnterprise = true;
|
'service:env',
|
||||||
var(key) {
|
class Stub extends EnvStub {
|
||||||
return key;
|
stubEnv = {
|
||||||
|
isEnterprise: true,
|
||||||
|
};
|
||||||
}
|
}
|
||||||
}
|
);
|
||||||
this.owner.register('service:env', EnvStub);
|
|
||||||
this.linkData = { isLinked: false };
|
this.linkData = { isLinked: false };
|
||||||
|
|
||||||
await render(hbs`<LinkToHcpBanner @linkData={{this.linkData}} />`);
|
await render(hbs`<LinkToHcpBanner @linkData={{this.linkData}} />`);
|
||||||
assert
|
assert
|
||||||
.dom('[data-test-link-to-hcp-banner-description]')
|
.dom('[data-test-link-to-hcp-banner-description]')
|
||||||
|
|
Loading…
Reference in New Issue