mirror of
				https://github.com/optim-enterprises-bv/vault.git
				synced 2025-11-03 20:17:59 +00:00 
			
		
		
		
	* 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>
		
			
				
	
	
		
			154 lines
		
	
	
		
			5.0 KiB
		
	
	
	
		
			JavaScript
		
	
	
	
	
	
			
		
		
	
	
			154 lines
		
	
	
		
			5.0 KiB
		
	
	
	
		
			JavaScript
		
	
	
	
	
	
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={{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());
 | 
						|
    let 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;
 | 
						|
    });
 | 
						|
    let 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;
 | 
						|
    });
 | 
						|
    let 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;
 | 
						|
    });
 | 
						|
    let 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);
 | 
						|
    let 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;
 | 
						|
    });
 | 
						|
    let 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;
 | 
						|
    });
 | 
						|
    let 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);
 | 
						|
    let 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');
 | 
						|
      }
 | 
						|
    });
 | 
						|
  });
 | 
						|
});
 |