refactor: 💡 add custom sort to resources (#2860)
* refactor: 💡 add custom sort * test: 💍 fix tests * test: 💍 fix more tests * refactor: 💡 use reusable sort function for name * refactor: 💡 use sort util in all resources w/ optional name * Add missing copyright headers * test: 💍 fix broken tests & add tests for new util * refactor: 💡 add name custom sort to users * test: 💍 fix import in tests * refactor: 💡 add custom name sort to scopes * test: 💍 pr feedback on util test cases * refactor: 💡 move sort function into object (pr feedback)
This commit is contained in:
1 parent
4c959ab297
commit
738fa1f15f
27 files changed
+331
-41
No files matched your search
@@ -14,6 +14,7 @@ import {
|
||||
import { setupApplicationTest } from 'admin/tests/helpers';
|
||||
import setupMirage from 'ember-cli-mirage/test-support/setup-mirage';
|
||||
import { setupIndexedDb } from 'api/test-support/helpers/indexed-db';
|
||||
import { setupIntl } from 'ember-intl/test-support';
|
||||
import { Response } from 'miragejs';
|
||||
import a11yAudit from 'ember-a11y-testing/test-support/audit';
|
||||
import {
|
||||
@@ -32,6 +33,7 @@ module('Acceptance | authentication', function (hooks) {
|
||||
setupApplicationTest(hooks);
|
||||
setupMirage(hooks);
|
||||
setupIndexedDb(hooks);
|
||||
setupIntl(hooks, 'en-us');
|
||||
|
||||
let indexURL;
|
||||
let globalScope;
|
||||
|
||||
@@ -187,6 +187,14 @@ module('Acceptance | roles | list', function (hooks) {
|
||||
expectedAscendingSort: ['Alpha', 'Beta', 'Delta', 'Epsilon', 'Gamma'],
|
||||
column: 1,
|
||||
},
|
||||
'on grants applied': {
|
||||
attribute: {
|
||||
key: 'grant_scope_ids',
|
||||
values: [[GRANT_SCOPE_THIS], [GRANT_SCOPE_THIS], [], [], []],
|
||||
},
|
||||
expectedAscendingSort: ['No', 'No', 'No', 'Yes', 'Yes'],
|
||||
column: 2,
|
||||
},
|
||||
'on id': {
|
||||
attribute: {
|
||||
key: 'id',
|
||||
|
||||
@@ -8,6 +8,7 @@ import { visit, currentURL, click, fillIn, waitFor } from '@ember/test-helpers';
|
||||
import { setupApplicationTest } from 'admin/tests/helpers';
|
||||
import setupMirage from 'ember-cli-mirage/test-support/setup-mirage';
|
||||
import { setupIndexedDb } from 'api/test-support/helpers/indexed-db';
|
||||
import { setupIntl } from 'ember-intl/test-support';
|
||||
import { authenticateSession } from 'ember-simple-auth/test-support';
|
||||
import { faker } from '@faker-js/faker';
|
||||
import * as commonSelectors from 'admin/tests/helpers/selectors';
|
||||
@@ -22,6 +23,7 @@ module('Acceptance | session recordings | list', function (hooks) {
|
||||
setupApplicationTest(hooks);
|
||||
setupMirage(hooks);
|
||||
setupIndexedDb(hooks);
|
||||
setupIntl(hooks, 'en-us');
|
||||
|
||||
const CREATED_TIME_VALUES_ARRAY = [
|
||||
'2020-01-01T00:00:00.010Z',
|
||||
@@ -288,7 +290,7 @@ module('Acceptance | session recordings | list', function (hooks) {
|
||||
STATE_SESSION_RECORDING_STARTED,
|
||||
],
|
||||
},
|
||||
expectedAscendingSort: ['Completed', 'Recording', 'Failed'],
|
||||
expectedAscendingSort: ['Completed', 'Failed', 'Recording'],
|
||||
column: 2,
|
||||
},
|
||||
},
|
||||
|
||||
@@ -10,6 +10,7 @@ import setupMirage from 'ember-cli-mirage/test-support/setup-mirage';
|
||||
import a11yAudit from 'ember-a11y-testing/test-support/audit';
|
||||
import { authenticateSession } from 'ember-simple-auth/test-support';
|
||||
import { setupIndexedDb } from 'api/test-support/helpers/indexed-db';
|
||||
import { setupIntl } from 'ember-intl/test-support';
|
||||
import * as commonSelectors from 'admin/tests/helpers/selectors';
|
||||
import * as selectors from './selectors';
|
||||
|
||||
@@ -17,6 +18,7 @@ module('Acceptance | session-recordings | read', function (hooks) {
|
||||
setupApplicationTest(hooks);
|
||||
setupMirage(hooks);
|
||||
setupIndexedDb(hooks);
|
||||
setupIntl(hooks, 'en-us');
|
||||
|
||||
let featuresService;
|
||||
|
||||
|
||||
+2
@@ -11,6 +11,7 @@ import a11yAudit from 'ember-a11y-testing/test-support/audit';
|
||||
import { authenticateSession } from 'ember-simple-auth/test-support';
|
||||
import { Response } from 'miragejs';
|
||||
import { setupIndexedDb } from 'api/test-support/helpers/indexed-db';
|
||||
import { setupIntl } from 'ember-intl/test-support';
|
||||
import * as commonSelectors from 'admin/tests/helpers/selectors';
|
||||
import * as selectors from '../../selectors';
|
||||
|
||||
@@ -20,6 +21,7 @@ module(
|
||||
setupApplicationTest(hooks);
|
||||
setupMirage(hooks);
|
||||
setupIndexedDb(hooks);
|
||||
setupIntl(hooks, 'en-us');
|
||||
|
||||
let featuresService;
|
||||
let getRecordingCount;
|
||||
|
||||
@@ -11,6 +11,7 @@ import a11yAudit from 'ember-a11y-testing/test-support/audit';
|
||||
import { Response } from 'miragejs';
|
||||
import { authenticateSession } from 'ember-simple-auth/test-support';
|
||||
import { setupIndexedDb } from 'api/test-support/helpers/indexed-db';
|
||||
import { setupIntl } from 'ember-intl/test-support';
|
||||
import * as commonSelectors from 'admin/tests/helpers/selectors';
|
||||
|
||||
import { TYPE_TARGET_TCP, TYPE_TARGET_SSH } from 'api/models/target';
|
||||
@@ -19,6 +20,7 @@ module('Acceptance | targets | create-alias', function (hooks) {
|
||||
setupApplicationTest(hooks);
|
||||
setupMirage(hooks);
|
||||
setupIndexedDb(hooks);
|
||||
setupIntl(hooks, 'en-us');
|
||||
|
||||
let getAliasCount;
|
||||
let featuresService;
|
||||
|
||||
@@ -17,6 +17,7 @@ import { Response } from 'miragejs';
|
||||
import { authenticateSession } from 'ember-simple-auth/test-support';
|
||||
import { TYPE_TARGET_TCP, TYPE_TARGET_SSH } from 'api/models/target';
|
||||
import { setupIndexedDb } from 'api/test-support/helpers/indexed-db';
|
||||
import { setupIntl } from 'ember-intl/test-support';
|
||||
import * as commonSelectors from 'admin/tests/helpers/selectors';
|
||||
import * as selectors from './selectors';
|
||||
|
||||
@@ -24,6 +25,7 @@ module('Acceptance | targets | create', function (hooks) {
|
||||
setupApplicationTest(hooks);
|
||||
setupMirage(hooks);
|
||||
setupIndexedDb(hooks);
|
||||
setupIntl(hooks, 'en-us');
|
||||
|
||||
let getTargetCount;
|
||||
let getTCPTargetCount;
|
||||
|
||||
@@ -8,6 +8,7 @@ import { visit, click, currentURL } from '@ember/test-helpers';
|
||||
import { setupApplicationTest } from 'admin/tests/helpers';
|
||||
import setupMirage from 'ember-cli-mirage/test-support/setup-mirage';
|
||||
import { setupIndexedDb } from 'api/test-support/helpers/indexed-db';
|
||||
import { setupIntl } from 'ember-intl/test-support';
|
||||
import { Response } from 'miragejs';
|
||||
import { authenticateSession } from 'ember-simple-auth/test-support';
|
||||
import * as commonSelectors from 'admin/tests/helpers/selectors';
|
||||
@@ -17,6 +18,7 @@ module('Acceptance | targets | delete', function (hooks) {
|
||||
setupApplicationTest(hooks);
|
||||
setupMirage(hooks);
|
||||
setupIndexedDb(hooks);
|
||||
setupIntl(hooks, 'en-us');
|
||||
|
||||
let getTargetCount;
|
||||
|
||||
|
||||
@@ -15,6 +15,7 @@ import {
|
||||
import { setupApplicationTest } from 'admin/tests/helpers';
|
||||
import setupMirage from 'ember-cli-mirage/test-support/setup-mirage';
|
||||
import { setupIndexedDb } from 'api/test-support/helpers/indexed-db';
|
||||
import { setupIntl } from 'ember-intl/test-support';
|
||||
import { authenticateSession } from 'ember-simple-auth/test-support';
|
||||
import { TYPE_TARGET_TCP, TYPE_TARGET_SSH } from 'api/models/target';
|
||||
import { STATUS_SESSION_ACTIVE } from 'api/models/session';
|
||||
@@ -26,6 +27,7 @@ module('Acceptance | targets | list', function (hooks) {
|
||||
setupApplicationTest(hooks);
|
||||
setupMirage(hooks);
|
||||
setupIndexedDb(hooks);
|
||||
setupIntl(hooks, 'en-us');
|
||||
|
||||
const NAME_VALUES_ARRAY = ['Alpha', 'Beta', 'Delta', 'Epsilon', 'Gamma'];
|
||||
const ID_VALUES_ARRAY = ['i_0001', 'i_0010', 'i_0100', 'i_1000', 'i_10000'];
|
||||
@@ -307,7 +309,7 @@ module('Acceptance | targets | list', function (hooks) {
|
||||
key: 'type',
|
||||
values: [TYPE_TARGET_SSH, TYPE_TARGET_TCP, TYPE_TARGET_SSH],
|
||||
},
|
||||
expectedAscendingSort: ['SSH', 'SSH', 'Generic TCP'],
|
||||
expectedAscendingSort: ['Generic TCP', 'SSH', 'SSH'],
|
||||
column: 2,
|
||||
},
|
||||
'on id': {
|
||||
|
||||
@@ -8,6 +8,7 @@ import { visit, currentURL, click } from '@ember/test-helpers';
|
||||
import { setupApplicationTest } from 'admin/tests/helpers';
|
||||
import setupMirage from 'ember-cli-mirage/test-support/setup-mirage';
|
||||
import { setupIndexedDb } from 'api/test-support/helpers/indexed-db';
|
||||
import { setupIntl } from 'ember-intl/test-support';
|
||||
import a11yAudit from 'ember-a11y-testing/test-support/audit';
|
||||
import { authenticateSession } from 'ember-simple-auth/test-support';
|
||||
import { TYPE_TARGET_TCP, TYPE_TARGET_SSH } from 'api/models/target';
|
||||
@@ -18,6 +19,7 @@ module('Acceptance | targets | read', function (hooks) {
|
||||
setupApplicationTest(hooks);
|
||||
setupMirage(hooks);
|
||||
setupIndexedDb(hooks);
|
||||
setupIntl(hooks, 'en-us');
|
||||
|
||||
let featuresService;
|
||||
let aliasResource;
|
||||
|
||||
@@ -8,6 +8,7 @@ import { visit, currentURL, click, fillIn } from '@ember/test-helpers';
|
||||
import { setupApplicationTest } from 'admin/tests/helpers';
|
||||
import setupMirage from 'ember-cli-mirage/test-support/setup-mirage';
|
||||
import { setupIndexedDb } from 'api/test-support/helpers/indexed-db';
|
||||
import { setupIntl } from 'ember-intl/test-support';
|
||||
import { Response } from 'miragejs';
|
||||
import { authenticateSession } from 'ember-simple-auth/test-support';
|
||||
import * as commonSelectors from 'admin/tests/helpers/selectors';
|
||||
@@ -17,6 +18,7 @@ module('Acceptance | targets | update', function (hooks) {
|
||||
setupApplicationTest(hooks);
|
||||
setupMirage(hooks);
|
||||
setupIndexedDb(hooks);
|
||||
setupIntl(hooks, 'en-us');
|
||||
|
||||
let featuresService;
|
||||
|
||||
|
||||
@@ -5,11 +5,13 @@
|
||||
|
||||
import { module, test } from 'qunit';
|
||||
import { setupTest } from 'admin/tests/helpers';
|
||||
import { setupIntl } from 'ember-intl/test-support';
|
||||
|
||||
module(
|
||||
'Unit | Route | scopes/scope/session-recordings/index',
|
||||
function (hooks) {
|
||||
setupTest(hooks);
|
||||
setupIntl(hooks, 'en-us');
|
||||
|
||||
test('it exists', function (assert) {
|
||||
let route = this.owner.lookup(
|
||||
|
||||
@@ -5,9 +5,11 @@
|
||||
|
||||
import { module, test } from 'qunit';
|
||||
import { setupTest } from 'ember-qunit';
|
||||
import { setupIntl } from 'ember-intl/test-support';
|
||||
|
||||
module('Unit | Route | scopes/scope/targets/index', function (hooks) {
|
||||
setupTest(hooks);
|
||||
setupIntl(hooks, 'en-us');
|
||||
|
||||
test('it exists', function (assert) {
|
||||
let route = this.owner.lookup('route:scopes/scope/targets/index');
|
||||
|
||||
@@ -0,0 +1,67 @@
|
||||
/**
|
||||
* Copyright (c) HashiCorp, Inc.
|
||||
* SPDX-License-Identifier: BUSL-1.1
|
||||
*/
|
||||
|
||||
import { sortNameWithIdFallback } from 'admin/utils/sort-name-with-id-fallback';
|
||||
import { module, test } from 'qunit';
|
||||
|
||||
function createMockRecord(id, attributes = {}) {
|
||||
return {
|
||||
id,
|
||||
attributes,
|
||||
};
|
||||
}
|
||||
|
||||
module('Unit | Utility | sort-name-with-id-fallback', function () {
|
||||
test.each(
|
||||
'sort on name with id fallback',
|
||||
[
|
||||
{
|
||||
recordA: createMockRecord('id_01'),
|
||||
recordB: createMockRecord('id_01'),
|
||||
expectedResult: 0,
|
||||
},
|
||||
{
|
||||
recordA: createMockRecord('id_02'),
|
||||
recordB: createMockRecord('id_01'),
|
||||
expectedResult: 1,
|
||||
},
|
||||
{
|
||||
recordA: createMockRecord('id_01'),
|
||||
recordB: createMockRecord('id_02'),
|
||||
expectedResult: -1,
|
||||
},
|
||||
{
|
||||
recordA: createMockRecord('id_01', { name: 'Alpha' }),
|
||||
recordB: createMockRecord('id_02'),
|
||||
expectedResult: -1,
|
||||
},
|
||||
{
|
||||
recordA: createMockRecord('id_01'),
|
||||
recordB: createMockRecord('id_02', { name: 'Alpha' }),
|
||||
expectedResult: 1,
|
||||
},
|
||||
{
|
||||
recordA: createMockRecord('id_01', { name: 'Alpha' }),
|
||||
recordB: createMockRecord('id_02', { name: 'Beta' }),
|
||||
expectedResult: -1,
|
||||
},
|
||||
{
|
||||
recordA: createMockRecord('id_01', { name: 'Beta' }),
|
||||
recordB: createMockRecord('id_02', { name: 'Alpha' }),
|
||||
expectedResult: 1,
|
||||
},
|
||||
{
|
||||
recordA: createMockRecord('id_01', { name: 'Alpha' }),
|
||||
recordB: createMockRecord('id_02', { name: 'Alpha' }),
|
||||
expectedResult: 0,
|
||||
},
|
||||
],
|
||||
function (assert, input) {
|
||||
const result = sortNameWithIdFallback(input.recordA, input.recordB);
|
||||
|
||||
assert.strictEqual(result, input.expectedResult);
|
||||
},
|
||||
);
|
||||
});
|
||||
Reference in new issue
Block a user