mirror of
https://github.com/hashicorp/vault.git
synced 2025-08-10 00:27:02 +02:00
* Adding explicit MPL license for sub-package. This directory and its subdirectories (packages) contain files licensed with the MPLv2 `LICENSE` file in this directory and are intentionally licensed separately from the BSL `LICENSE` file at the root of this repository. * Adding explicit MPL license for sub-package. This directory and its subdirectories (packages) contain files licensed with the MPLv2 `LICENSE` file in this directory and are intentionally licensed separately from the BSL `LICENSE` file at the root of this repository. * Updating the license from MPL to Business Source License. Going forward, this project will be licensed under the Business Source License v1.1. Please see our blog post for more details at https://hashi.co/bsl-blog, FAQ at www.hashicorp.com/licensing-faq, and details of the license at www.hashicorp.com/bsl. * add missing license headers * Update copyright file headers to BUS-1.1 * Fix test that expected exact offset on hcl file --------- Co-authored-by: hashicorp-copywrite[bot] <110428419+hashicorp-copywrite[bot]@users.noreply.github.com> Co-authored-by: Sarah Thompson <sthompson@hashicorp.com> Co-authored-by: Brian Kassouf <bkassouf@hashicorp.com>
159 lines
5.1 KiB
JavaScript
159 lines
5.1 KiB
JavaScript
/**
|
|
* Copyright (c) HashiCorp, Inc.
|
|
* SPDX-License-Identifier: BUSL-1.1
|
|
*/
|
|
|
|
import { module, test } from 'qunit';
|
|
import { setupRenderingTest } from 'ember-qunit';
|
|
import { render, triggerEvent, waitUntil } from '@ember/test-helpers';
|
|
import hbs from 'htmlbars-inline-precompile';
|
|
import sinon from 'sinon';
|
|
|
|
let file;
|
|
const data = JSON.stringify({ some: 'content' }, null, 2);
|
|
const fileEvent = () => {
|
|
file = new Blob([data], { type: 'application/json' });
|
|
file.name = 'file.json';
|
|
return ['change', { files: [file] }];
|
|
};
|
|
|
|
module('Integration | Component | pgp list', function (hooks) {
|
|
setupRenderingTest(hooks);
|
|
|
|
test('it renders', async function (assert) {
|
|
this.set('listLength', 0);
|
|
await render(hbs`<PgpList @listLength={{this.listLength}} />`);
|
|
assert.dom('[data-test-empty-text]').exists('shows the empty state');
|
|
this.set('listLength', 1);
|
|
assert
|
|
.dom('[data-test-pgp-file]')
|
|
.exists({ count: 1 }, 'renders pgp-file one component when length is updated');
|
|
this.set('listLength', 2);
|
|
assert
|
|
.dom('[data-test-pgp-file]')
|
|
.exists({ count: 2 }, 'renders multiple pgp-file components when length is updated');
|
|
});
|
|
|
|
test('onDataUpdate is called properly', async function (assert) {
|
|
this.set('spy', sinon.spy());
|
|
const event = fileEvent();
|
|
|
|
await render(hbs`<PgpList @listLength={{1}} @onDataUpdate={{this.spy}} />`);
|
|
triggerEvent('[data-test-pgp-file-input]', ...event);
|
|
|
|
// FileReader is async, but then we need extra run loop wait to re-render
|
|
await waitUntil(() => {
|
|
return !!this.spy.calledOnce;
|
|
});
|
|
const expected = [btoa(data)];
|
|
assert.deepEqual(
|
|
this.spy.getCall(0).args[0],
|
|
expected,
|
|
'calls onchange with an array of base64 converted files'
|
|
);
|
|
});
|
|
|
|
test('sparse filling of multiple files, then shortening', async function (assert) {
|
|
this.set('spy', sinon.spy());
|
|
this.set('listLength', 3);
|
|
|
|
await render(hbs`<PgpList @listLength={{this.listLength}} @onDataUpdate={{this.spy}} />`);
|
|
|
|
// add a file to the first input
|
|
triggerEvent('[data-test-pgp-file]:nth-child(1) [data-test-pgp-file-input]', ...fileEvent());
|
|
await waitUntil(() => {
|
|
return !!this.spy.calledOnce;
|
|
});
|
|
const expected = [btoa(data), '', ''];
|
|
assert.deepEqual(
|
|
this.spy.getCall(0).args[0],
|
|
expected,
|
|
'calls onchange with an array of base64 converted files'
|
|
);
|
|
|
|
// add a file to the third input
|
|
triggerEvent('[data-test-pgp-file]:nth-child(3) [data-test-pgp-file-input]', ...fileEvent());
|
|
await waitUntil(() => {
|
|
return !!this.spy.calledTwice;
|
|
});
|
|
const expected2 = [btoa(data), '', btoa(data)];
|
|
assert.deepEqual(
|
|
this.spy.getCall(1).args[0],
|
|
expected2,
|
|
'calls onchange with an array 2 base64 converted files'
|
|
);
|
|
|
|
// this will trim off the last input which was filled, so we should only have one file in the array
|
|
// now
|
|
this.set('listLength', 2);
|
|
const expected3 = [btoa(data), ''];
|
|
assert.deepEqual(
|
|
this.spy.getCall(2).args[0],
|
|
expected3,
|
|
'shortens the list with an array with one base64 converted files'
|
|
);
|
|
});
|
|
|
|
test('sparse filling of multiple files, then lengthening', async function (assert) {
|
|
this.set('spy', sinon.spy());
|
|
this.set('listLength', 3);
|
|
|
|
await render(hbs`<PgpList @listLength={{this.listLength}} @onDataUpdate={{this.spy}} />`);
|
|
|
|
// add a file to the first input
|
|
triggerEvent('[data-test-pgp-file]:nth-child(1) [data-test-pgp-file-input]', ...fileEvent());
|
|
await waitUntil(() => {
|
|
return !!this.spy.calledOnce;
|
|
});
|
|
const expected = [btoa(data), '', ''];
|
|
assert.deepEqual(
|
|
this.spy.getCall(0).args[0],
|
|
expected,
|
|
'calls onchange with an array of base64 converted files'
|
|
);
|
|
|
|
// add a file to the third input
|
|
triggerEvent('[data-test-pgp-file]:nth-child(3) [data-test-pgp-file-input]', ...fileEvent());
|
|
await waitUntil(() => {
|
|
return !!this.spy.calledTwice;
|
|
});
|
|
const expected2 = [btoa(data), '', btoa(data)];
|
|
assert.deepEqual(
|
|
this.spy.getCall(1).args[0],
|
|
expected2,
|
|
'calls onchange with an array 2 base64 converted files'
|
|
);
|
|
|
|
// this will add a couple of inputs but should keep the existing 3
|
|
this.set('listLength', 5);
|
|
const expected3 = [btoa(data), '', btoa(data), '', ''];
|
|
assert.deepEqual(
|
|
this.spy.getCall(2).args[0],
|
|
expected3,
|
|
'lengthening the list with an array with one base64 converted files'
|
|
);
|
|
});
|
|
|
|
test('it should render correct amount of file components on listLength change', async function (assert) {
|
|
assert.expect(4);
|
|
|
|
this.set('listLength', null);
|
|
|
|
await render(hbs`
|
|
<PgpList
|
|
@listLength={{this.listLength}}
|
|
/>
|
|
`);
|
|
[1, 5, 3, 0].forEach((count) => {
|
|
this.set('listLength', count);
|
|
if (count) {
|
|
assert
|
|
.dom('[data-test-pgp-file]')
|
|
.exists({ count }, `Correct number of file inputs render when listLength is updated to ${count}`);
|
|
} else {
|
|
assert.dom('[data-test-empty-text]').exists('Placeholder renders when list length is zero');
|
|
}
|
|
});
|
|
});
|
|
});
|