Skip to content

Commit 4b2a599

Browse files
committed
added some missing tests for the title
1 parent 09e447c commit 4b2a599

File tree

3 files changed

+62
-4
lines changed

3 files changed

+62
-4
lines changed

packages/components/src/components/hds/code-editor/index.ts

-2
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ import { modifier } from 'ember-modifier';
1010

1111
import type { ComponentLike } from '@glint/template';
1212
import type { HdsCodeEditorSignature as HdsCodeEditorModifierSignature } from 'src/modifiers/hds-code-editor';
13-
import type { HdsButtonSignature } from 'src/components/hds/button';
1413
import type { HdsCodeEditorDescriptionSignature } from './description';
1514
import type { HdsCodeEditorTitleSignature } from './title';
1615
import type { HdsCodeEditorGenericSignature } from './generic';
@@ -35,7 +34,6 @@ export interface HdsCodeEditorSignature {
3534
Title?: ComponentLike<HdsCodeEditorTitleSignature>;
3635
Description?: ComponentLike<HdsCodeEditorDescriptionSignature>;
3736
Generic?: ComponentLike<HdsCodeEditorGenericSignature>;
38-
Button?: ComponentLike<HdsButtonSignature>;
3937
},
4038
];
4139
};

showcase/tests/integration/components/hds/code-editor/full-screen-button-test.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -65,10 +65,10 @@ module(
6565
this.set('onToggleFullScreen', onToggleFullScreen);
6666

6767
await render(
68-
hbs`<Hds::CodeEditor::FullScreenButton @isFullScreen={{false}} @onToggleFullScreen={{this.onToggleFullScreen}} />`
68+
hbs`<Hds::CodeEditor::FullScreenButton id="test-button" @isFullScreen={{false}} @onToggleFullScreen={{this.onToggleFullScreen}} />`
6969
);
7070

71-
await click('.hds-code-editor__full-screen-button');
71+
await click('#test-button');
7272

7373
assert.ok(onToggleFullScreen.calledOnce);
7474
});
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
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

Comments
 (0)