2022-10-13 16:21:56 +00:00
|
|
|
import { module, test } from 'qunit';
|
|
|
|
import { setupRenderingTest } from 'ember-qunit';
|
|
|
|
import hbs from 'htmlbars-inline-precompile';
|
|
|
|
import { click, render } from '@ember/test-helpers';
|
2022-10-14 18:21:25 +00:00
|
|
|
import sinon from 'sinon';
|
2022-10-13 16:21:56 +00:00
|
|
|
|
|
|
|
module('Integration | Component | consul node agentless-notice', function (hooks) {
|
|
|
|
setupRenderingTest(hooks);
|
2022-10-14 18:21:25 +00:00
|
|
|
hooks.beforeEach(() => {
|
|
|
|
const localStore = {};
|
|
|
|
|
|
|
|
sinon.stub(window.localStorage, 'getItem').callsFake((key) => localStore[key]);
|
|
|
|
sinon.stub(window.localStorage, 'setItem').callsFake((key, value) => (localStore[key] = value));
|
|
|
|
});
|
2022-10-13 16:21:56 +00:00
|
|
|
|
|
|
|
test('it does not display the notice if the filtered nodes are the same as the regular nodes', async function (assert) {
|
|
|
|
this.set('nodes', [
|
|
|
|
{
|
|
|
|
Meta: {
|
|
|
|
'synthetic-node': false,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
]);
|
|
|
|
|
|
|
|
this.set('filteredNodes', [
|
|
|
|
{
|
|
|
|
Meta: {
|
|
|
|
'synthetic-node': false,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
]);
|
|
|
|
|
|
|
|
await render(
|
|
|
|
hbs`<Consul::Node::AgentlessNotice @items={{this.nodes}} @filteredItems={{this.filteredNodes}} />`
|
|
|
|
);
|
2022-10-14 18:21:25 +00:00
|
|
|
assert.true(window.localStorage.getItem.called);
|
2022-10-13 16:21:56 +00:00
|
|
|
assert
|
|
|
|
.dom('[data-test-node-agentless-notice]')
|
|
|
|
.doesNotExist(
|
|
|
|
'The agentless notice should not display if the items are the same as the filtered items'
|
|
|
|
);
|
|
|
|
});
|
|
|
|
|
|
|
|
test('it does display the notice when the filtered items are smaller then the regular items', async function (assert) {
|
|
|
|
this.set('nodes', [
|
|
|
|
{
|
|
|
|
Meta: {
|
2022-10-13 16:38:26 +00:00
|
|
|
'synthetic-node': true,
|
2022-10-13 16:21:56 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
]);
|
|
|
|
|
|
|
|
this.set('filteredNodes', []);
|
|
|
|
|
|
|
|
await render(
|
|
|
|
hbs`<Consul::Node::AgentlessNotice @items={{this.nodes}} @filteredItems={{this.filteredNodes}} />`
|
|
|
|
);
|
|
|
|
|
|
|
|
assert
|
|
|
|
.dom('[data-test-node-agentless-notice]')
|
|
|
|
.exists(
|
|
|
|
'The agentless notice should display if their are less items then the filtered items'
|
|
|
|
);
|
|
|
|
|
|
|
|
await click('button');
|
|
|
|
assert
|
|
|
|
.dom('[data-test-node-agentless-notice]')
|
2022-10-13 16:59:48 +00:00
|
|
|
.doesNotExist('The agentless notice be dismissed');
|
2022-10-14 18:21:25 +00:00
|
|
|
assert.true(
|
|
|
|
window.localStorage.setItem.calledOnceWith('consul-nodes-agentless-notice-dismissed', 'true'),
|
|
|
|
"Set the key in localstorage to 'true'"
|
|
|
|
);
|
|
|
|
});
|
|
|
|
|
|
|
|
test('it does not display if the localstorage key is already set to true', async function (assert) {
|
|
|
|
this.set('nodes', [
|
|
|
|
{
|
|
|
|
Meta: {
|
|
|
|
'synthetic-node': false,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
]);
|
|
|
|
|
|
|
|
this.set('filteredNodes', [
|
|
|
|
{
|
|
|
|
Meta: {
|
|
|
|
'synthetic-node': false,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
]);
|
|
|
|
|
2022-10-14 20:08:40 +00:00
|
|
|
window.localStorage.setItem('consul-nodes-agentless-notice-dismissed-partition', 'true');
|
2022-10-14 18:21:25 +00:00
|
|
|
|
|
|
|
await render(
|
2022-10-14 20:08:40 +00:00
|
|
|
hbs`<Consul::Node::AgentlessNotice @items={{this.nodes}} @filteredItems={{this.filteredNodes}} @postfix="partition" />`
|
2022-10-14 18:21:25 +00:00
|
|
|
);
|
|
|
|
|
|
|
|
assert.true(
|
2022-10-14 20:08:40 +00:00
|
|
|
window.localStorage.getItem.calledOnceWith(
|
|
|
|
'consul-nodes-agentless-notice-dismissed-partition'
|
|
|
|
)
|
2022-10-14 18:21:25 +00:00
|
|
|
);
|
|
|
|
|
|
|
|
assert
|
|
|
|
.dom('[data-test-node-agentless-notice]')
|
|
|
|
.doesNotExist(
|
|
|
|
"The agentless notice should not display if the local storage key has already been set to 'true'"
|
|
|
|
);
|
2022-10-13 16:21:56 +00:00
|
|
|
});
|
|
|
|
});
|