vault/ui/tests/integration/utils/field-to-attrs-test.js
Jordan Reimer e5b1f718f1
Ember Upgrade to 3.24 (#13443)
* Update browserslist

* Add browserslistrc

* ember-cli-update --to 3.26, fix conflicts

* Run codemodes that start with ember-*

* More codemods - before cp*

* More codemods (curly data-test-*)

* WIP ember-basic-dropdown template errors

* updates ember-basic-dropdown and related deps to fix build issues

* updates basic dropdown instances to new version API

* updates more deps -- ember-template-lint is working again

* runs no-implicit-this codemod

* creates and runs no-quoteless-attributes codemod

* runs angle brackets codemod

* updates lint:hbs globs to only touch hbs files

* removes yield only templates

* creates and runs deprecated args transform

* supresses lint error for invokeAction on LinkTo component

* resolves remaining ambiguous path lint errors

* resolves simple-unless lint errors

* adds warnings for deprecated tagName arg on LinkTo components

* adds warnings for remaining curly component invocation

* updates global template lint rules

* resolves remaining template lint errors

* disables some ember specfic lint rules that target pre octane patterns

* js lint fix run

* resolves remaining js lint errors

* fixes test run

* adds npm-run-all dep

* fixes test attribute issues

* fixes console acceptance tests

* fixes tests

* adds yield only wizard/tutorial-active template

* fixes more tests

* attempts to fix more flaky tests

* removes commented out settled in transit test

* updates deprecations workflow and adds initializer to filter by version

* updates flaky policies acl old test

* updates to flaky transit test

* bumps ember deps down to LTS version

* runs linters after main merge

* fixes client count tests after bad merge conflict fixes

* fixes client count history test

* more updates to lint config

* another round of hbs lint fixes after extending stylistic rule

* updates lint-staged commands

* removes indent eslint rule since it seems to break things

* fixes bad attribute in transform-edit-form template

* test fixes

* fixes enterprise tests

* adds changelog

* removes deprecated ember-concurrency-test-waiters dep and adds @ember/test-waiters

* flaky test fix

Co-authored-by: hashishaw <cshaw@hashicorp.com>
2021-12-16 20:44:29 -07:00

150 lines
6.1 KiB
JavaScript

import { run } from '@ember/runloop';
import { module, test } from 'qunit';
import { setupTest } from 'ember-qunit';
import fieldToAttrs, { expandAttributeMeta } from 'vault/utils/field-to-attrs';
module('Integration | Util | field to attrs', function (hooks) {
setupTest(hooks);
const PATH_ATTR = { type: 'string', name: 'path', options: {} };
const DESCRIPTION_ATTR = { type: 'string', name: 'description', options: { editType: 'textarea' } };
const DEFAULT_LEASE_ATTR = {
type: undefined,
name: 'config.defaultLeaseTtl',
options: { label: 'Default Lease TTL', editType: 'ttl' },
};
const OTHER_DEFAULT_LEASE_ATTR = {
type: undefined,
name: 'otherConfig.defaultLeaseTtl',
options: { label: 'Default Lease TTL', editType: 'ttl' },
};
const MAX_LEASE_ATTR = {
type: undefined,
name: 'config.maxLeaseTtl',
options: { label: 'Max Lease TTL', editType: 'ttl' },
};
const OTHER_MAX_LEASE_ATTR = {
type: undefined,
name: 'otherConfig.maxLeaseTtl',
options: { label: 'Max Lease TTL', editType: 'ttl' },
};
test('it extracts attrs', function (assert) {
const model = run(() => this.owner.lookup('service:store').createRecord('test-form-model'));
run(() => {
const [attr] = expandAttributeMeta(model, ['path']);
assert.deepEqual(attr, PATH_ATTR, 'returns attribute meta');
});
});
test('it extracts more than one attr', function (assert) {
const model = run(() => this.owner.lookup('service:store').createRecord('test-form-model'));
run(() => {
const [path, desc] = expandAttributeMeta(model, ['path', 'description']);
assert.deepEqual(path, PATH_ATTR, 'returns attribute meta');
assert.deepEqual(desc, DESCRIPTION_ATTR, 'returns attribute meta');
});
});
test('it extracts fieldGroups', function (assert) {
const model = run(() => this.owner.lookup('service:store').createRecord('test-form-model'));
run(() => {
const groups = fieldToAttrs(model, [{ default: ['path'] }, { Options: ['description'] }]);
const expected = [{ default: [PATH_ATTR] }, { Options: [DESCRIPTION_ATTR] }];
assert.deepEqual(groups, expected, 'expands all given groups');
});
});
test('it extracts arrays as fieldGroups', function (assert) {
const model = run(() => this.owner.lookup('service:store').createRecord('test-form-model'));
run(() => {
const groups = fieldToAttrs(model, [
{ default: ['path', 'description'] },
{ Options: ['description'] },
]);
const expected = [{ default: [PATH_ATTR, DESCRIPTION_ATTR] }, { Options: [DESCRIPTION_ATTR] }];
assert.deepEqual(groups, expected, 'expands all given groups');
});
});
test('it extracts model-fragment attributes with brace expansion', function (assert) {
const model = run(() => this.owner.lookup('service:store').createRecord('test-form-model'));
run(() => {
const [attr] = expandAttributeMeta(model, ['config.{defaultLeaseTtl}']);
assert.deepEqual(attr, DEFAULT_LEASE_ATTR, 'properly extracts model fragment attr');
});
run(() => {
const [defaultLease, maxLease] = expandAttributeMeta(model, ['config.{defaultLeaseTtl,maxLeaseTtl}']);
assert.deepEqual(defaultLease, DEFAULT_LEASE_ATTR, 'properly extracts default lease');
assert.deepEqual(maxLease, MAX_LEASE_ATTR, 'properly extracts max lease');
});
});
test('it extracts model-fragment attributes with double brace expansion', function (assert) {
const model = run(() => this.owner.lookup('service:store').createRecord('test-form-model'));
run(() => {
const [configDefault, configMax, otherConfigDefault, otherConfigMax] = expandAttributeMeta(model, [
'{config,otherConfig}.{defaultLeaseTtl,maxLeaseTtl}',
]);
assert.deepEqual(configDefault, DEFAULT_LEASE_ATTR, 'properly extracts config.defaultLeaseTTL');
assert.deepEqual(
otherConfigDefault,
OTHER_DEFAULT_LEASE_ATTR,
'properly extracts otherConfig.defaultLeaseTTL'
);
assert.deepEqual(configMax, MAX_LEASE_ATTR, 'properly extracts config.maxLeaseTTL');
assert.deepEqual(otherConfigMax, OTHER_MAX_LEASE_ATTR, 'properly extracts otherConfig.maxLeaseTTL');
});
});
test('it extracts model-fragment attributes with dot notation', function (assert) {
const model = run(() => this.owner.lookup('service:store').createRecord('test-form-model'));
run(() => {
const [attr] = expandAttributeMeta(model, ['config.defaultLeaseTtl']);
assert.deepEqual(attr, DEFAULT_LEASE_ATTR, 'properly extracts model fragment attr');
});
run(() => {
const [defaultLease, maxLease] = expandAttributeMeta(model, [
'config.defaultLeaseTtl',
'config.maxLeaseTtl',
]);
assert.deepEqual(defaultLease, DEFAULT_LEASE_ATTR, 'properly extracts model fragment attr');
assert.deepEqual(maxLease, MAX_LEASE_ATTR, 'properly extracts model fragment attr');
});
});
test('it extracts fieldGroups from model-fragment attributes with brace expansion', function (assert) {
const model = run(() => this.owner.lookup('service:store').createRecord('test-form-model'));
const expected = [
{ default: [PATH_ATTR, DEFAULT_LEASE_ATTR, MAX_LEASE_ATTR] },
{ Options: [DESCRIPTION_ATTR] },
];
run(() => {
const groups = fieldToAttrs(model, [
{ default: ['path', 'config.{defaultLeaseTtl,maxLeaseTtl}'] },
{ Options: ['description'] },
]);
assert.deepEqual(groups, expected, 'properly extracts fieldGroups with brace expansion');
});
});
test('it extracts fieldGroups from model-fragment attributes with dot notation', function (assert) {
const model = run(() => this.owner.lookup('service:store').createRecord('test-form-model'));
const expected = [
{ default: [DEFAULT_LEASE_ATTR, PATH_ATTR, MAX_LEASE_ATTR] },
{ Options: [DESCRIPTION_ATTR] },
];
run(() => {
const groups = fieldToAttrs(model, [
{ default: ['config.defaultLeaseTtl', 'path', 'config.maxLeaseTtl'] },
{ Options: ['description'] },
]);
assert.deepEqual(groups, expected, 'properly extracts fieldGroups with dot notation');
});
});
});