|
| 1 | +/** |
| 2 | + * Copyright (c) HashiCorp, Inc. |
| 3 | + * SPDX-License-Identifier: MPL-2.0 |
| 4 | + */ |
| 5 | + |
| 6 | +import { module, test } from 'qunit'; |
| 7 | +import { setupRenderingTest } from 'ember-qunit'; |
| 8 | +import { render } from '@ember/test-helpers'; |
| 9 | +import { hbs } from 'ember-cli-htmlbars'; |
| 10 | +import sinon from 'sinon'; |
| 11 | + |
| 12 | +module('Integration | Component | hds/code-editor/title', function (hooks) { |
| 13 | + setupRenderingTest(hooks); |
| 14 | + |
| 15 | + test('it should render the component with a CSS class that matches the component name', async function (assert) { |
| 16 | + this.set('noop', () => {}); |
| 17 | + |
| 18 | + await render( |
| 19 | + hbs`<Hds::CodeEditor::Title @editorId="test" @onInsert={{this.noop}} />` |
| 20 | + ); |
| 21 | + |
| 22 | + assert.dom('.hds-code-editor__title').exists(); |
| 23 | + }); |
| 24 | + |
| 25 | + test('it should render the component with a title using the default tag', async function (assert) { |
| 26 | + this.set('noop', () => {}); |
| 27 | + |
| 28 | + await render( |
| 29 | + hbs`<Hds::CodeEditor::Title @editorId="test" @onInsert={{this.noop}}>Test Title</Hds::CodeEditor::Title>` |
| 30 | + ); |
| 31 | + |
| 32 | + assert |
| 33 | + .dom('.hds-code-editor__title') |
| 34 | + .hasTagName('h2') |
| 35 | + .hasText('Test Title'); |
| 36 | + }); |
| 37 | + |
| 38 | + // @tag |
| 39 | + test('it shoud render the component title with a custom tag when provided', async function (assert) { |
| 40 | + this.set('noop', () => {}); |
| 41 | + |
| 42 | + await render( |
| 43 | + hbs`<Hds::CodeEditor::Title @editorId="test" @tag="h1" @onInsert={{this.noop}}>Test Title</Hds::CodeEditor::Title>` |
| 44 | + ); |
| 45 | + |
| 46 | + assert.dom('.hds-code-editor__title').hasTagName('h1'); |
| 47 | + }); |
| 48 | + |
| 49 | + // @onInsert |
| 50 | + test('it should call the `@onInsert` action when the title is inserted', async function (assert) { |
| 51 | + const onInsert = sinon.spy(); |
| 52 | + this.set('onInsert', onInsert); |
| 53 | + |
| 54 | + await render( |
| 55 | + hbs`<Hds::CodeEditor::Title @editorId="test" @onInsert={{this.onInsert}}>Test Title</Hds::CodeEditor::Title>` |
| 56 | + ); |
| 57 | + |
| 58 | + assert.true(onInsert.calledOnce); |
| 59 | + }); |
| 60 | +}); |
0 commit comments