* chore: 🤖 Add initial page layout for code editor + sidebar (#3180) * chore: 🤖 Add initial page layout for code editor + sidebar * test: 💍 add missing a11y ignores for exisitng color issue ✅ Closes: https://hashicorp.atlassian.net/browse/ICU-18460 * Replace `Rose::CodeEditor` with `Hds::CodeEditor` (#2679) * chore: 🤖 replace Rose::CodeEditor with Hds::CodeEditor - Remove CodeEditor 5 dependency * chore: 🤖 Replace CodeMirror5 dep remove CodeMirror5 and replace existing editors with HDS::CodeEditor * chore: 🤖 deleting old codeeditor styles * feat: 🎸 changing code editor changing code editor ✅ Closes: 0 * removed unused export * pr cleanup * updating tests for new code editor * responding to PR feedback * added whitespace * fixing linting violations * chore: 🤖 self-review PR self-review PR in the course of switching to new HDS code editor * fix: 🐛 fix linting bug * fix: 🐛 unneeded dependency remove jslint dependency as this is handled in the new code editor from HDS * fix: 🐛 Fixing import bug Fix import bug caused by importing scss modules that no longer exist * Fix and refactor code editor acceptance test * Fix and refactor code editor acceptance test * chore: 🤖 remove codemirror dependency * refactor: 💡 fix merge conflict issues * test: 💍 update e2e test selectors * test: 💍 fix target spec click event * refactor: 💡 clean up test selectors for code editor * refactor: 💡 clean up storage bucket test selectors * chore: 🤖 remove code mirror modifiers --------- Co-authored-by: calcaide <ccorvo@hashicorp.com> Co-authored-by: cameronperera <cameron.perera@hashicorp.com> * feat: 🎸 Create string formats component (#3191) * feat: 🎸 Create string formats component * Add missing copyright headers * fix: 🐛 change to readonly ✅ Closes: https://hashicorp.atlassian.net/browse/ICU-18458 * feat: 🎸 add grant schema to mirage (#3196) * feat: 🎸 add grant schema to mirage * refactor: 💡 update grant schema mirage data * refactor: 💡 fix route name in mirage * feat: 🎸 add export options flyout (#3198) * feat: 🎸 add export options flyout * fix: 🐛 update id to be ids * test: 💍 add a11y ignores * test: 💍 fix tests for grant string format ✅ Closes: https://hashicorp.atlassian.net/browse/ICU-18524 * feat: 🎸 Add autocompletion to code editor (#3207) * feat: 🎸 create grant actions component * feat: 🎸 add description to actions * feat: 🎸 update default logic to not show all actions * feat: 🎸 show invalid id and type message * test: 💍 create const for test selectors * feat: 🎸 trigger action suggestion when cursor moves * refactor: 💡 add createGrantLineHelpers func * refactor: 💡 small refactors * feat: 🎸 Add CSP nonce to code editors (#3230) Co-authored-by: Zhihe Li <zhihe.li@hashicorp.com> * refactor: 💡 small refactor * test: 💍 add more tests * refactor: 💡 fix merge conflicts issues * refactor: 💡 updates from PR feedback * refactor: 💡 updates for completions and linting * test: 💍 fix test issue with translations * test: 💍 fix test issue that was already fixed once * refactor: 💡 address PR feedback --------- Co-authored-by: Lisbet Alvarez <107949262+lisbet-alvarez@users.noreply.github.com> Co-authored-by: Zack Moore <zack.moore@hashicorp.com> Co-authored-by: calcaide <ccorvo@hashicorp.com> Co-authored-by: Zhihe Li <zhihe.li@hashicorp.com> Co-authored-by: Bharath Gajjala <120367134+bgajjala8@users.noreply.github.com>
273 lines
8.0 KiB
JavaScript
273 lines
8.0 KiB
JavaScript
/**
|
|
* Copyright IBM Corp. 2021, 2026
|
|
* SPDX-License-Identifier: BUSL-1.1
|
|
*/
|
|
|
|
import { module, test } from 'qunit';
|
|
import { setupRenderingTest } from 'admin/tests/helpers';
|
|
import { setupIntl } from 'ember-intl/test-support';
|
|
import { render } from '@ember/test-helpers';
|
|
import { hbs } from 'ember-cli-htmlbars';
|
|
import * as commonSelectors from 'admin/tests/helpers/selectors';
|
|
|
|
const GRANT_ACTIONS_TABLE = '[data-test-grant-actions-table]';
|
|
const GRANT_ACTIONS_EMPTY_STATE = '[data-test-grant-actions-empty-state]';
|
|
const GRANT_ACTIONS_NO_TYPE_DETECTED =
|
|
'[data-test-grant-actions-no-type-detected]';
|
|
const GRANT_ACTIONS_INVALID_ID_OR_TYPE =
|
|
'[data-test-grant-actions-invalid-id-or-type]';
|
|
|
|
module('Integration | Component | grant-actions/index', function (hooks) {
|
|
setupRenderingTest(hooks);
|
|
setupIntl(hooks, 'en-us');
|
|
|
|
hooks.beforeEach(function () {
|
|
this.grantsSchema = {
|
|
resource_types: [
|
|
{
|
|
type: 'host-catalog',
|
|
collection_actions: ['create', 'list'],
|
|
id_actions: ['read', 'update', 'delete'],
|
|
id_prefixes: ['hcst'],
|
|
},
|
|
{
|
|
type: 'host',
|
|
parent_type: 'host-catalog',
|
|
collection_actions: ['create', 'list'],
|
|
id_actions: ['read', 'update', 'delete'],
|
|
id_prefixes: ['h'],
|
|
},
|
|
{
|
|
type: 'host-set',
|
|
parent_type: 'host-catalog',
|
|
collection_actions: ['create', 'list'],
|
|
id_actions: [
|
|
'delete',
|
|
'add-hosts',
|
|
'set-hosts',
|
|
'remove-hosts',
|
|
'read',
|
|
'update',
|
|
],
|
|
id_prefixes: ['hs'],
|
|
},
|
|
],
|
|
};
|
|
});
|
|
|
|
test('it renders the actions relevant to the current grant line', async function (assert) {
|
|
this.grantString = 'ids=hcst_1234567890;type=host-set';
|
|
|
|
await render(hbs`
|
|
<GrantActions
|
|
@grantsSchema={{this.grantsSchema}}
|
|
@grantString={{this.grantString}}
|
|
/>
|
|
`);
|
|
|
|
assert.dom(GRANT_ACTIONS_TABLE).isVisible();
|
|
assert.dom(commonSelectors.TABLE_ROWS).isVisible({ count: 8 });
|
|
|
|
const rows = [...this.element.querySelectorAll(commonSelectors.TABLE_ROWS)];
|
|
const rowData = rows.map((row) => {
|
|
const cells = [...row.querySelectorAll('td')].map((cell) =>
|
|
cell.textContent.trim(),
|
|
);
|
|
|
|
return {
|
|
name: cells[0],
|
|
description: cells[1],
|
|
};
|
|
});
|
|
|
|
assert.deepEqual(
|
|
rowData.map(({ name }) => name),
|
|
[
|
|
'add-hosts',
|
|
'create',
|
|
'delete',
|
|
'list',
|
|
'read',
|
|
'remove-hosts',
|
|
'set-hosts',
|
|
'update',
|
|
],
|
|
);
|
|
|
|
assert.deepEqual(rowData[0], {
|
|
name: 'add-hosts',
|
|
description: 'Add hosts to a host set',
|
|
});
|
|
|
|
assert.deepEqual(rowData[1], {
|
|
name: 'create',
|
|
description: 'Create a new host-set',
|
|
});
|
|
|
|
assert.deepEqual(rowData.at(-1), {
|
|
name: 'update',
|
|
description: 'Update a host-set',
|
|
});
|
|
|
|
assert.dom(GRANT_ACTIONS_EMPTY_STATE).doesNotExist();
|
|
assert.dom(GRANT_ACTIONS_NO_TYPE_DETECTED).doesNotExist();
|
|
});
|
|
|
|
test('it renders the no resource type detected state when the current line has no detectable type', async function (assert) {
|
|
this.grantString = 'output_fields=*';
|
|
|
|
await render(hbs`
|
|
<GrantActions
|
|
@grantsSchema={{this.grantsSchema}}
|
|
@grantString={{this.grantString}}
|
|
/>
|
|
`);
|
|
|
|
assert.dom(GRANT_ACTIONS_TABLE).doesNotExist();
|
|
assert.dom(GRANT_ACTIONS_INVALID_ID_OR_TYPE).doesNotExist();
|
|
assert
|
|
.dom(GRANT_ACTIONS_NO_TYPE_DETECTED)
|
|
.hasText('No resource type detected.');
|
|
assert.dom(GRANT_ACTIONS_EMPTY_STATE).doesNotExist();
|
|
});
|
|
|
|
test('it renders the invalid ID and type state for an unknown type', async function (assert) {
|
|
this.grantString = 'type=not-a-real-type;actions=';
|
|
|
|
await render(hbs`
|
|
<GrantActions
|
|
@grantsSchema={{this.grantsSchema}}
|
|
@grantString={{this.grantString}}
|
|
/>
|
|
`);
|
|
|
|
assert.dom(GRANT_ACTIONS_TABLE).doesNotExist();
|
|
assert.dom(GRANT_ACTIONS_NO_TYPE_DETECTED).doesNotExist();
|
|
assert.dom(GRANT_ACTIONS_EMPTY_STATE).doesNotExist();
|
|
assert
|
|
.dom(GRANT_ACTIONS_INVALID_ID_OR_TYPE)
|
|
.hasText('Invalid ID and type. No actions available.');
|
|
});
|
|
|
|
test('it renders the invalid ID and type state for an unknown ID', async function (assert) {
|
|
this.grantString = 'ids=bad_123;actions=';
|
|
|
|
await render(hbs`
|
|
<GrantActions
|
|
@grantsSchema={{this.grantsSchema}}
|
|
@grantString={{this.grantString}}
|
|
/>
|
|
`);
|
|
|
|
assert.dom(GRANT_ACTIONS_TABLE).doesNotExist();
|
|
assert.dom(GRANT_ACTIONS_NO_TYPE_DETECTED).doesNotExist();
|
|
assert.dom(GRANT_ACTIONS_EMPTY_STATE).doesNotExist();
|
|
assert
|
|
.dom(GRANT_ACTIONS_INVALID_ID_OR_TYPE)
|
|
.hasText('Invalid ID and type. No actions available.');
|
|
});
|
|
|
|
test('it keeps the no suggestions state when a type is known but no actions apply', async function (assert) {
|
|
this.grantString = 'type=host;actions=';
|
|
|
|
await render(hbs`
|
|
<GrantActions
|
|
@grantsSchema={{this.grantsSchema}}
|
|
@grantString={{this.grantString}}
|
|
/>
|
|
`);
|
|
|
|
assert.dom(GRANT_ACTIONS_TABLE).doesNotExist();
|
|
assert.dom(GRANT_ACTIONS_INVALID_ID_OR_TYPE).doesNotExist();
|
|
assert.dom(GRANT_ACTIONS_NO_TYPE_DETECTED).doesNotExist();
|
|
assert.dom(GRANT_ACTIONS_EMPTY_STATE).hasText('No suggestions');
|
|
});
|
|
|
|
test('it renders the no-type-detected state for an empty grant string', async function (assert) {
|
|
this.grantString = '';
|
|
|
|
await render(hbs`
|
|
<GrantActions
|
|
@grantsSchema={{this.grantsSchema}}
|
|
@grantString={{this.grantString}}
|
|
/>
|
|
`);
|
|
|
|
assert.dom(GRANT_ACTIONS_TABLE).doesNotExist();
|
|
assert.dom(GRANT_ACTIONS_INVALID_ID_OR_TYPE).doesNotExist();
|
|
assert
|
|
.dom(GRANT_ACTIONS_NO_TYPE_DETECTED)
|
|
.hasText('No resource type detected.');
|
|
assert.dom(GRANT_ACTIONS_EMPTY_STATE).doesNotExist();
|
|
});
|
|
|
|
test('it renders the no-type-detected state for template IDs', async function (assert) {
|
|
this.grantString = 'ids={{.User.Id}}';
|
|
|
|
await render(hbs`
|
|
<GrantActions
|
|
@grantsSchema={{this.grantsSchema}}
|
|
@grantString={{this.grantString}}
|
|
/>
|
|
`);
|
|
|
|
assert.dom(GRANT_ACTIONS_TABLE).doesNotExist();
|
|
assert.dom(GRANT_ACTIONS_INVALID_ID_OR_TYPE).doesNotExist();
|
|
assert
|
|
.dom(GRANT_ACTIONS_NO_TYPE_DETECTED)
|
|
.hasText('No resource type detected.');
|
|
assert.dom(GRANT_ACTIONS_EMPTY_STATE).doesNotExist();
|
|
});
|
|
|
|
test('it renders the invalid state for a pinned id paired with its own type instead of a child type', async function (assert) {
|
|
this.grantString = 'ids=hcst_1234567890;type=host-catalog';
|
|
|
|
await render(hbs`
|
|
<GrantActions
|
|
@grantsSchema={{this.grantsSchema}}
|
|
@grantString={{this.grantString}}
|
|
/>
|
|
`);
|
|
|
|
assert.dom(GRANT_ACTIONS_TABLE).doesNotExist();
|
|
assert.dom(GRANT_ACTIONS_NO_TYPE_DETECTED).doesNotExist();
|
|
assert.dom(GRANT_ACTIONS_EMPTY_STATE).doesNotExist();
|
|
assert
|
|
.dom(GRANT_ACTIONS_INVALID_ID_OR_TYPE)
|
|
.hasText('Invalid ID and type. No actions available.');
|
|
});
|
|
|
|
test('it renders only CRUDL actions with fallback descriptions when type is wildcard', async function (assert) {
|
|
this.grantString = 'ids=*;type=*';
|
|
|
|
await render(hbs`
|
|
<GrantActions
|
|
@grantsSchema={{this.grantsSchema}}
|
|
@grantString={{this.grantString}}
|
|
/>
|
|
`);
|
|
|
|
assert.dom(GRANT_ACTIONS_TABLE).isVisible();
|
|
|
|
const rows = [...this.element.querySelectorAll(commonSelectors.TABLE_ROWS)];
|
|
const rowNames = rows.map((row) =>
|
|
row.querySelector('td')?.textContent.trim(),
|
|
);
|
|
|
|
assert.deepEqual(
|
|
rowNames,
|
|
['create', 'delete', 'list', 'read', 'update'],
|
|
'only CRUDL actions are shown for wildcard grants',
|
|
);
|
|
|
|
const createRow = rows.find(
|
|
(row) => row.querySelector('td')?.textContent.trim() === 'create',
|
|
);
|
|
assert.strictEqual(
|
|
createRow.querySelectorAll('td')[1].textContent.trim(),
|
|
'Creates resources',
|
|
'description falls back to generic when no resource type is detected',
|
|
);
|
|
});
|
|
});
|