2023-03-15 16:00:52 +00:00
|
|
|
/**
|
|
|
|
* Copyright (c) HashiCorp, Inc.
|
|
|
|
* SPDX-License-Identifier: MPL-2.0
|
|
|
|
*/
|
|
|
|
|
2020-09-17 19:08:06 +00:00
|
|
|
import EmberObject from '@ember/object';
|
|
|
|
import { module, test } from 'qunit';
|
|
|
|
import { setupRenderingTest } from 'ember-qunit';
|
2021-04-26 16:23:57 +00:00
|
|
|
import { render, click } from '@ember/test-helpers';
|
2020-09-17 19:08:06 +00:00
|
|
|
import hbs from 'htmlbars-inline-precompile';
|
|
|
|
|
2021-12-17 03:44:29 +00:00
|
|
|
module('Integration | Component | transform-list-item', function (hooks) {
|
2020-09-17 19:08:06 +00:00
|
|
|
setupRenderingTest(hooks);
|
|
|
|
|
2021-12-17 03:44:29 +00:00
|
|
|
test('it renders un-clickable item if no read capability', async function (assert) {
|
2022-11-09 23:15:31 +00:00
|
|
|
const item = EmberObject.create({
|
2020-09-17 19:08:06 +00:00
|
|
|
id: 'foo',
|
|
|
|
updatePath: {
|
|
|
|
canRead: false,
|
|
|
|
canDelete: true,
|
|
|
|
canUpdate: true,
|
|
|
|
},
|
|
|
|
});
|
|
|
|
this.set('itemPath', 'role/foo');
|
|
|
|
this.set('itemType', 'role');
|
|
|
|
this.set('item', item);
|
2021-06-02 14:59:31 +00:00
|
|
|
await render(hbs`<SecretList::TransformListItem
|
2022-10-18 15:46:02 +00:00
|
|
|
@item={{this.item}}
|
|
|
|
@itemPath={{this.itemPath}}
|
|
|
|
@itemType={{this.itemType}}
|
2020-09-17 19:08:06 +00:00
|
|
|
/>`);
|
|
|
|
|
|
|
|
assert.dom('[data-test-view-only-list-item]').exists('shows view only list item');
|
|
|
|
assert.dom('[data-test-view-only-list-item]').hasText(item.id, 'has correct label');
|
|
|
|
});
|
|
|
|
|
2021-12-17 03:44:29 +00:00
|
|
|
test('it is clickable with details menu item if read capability', async function (assert) {
|
2022-11-09 23:15:31 +00:00
|
|
|
const item = EmberObject.create({
|
2020-09-17 19:08:06 +00:00
|
|
|
id: 'foo',
|
|
|
|
updatePath: {
|
|
|
|
canRead: true,
|
|
|
|
canDelete: false,
|
|
|
|
canUpdate: false,
|
|
|
|
},
|
|
|
|
});
|
|
|
|
this.set('itemPath', 'template/foo');
|
|
|
|
this.set('itemType', 'template');
|
|
|
|
this.set('item', item);
|
2021-06-02 14:59:31 +00:00
|
|
|
await render(hbs`<SecretList::TransformListItem
|
2022-10-18 15:46:02 +00:00
|
|
|
@item={{this.item}}
|
|
|
|
@itemPath={{this.itemPath}}
|
|
|
|
@itemType={{this.itemType}}
|
2020-09-17 19:08:06 +00:00
|
|
|
/>`);
|
|
|
|
|
|
|
|
assert.dom('[data-test-secret-link="template/foo"]').exists('shows clickable list item');
|
|
|
|
await click('button.popup-menu-trigger');
|
2021-04-26 16:23:57 +00:00
|
|
|
assert.dom('.popup-menu-content li').exists({ count: 1 }, 'has one option');
|
2020-09-17 19:08:06 +00:00
|
|
|
});
|
|
|
|
|
2021-12-17 03:44:29 +00:00
|
|
|
test('it has details and edit menu item if read & edit capabilities', async function (assert) {
|
2022-11-09 23:15:31 +00:00
|
|
|
const item = EmberObject.create({
|
2020-09-17 19:08:06 +00:00
|
|
|
id: 'foo',
|
|
|
|
updatePath: {
|
|
|
|
canRead: true,
|
|
|
|
canDelete: true,
|
|
|
|
canUpdate: true,
|
|
|
|
},
|
|
|
|
});
|
|
|
|
this.set('itemPath', 'alphabet/foo');
|
|
|
|
this.set('itemType', 'alphabet');
|
|
|
|
this.set('item', item);
|
2021-06-02 14:59:31 +00:00
|
|
|
await render(hbs`<SecretList::TransformListItem
|
2022-10-18 15:46:02 +00:00
|
|
|
@item={{this.item}}
|
|
|
|
@itemPath={{this.itemPath}}
|
|
|
|
@itemType={{this.itemType}}
|
2020-09-17 19:08:06 +00:00
|
|
|
/>`);
|
|
|
|
|
|
|
|
assert.dom('[data-test-secret-link="alphabet/foo"]').exists('shows clickable list item');
|
|
|
|
await click('button.popup-menu-trigger');
|
2021-04-26 16:23:57 +00:00
|
|
|
assert.dom('.popup-menu-content li').exists({ count: 2 }, 'has both options');
|
2020-09-17 19:08:06 +00:00
|
|
|
});
|
|
|
|
|
2021-12-17 03:44:29 +00:00
|
|
|
test('it is not clickable if built-in template with all capabilities', async function (assert) {
|
2022-11-09 23:15:31 +00:00
|
|
|
const item = EmberObject.create({
|
2020-09-17 19:08:06 +00:00
|
|
|
id: 'builtin/foo',
|
|
|
|
updatePath: {
|
|
|
|
canRead: true,
|
|
|
|
canDelete: true,
|
|
|
|
canUpdate: true,
|
|
|
|
},
|
|
|
|
});
|
|
|
|
this.set('itemPath', 'template/builtin/foo');
|
|
|
|
this.set('itemType', 'template');
|
|
|
|
this.set('item', item);
|
2021-06-02 14:59:31 +00:00
|
|
|
await render(hbs`<SecretList::TransformListItem
|
2022-10-18 15:46:02 +00:00
|
|
|
@item={{this.item}}
|
|
|
|
@itemPath={{this.itemPath}}
|
|
|
|
@itemType={{this.itemType}}
|
2020-09-17 19:08:06 +00:00
|
|
|
/>`);
|
|
|
|
|
|
|
|
assert.dom('[data-test-view-only-list-item]').exists('shows view only list item');
|
|
|
|
assert.dom('[data-test-view-only-list-item]').hasText(item.id, 'has correct label');
|
|
|
|
});
|
|
|
|
|
2021-12-17 03:44:29 +00:00
|
|
|
test('it is not clickable if built-in alphabet', async function (assert) {
|
2022-11-09 23:15:31 +00:00
|
|
|
const item = EmberObject.create({
|
2020-09-17 19:08:06 +00:00
|
|
|
id: 'builtin/foo',
|
|
|
|
updatePath: {
|
|
|
|
canRead: true,
|
|
|
|
canDelete: true,
|
|
|
|
canUpdate: true,
|
|
|
|
},
|
|
|
|
});
|
|
|
|
this.set('itemPath', 'alphabet/builtin/foo');
|
|
|
|
this.set('itemType', 'alphabet');
|
|
|
|
this.set('item', item);
|
2021-06-02 14:59:31 +00:00
|
|
|
await render(hbs`<SecretList::TransformListItem
|
2022-10-18 15:46:02 +00:00
|
|
|
@item={{this.item}}
|
|
|
|
@itemPath={{this.itemPath}}
|
|
|
|
@itemType={{this.itemType}}
|
2020-09-17 19:08:06 +00:00
|
|
|
/>`);
|
|
|
|
|
|
|
|
assert.dom('[data-test-view-only-list-item]').exists('shows view only list item');
|
|
|
|
assert.dom('[data-test-view-only-list-item]').hasText(item.id, 'has correct label');
|
|
|
|
});
|
|
|
|
});
|