vault/ui/tests/integration/components/json-editor-test.js
hashicorp-copywrite[bot] 0b12cdcfd1
[COMPLIANCE] License changes (#22290)
* 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>
2023-08-10 18:14:03 -07:00

82 lines
2.6 KiB
JavaScript

/**
* Copyright (c) HashiCorp, Inc.
* SPDX-License-Identifier: BUSL-1.1
*/
import { module, test } from 'qunit';
import { setupRenderingTest } from 'ember-qunit';
import { create } from 'ember-cli-page-object';
import { render, fillIn, find, waitUntil } from '@ember/test-helpers';
import hbs from 'htmlbars-inline-precompile';
import jsonEditor from '../../pages/components/json-editor';
import sinon from 'sinon';
const component = create(jsonEditor);
module('Integration | Component | json-editor', function (hooks) {
setupRenderingTest(hooks);
const JSON_BLOB = `{
"test": "test"
}`;
const BAD_JSON_BLOB = `{
"test": test
}`;
hooks.beforeEach(function () {
this.set('valueUpdated', sinon.spy());
this.set('onFocusOut', sinon.spy());
this.set('json_blob', JSON_BLOB);
this.set('bad_json_blob', BAD_JSON_BLOB);
this.set('hashi-read-only-theme', 'hashi-read-only auto-height');
});
test('it renders', async function (assert) {
await render(hbs`<JsonEditor
@value={{"{}"}}
@title={{"Test title"}}
@showToolbar={{true}}
@readOnly={{true}}
/>`);
assert.strictEqual(component.title, 'Test title', 'renders the provided title');
assert.true(component.hasToolbar, 'renders the toolbar');
assert.true(component.hasJSONEditor, 'renders the code mirror modifier');
assert.ok(component.canEdit, 'json editor can be edited');
});
test('it handles editing and linting and styles to json', async function (assert) {
await render(hbs`<JsonEditor
@value={{this.json_blob}}
@readOnly={{false}}
@valueUpdated={{this.valueUpdated}}
@onFocusOut={{this.onFocusOut}}
/>`);
// check for json styling
assert.dom('.cm-property').hasStyle({
color: 'rgb(158, 132, 197)',
});
assert.dom('.cm-string:nth-child(2)').hasStyle({
color: 'rgb(29, 219, 163)',
});
await fillIn('textarea', this.bad_json_blob);
await waitUntil(() => find('.CodeMirror-lint-marker-error'));
assert.dom('.CodeMirror-lint-marker-error').exists('throws linting error');
assert.dom('.CodeMirror-linenumber').exists('shows line numbers');
});
test('it renders the correct theme and expected styling', async function (assert) {
await render(hbs`<JsonEditor
@value={{this.json_blob}}
@theme={{this.hashi-read-only-theme}}
@readOnly={{true}}
/>`);
assert.dom('.cm-s-hashi-read-only').hasStyle({
background: 'rgb(247, 248, 250) none repeat scroll 0% 0% / auto padding-box border-box',
});
assert.dom('.CodeMirror-linenumber').doesNotExist('on readOnly does not show line numbers');
});
});