forked from hashicorp/vault
-
Notifications
You must be signed in to change notification settings - Fork 0
/
info-table-row-test.js
165 lines (137 loc) · 5.53 KB
/
info-table-row-test.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
import { module, test } from 'qunit';
import { resolve } from 'rsvp';
import Service from '@ember/service';
import { setupRenderingTest } from 'ember-qunit';
import { render, settled, triggerEvent } from '@ember/test-helpers';
import hbs from 'htmlbars-inline-precompile';
const VALUE = 'test value';
const LABEL = 'test label';
const TYPE = 'array';
const DEFAULT = 'some default value';
const routerService = Service.extend({
transitionTo() {
return {
followRedirects() {
return resolve();
},
};
},
replaceWith() {
return resolve();
},
});
module('Integration | Component | InfoTableRow', function(hooks) {
setupRenderingTest(hooks);
hooks.beforeEach(function() {
this.set('value', VALUE);
this.set('label', LABEL);
this.set('type', TYPE);
this.set('default', DEFAULT);
this.owner.register('service:router', routerService);
this.router = this.owner.lookup('service:router');
});
hooks.afterEach(function() {
this.owner.unregister('service:store');
});
test('it renders', async function(assert) {
await render(hbs`<InfoTableRow
@value={{value}}
@label={{label}}
@defaultShown={{default}}
/>`);
assert.dom('[data-test-component="info-table-row"]').exists();
let string = document.querySelector('code').textContent;
assert.equal(string, VALUE, 'renders value as passed through');
this.set('value', '');
assert
.dom('[data-test-label-div]')
.doesNotExist('does not render if no value and alwaysRender is false (even if default exists)');
});
test('it renders a tooltip', async function(assert) {
this.set('tooltipText', 'Tooltip text!');
await render(hbs`<InfoTableRow
@value={{value}}
@label={{label}}
@tooltipText={{tooltipText}}
/>`);
await triggerEvent('[data-test-value-div="test label"] .ember-basic-dropdown-trigger', 'mouseenter');
await settled();
let tooltip = document.querySelector('div.box').textContent.trim();
assert.equal(tooltip, 'Tooltip text!', 'renders tooltip text');
});
test('it should copy tooltip', async function(assert) {
assert.expect(4);
this.set('isCopyable', false);
await render(hbs`
<InfoTableRow
@label={{label}}
@value={{value}}
@tooltipText="Foo bar"
@isTooltipCopyable={{isCopyable}}
/>
`);
await triggerEvent('[data-test-value-div="test label"] .ember-basic-dropdown-trigger', 'mouseenter');
await settled();
assert.dom('[data-test-tooltip-copy]').hasAttribute('disabled', '', 'Tooltip copy button is disabled');
assert.dom('[data-test-tooltip-copy]').doesNotHaveClass('has-pointer', 'Pointer class not applied when disabled');
this.set('isCopyable', true);
assert.dom('[data-test-tooltip-copy]').doesNotHaveAttribute('disabled', 'Tooltip copy button is enabled');
assert.dom('[data-test-tooltip-copy]').hasClass('has-pointer', 'Pointer class applied to copy button');
});
test('it renders a string with no link if isLink is true and the item type is not an array.', async function(assert) {
// This could be changed in the component so that it adds a link for any item type, but right now it should only add a link if item type is an array.
await render(hbs`<InfoTableRow
@value={{value}}
@label={{label}}
@isLink={{true}}
/>`);
let string = document.querySelector('code').textContent;
assert.equal(string, VALUE, 'renders value in code element and not in a tag');
});
test('it renders links if isLink is true and type is array', async function(assert) {
this.set('valueArray', ['valueArray']);
await render(hbs`<InfoTableRow
@value={{valueArray}}
@label={{label}}
@isLink={{true}}
@type={{type}}
/>`);
assert.dom('[data-test-item="array"]').hasText('valueArray', 'Confirm link with item value exist');
});
test('it renders as expected if a label and/or value do not exist', async function(assert) {
this.set('value', VALUE);
this.set('label', '');
this.set('default', '');
await render(hbs`<InfoTableRow
@value={{value}}
@label={{label}}
@alwaysRender={{true}}
@defaultShown={{default}}
/>`);
assert.dom('div.column span').hasClass('hs-icon-s', 'Renders a dash (-) for the label');
this.set('value', '');
this.set('label', LABEL);
assert.dom('div.column.is-flex span').hasClass('hs-icon-s', 'Renders a dash (-) for empty string value');
this.set('value', null);
assert.dom('div.column.is-flex span').hasClass('hs-icon-s', 'Renders a dash (-) for null value');
this.set('value', undefined);
assert.dom('div.column.is-flex span').hasClass('hs-icon-s', 'Renders a dash (-) for undefined value');
this.set('default', DEFAULT);
assert.dom('[data-test-value-div]').hasText(DEFAULT, 'Renders default text if value is empty');
this.set('value', '');
this.set('label', '');
this.set('default', '');
let dashCount = document.querySelectorAll('.hs-icon-s').length;
assert.equal(dashCount, 2, 'Renders dash (-) when both label and value do not exist (and no defaults)');
});
test('block content overrides any passed in value content', async function(assert) {
await render(hbs`<InfoTableRow
@value={{value}}
@label={{label}}
@alwaysRender={{true}}>
Block content is here
</InfoTableRow>`);
let block = document.querySelector('[data-test-value-div]').textContent.trim();
assert.equal(block, 'Block content is here', 'renders block passed through');
});
});