Skip to content

Commit 5010412

Browse files
authored
Merge pull request #8255 from michaelchadwick/frontend-5868-fadetext-button-edit-tooltip
Add title tooltip to objective buttons
2 parents 7557618 + 2caaa2a commit 5010412

File tree

10 files changed

+96
-42
lines changed

10 files changed

+96
-42
lines changed
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
import {
2+
attribute,
3+
clickable,
4+
count,
5+
create,
6+
isVisible,
7+
text,
8+
triggerable,
9+
} from 'ember-cli-page-object';
10+
import { hasFocus } from 'ilios-common';
11+
import fadeText from './fade-text.js';
12+
13+
const definition = {
14+
scope: '[data-test-editable-field]',
15+
value: text(),
16+
hasEditIcon: isVisible('[data-test-edit-icon]'),
17+
editable: {
18+
scope: '[data-test-edit]',
19+
edit: clickable(),
20+
iconCount: count(),
21+
title: attribute('title'),
22+
},
23+
enter: triggerable('keyup', 'input', { eventProperties: { key: 'Enter' } }),
24+
escape: triggerable('keyup', 'input', { eventProperties: { key: 'Escape' } }),
25+
cancel: clickable('[data-test-cancel]'),
26+
inputHasFocus: hasFocus('input'),
27+
textareaHasFocus: hasFocus('textarea'),
28+
fadeText,
29+
};
30+
31+
export default definition;
32+
export const component = create(definition);

packages/ilios-common/addon/components/course/objective-list-item-parents.hbs

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,14 @@
3333
>
3434
{{#if @editable}}
3535
<span data-test-parent>
36-
<button type="button" class="link-button" {{on "click" @manage}} data-test-manage>
36+
<button
37+
type="button"
38+
class="link-button"
39+
aria-label={{t "general.edit"}}
40+
title={{t "general.edit"}}
41+
{{on "click" @manage}}
42+
data-test-manage
43+
>
3744
<div class="display-text-wrapper{{if shouldFade ' faded'}}">
3845
<div class="display-text" {{on-resize updateTextDims}}>
3946
{{displayText}}
@@ -63,7 +70,6 @@
6370
<button
6471
class="expand-text-button"
6572
type="button"
66-
aria-label={{t "general.expand"}}
6773
title={{t "general.expand"}}
6874
data-test-expand
6975
{{on "click" expand}}
@@ -75,7 +81,6 @@
7581
{{#if expanded}}
7682
<button
7783
class="expand-text-button"
78-
aria-label={{t "general.collapse"}}
7984
title={{t "general.collapse"}}
8085
type="button"
8186
data-test-collapse

packages/ilios-common/addon/components/course/objective-list-item.hbs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
@close={{this.revertTitleChanges}}
1717
@fadeTextExpanded={{this.fadeTextExpanded}}
1818
@onExpandAllFadeText={{this.expandAllFadeText}}
19+
@showTitle={{true}}
1920
>
2021
<HtmlEditor
2122
@content={{@courseObjective.title}}

packages/ilios-common/addon/components/editable-field.hbs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<div class="editinplace{{if this.isEditing ' is-editing'}}" ...attributes>
1+
<div class="editinplace{{if this.isEditing ' is-editing'}}" data-test-editable-field ...attributes>
22
<span class="content">
33
{{#if this.isEditing}}
44
<span
@@ -55,6 +55,7 @@
5555
<button
5656
class="link-button editable"
5757
aria-label={{t "general.edit"}}
58+
title={{if @showTitle (t "general.edit")}}
5859
data-test-edit
5960
type="button"
6061
{{on "click" (fn this.setIsEditing true)}}

packages/ilios-common/addon/components/session/objective-list-item-parents.hbs

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,14 @@
3333
>
3434
{{#if @editable}}
3535
<span data-test-parent>
36-
<button type="button" class="link-button" {{on "click" @manage}} data-test-manage>
36+
<button
37+
type="button"
38+
class="link-button"
39+
aria-label={{t "general.edit"}}
40+
title={{t "general.edit"}}
41+
{{on "click" @manage}}
42+
data-test-manage
43+
>
3744
<div class="display-text-wrapper{{if shouldFade ' faded'}}">
3845
<div class="display-text" {{on-resize updateTextDims}}>
3946
{{displayText}}
@@ -63,7 +70,6 @@
6370
<button
6471
class="expand-text-button"
6572
type="button"
66-
aria-label={{t "general.expand"}}
6773
title={{t "general.expand"}}
6874
data-test-expand
6975
{{on "click" expand}}
@@ -75,7 +81,6 @@
7581
{{#if expanded}}
7682
<button
7783
class="expand-text-button"
78-
aria-label={{t "general.collapse"}}
7984
title={{t "general.collapse"}}
8085
type="button"
8186
data-test-collapse

packages/ilios-common/addon/components/session/objective-list-item.hbs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
@close={{this.revertTitleChanges}}
1717
@fadeTextExpanded={{this.fadeTextExpanded}}
1818
@onExpandAllFadeText={{this.expandAllFadeText}}
19+
@showTitle={{true}}
1920
>
2021
<HtmlEditor
2122
@content={{@sessionObjective.title}}

packages/ilios-common/translations/en-us.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ general:
124124
etAl: et al.
125125
eventNotFoundTitle: Event Not Found
126126
eventNotFoundExplanation: "The event you have tried to reach is either no longer available, or you have followed a personalized user link which is not shareable. If you continue to encounter issues, please contact your Ilios help desk."
127-
expand: expand
127+
expand: Expand
128128
expandDetail: Show Details
129129
externalId: Course ID
130130
file: File

packages/ilios-common/translations/es.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ general:
124124
etAl: et al.
125125
eventNotFoundTitle: Evento no encontrado
126126
eventNotFoundExplanation: "El evento al que ha intentado acceder ya no está disponible o ha seguido un enlace de usuario personalizado que no se puede compartir. Si sigue teniendo problemas, póngase en contacto con el servicio de asistencia de Ilios."
127-
expand: expandir
127+
expand: Expandir
128128
expandDetail: Enseñar Detalles
129129
externalId: Identificación del Curso
130130
file: Archivo

packages/ilios-common/translations/fr.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ general:
122122
ends: Terminé
123123
endTime: Heure Terminé
124124
etAl: et al.
125-
expand: étendre
125+
expand: Étendre
126126
eventNotFoundTitle: Evénement introuvable
127127
eventNotFoundExplanation: "L'événement que vous avez essayé d'atteindre n'est plus disponible ou vous avez suivi un lien utilisateur personnalisé qui n'est pas partageable. Si vous continuez à rencontrer des problèmes, veuillez contacter votre service d'assistance Ilios."
128128
expandDetail: Afficher Détails

packages/test-app/tests/integration/components/editable-field-test.js

Lines changed: 41 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,42 +1,42 @@
11
import { module, test } from 'qunit';
22
import { setupRenderingTest } from 'test-app/tests/helpers';
3-
import { render, click, triggerKeyEvent, waitFor } from '@ember/test-helpers';
3+
import { render, waitFor } from '@ember/test-helpers';
44
import { hbs } from 'ember-cli-htmlbars';
5+
import { setupIntl } from 'ember-intl/test-support';
6+
import { component } from 'ilios-common/page-objects/components/editable-field';
57

68
module('Integration | Component | editable field', function (hooks) {
79
setupRenderingTest(hooks);
10+
setupIntl(hooks, 'en-us');
811

912
test('it renders value', async function (assert) {
1013
await render(hbs`<EditableField @value='woot!' />`);
11-
assert.dom(this.element).hasText('woot!');
12-
assert.dom('[data-test-edit-icon]', this.element).isNotVisible();
14+
assert.strictEqual(component.value, 'woot!');
15+
assert.notOk(component.hasEditIcon);
1316
});
1417

1518
test('edit icon is present', async function (assert) {
1619
await render(hbs`<EditableField @value='woot!' @showIcon={{true}} />`);
17-
assert.dom(this.element).hasText('woot!');
18-
assert.dom('[data-test-edit-icon]', this.element).isVisible();
20+
assert.strictEqual(component.value, 'woot!');
21+
assert.ok(component.hasEditIcon);
1922
});
2023

2124
test('it renders clickPrompt', async function (assert) {
2225
await render(hbs`<EditableField @clickPrompt='click me!' />`);
23-
24-
assert.dom(this.element).hasText('click me!');
26+
assert.strictEqual(component.value, 'click me!');
2527
});
2628

2729
test('it renders content', async function (assert) {
2830
this.set('content', 'template block text');
2931
await render(hbs`<EditableField @value='text'>
3032
{{this.content}}
3133
</EditableField>`);
32-
33-
assert.dom(this.element).hasText('text');
34-
await click('[data-test-edit]');
35-
assert.dom(this.element).hasText('template block text');
34+
assert.strictEqual(component.value, 'text');
35+
await component.editable.edit();
36+
assert.strictEqual(component.value, 'template block text');
3637
});
3738

3839
test('it renders an edit icon when it looks empty', async function (assert) {
39-
const icon = '.fa-pen-to-square';
4040
this.set(
4141
'value',
4242
`
@@ -46,9 +46,8 @@ module('Integration | Component | editable field', function (hooks) {
4646
`,
4747
);
4848
await render(hbs`<EditableField @value={{this.value}} />`);
49-
50-
assert.dom(this.element).hasText('');
51-
assert.dom(icon).exists({ count: 1 });
49+
assert.strictEqual(component.value, '');
50+
assert.strictEqual(component.editable.iconCount, 1);
5251
});
5352

5453
test('save on enter', async function (assert) {
@@ -66,8 +65,8 @@ module('Integration | Component | editable field', function (hooks) {
6665
</label>
6766
</EditableField>`,
6867
);
69-
await click('[data-test-edit]');
70-
await triggerKeyEvent('.editinplace input', 'keyup', 13);
68+
await component.editable.edit();
69+
await component.enter();
7170
});
7271

7372
test('close on escape', async function (assert) {
@@ -85,8 +84,8 @@ module('Integration | Component | editable field', function (hooks) {
8584
</label>
8685
</EditableField>`,
8786
);
88-
await click('[data-test-edit]');
89-
await triggerKeyEvent('.editinplace input', 'keyup', 27);
87+
await component.editable.edit();
88+
await component.escape();
9089
});
9190

9291
test('focus when editor opens on input', async function (assert) {
@@ -97,8 +96,8 @@ module('Integration | Component | editable field', function (hooks) {
9796
<label><input />{{this.label}}</label>
9897
</EditableField>`,
9998
);
100-
await click('[data-test-edit]');
101-
assert.dom('input', this.element).isFocused();
99+
await component.editable.edit();
100+
assert.ok(component.inputHasFocus);
102101
});
103102

104103
test('focus when editor opens on textarea', async function (assert) {
@@ -108,16 +107,14 @@ module('Integration | Component | editable field', function (hooks) {
108107
<label for='textarea'>{{this.label}}</label>
109108
<textarea id='textarea'></textarea>
110109
</EditableField>`);
111-
await click('[data-test-edit]');
112-
113-
assert.dom('textarea', this.element).isFocused();
110+
await component.editable.edit();
111+
assert.ok(component.textareaHasFocus);
114112
});
115113

116114
test('expand/collapse overlong html', async function (assert) {
117115
const text = `
118116
<p>A long list:</p><ol><li>One</li><li>two</li><li>Five!</li><li>Six</li><li>Seven but with extra text to make long</li><li>a</li><li>b</li><li>c</li><li>d</li><li>e</li><li>f</li><li>g</li><li>h</li><li>iii</li><li>Jjjjjj</li><li>k</li><li>lLLLLLLlll</li><li>mmmmmMMMMMmm</li><li>nnnnnOPE</li><li>ohno</li><li>pppppPowerbook</li></ol>
119117
`;
120-
const fadedClass = 'faded';
121118
const fadedSelector = '.faded';
122119
this.set('value', text);
123120
this.set('fadeTextIsExpanded', false);
@@ -134,16 +131,17 @@ module('Integration | Component | editable field', function (hooks) {
134131

135132
await waitFor(fadedSelector);
136133

137-
assert.dom('.display-text-wrapper', this.element).hasClass(fadedClass);
138-
await click('[data-test-expand]');
134+
assert.ok(component.fadeText.enabled);
135+
assert.ok(component.fadeText.displayText.isFaded);
139136

140-
assert.dom('.display-text-wrapper', this.element).doesNotHaveClass(fadedClass);
137+
await component.fadeText.control.expand.click();
141138

142-
await click('[data-test-collapse]');
139+
assert.notOk(component.fadeText.displayText.isFaded);
143140

141+
await component.fadeText.control.collapse.click();
144142
await waitFor(fadedSelector);
145143

146-
assert.dom('.display-text-wrapper', this.element).hasClass(fadedClass);
144+
assert.ok(component.fadeText.displayText.isFaded);
147145
});
148146

149147
test('sends status info', async function (assert) {
@@ -152,9 +150,20 @@ module('Integration | Component | editable field', function (hooks) {
152150
hbs`<EditableField @close={{(noop)}} @value='lorem' @onEditingStatusChange={{set this 'status'}} />`,
153151
);
154152
assert.notOk(this.status);
155-
await click('[data-test-edit]');
153+
await component.editable.edit();
156154
assert.ok(this.status);
157-
await click('[data-test-cancel]');
155+
await component.cancel();
158156
assert.notOk(this.status);
159157
});
158+
159+
test('it has title property value only if @showTitle is true', async function (assert) {
160+
await render(hbs`<EditableField @value='lorem' />`);
161+
162+
assert.strictEqual(component.editable.title, undefined);
163+
164+
this.set('showTitle', true);
165+
await render(hbs`<EditableField @value='lorem' @showTitle={{this.showTitle}} />`);
166+
167+
assert.strictEqual(component.editable.title, 'Edit');
168+
});
160169
});

0 commit comments

Comments
 (0)