From 03aaf6d9f9a8b925471dfcdc0c22b0495727995a Mon Sep 17 00:00:00 2001 From: frank Date: Tue, 13 Oct 2026 11:49:58 -0500 Subject: [PATCH 1/2] 2176 --- .../views/admin/settings/organization/emailWorkflowRule.html | 2 +- .../settings/workflow/controlledVocabularyManagement.html | 2 +- src/main/webapp/app/views/admin/view.html | 4 ++-- .../app/views/directives/dragAndDropControlledVocabulary.html | 2 +- .../webapp/app/views/directives/dragAndDropCustomAction.html | 2 +- src/main/webapp/app/views/directives/dragAndDropDegree.html | 2 +- .../app/views/directives/dragAndDropDepositLocation.html | 2 +- .../webapp/app/views/directives/dragAndDropDocumentType.html | 2 +- .../app/views/directives/dragAndDropEmailTemplates.html | 2 +- .../webapp/app/views/directives/dragAndDropFieldGloss.html | 2 +- .../app/views/directives/dragAndDropFieldPredicate.html | 2 +- .../webapp/app/views/directives/dragAndDropFieldProfile.html | 2 +- .../app/views/directives/dragAndDropGraduationMonth.html | 2 +- src/main/webapp/app/views/directives/dragAndDropLanguage.html | 2 +- src/main/webapp/app/views/directives/dragAndDropNote.html | 2 +- .../app/views/directives/dragAndDropOrganizationCategory.html | 2 +- src/main/webapp/app/views/directives/lockingTextArea.html | 2 +- src/main/webapp/app/views/directives/submissionInfo.html | 2 +- src/main/webapp/app/views/myprofile.html | 4 ++-- src/main/webapp/app/views/sideboxes/submissionStatus.html | 4 ++-- 20 files changed, 23 insertions(+), 23 deletions(-) diff --git a/src/main/webapp/app/views/admin/settings/organization/emailWorkflowRule.html b/src/main/webapp/app/views/admin/settings/organization/emailWorkflowRule.html index 8dadb43446..2f22dc5e30 100644 --- a/src/main/webapp/app/views/admin/settings/organization/emailWorkflowRule.html +++ b/src/main/webapp/app/views/admin/settings/organization/emailWorkflowRule.html @@ -21,7 +21,7 @@ ng-repeat="rule in getSelectedOrganizationEmailWorkflowRules()" class="email-workflow-rule-row"> - + {{rule.emailTemplate.name}} diff --git a/src/main/webapp/app/views/admin/settings/workflow/controlledVocabularyManagement.html b/src/main/webapp/app/views/admin/settings/workflow/controlledVocabularyManagement.html index ae3e7c0844..c7b05156a4 100644 --- a/src/main/webapp/app/views/admin/settings/workflow/controlledVocabularyManagement.html +++ b/src/main/webapp/app/views/admin/settings/workflow/controlledVocabularyManagement.html @@ -124,7 +124,7 @@ - +
diff --git a/src/main/webapp/app/views/admin/view.html b/src/main/webapp/app/views/admin/view.html index da3298c320..59db44f114 100644 --- a/src/main/webapp/app/views/admin/view.html +++ b/src/main/webapp/app/views/admin/view.html @@ -32,7 +32,7 @@

REVIEWER NOTES

- + {{submission.reviewerNotes || 'none'}}
@@ -82,7 +82,7 @@

ALL FILES

{{documentFieldValue.fileInfo.time | date : 'MM/dd/yyyy h:mm:ss a' }} - + diff --git a/src/main/webapp/app/views/directives/dragAndDropControlledVocabulary.html b/src/main/webapp/app/views/directives/dragAndDropControlledVocabulary.html index 04b38cfe04..91eac841e2 100644 --- a/src/main/webapp/app/views/directives/dragAndDropControlledVocabulary.html +++ b/src/main/webapp/app/views/directives/dragAndDropControlledVocabulary.html @@ -3,5 +3,5 @@ {{ item[property] }} - +
\ No newline at end of file diff --git a/src/main/webapp/app/views/directives/dragAndDropCustomAction.html b/src/main/webapp/app/views/directives/dragAndDropCustomAction.html index d74c9cf879..3db2a76fb2 100644 --- a/src/main/webapp/app/views/directives/dragAndDropCustomAction.html +++ b/src/main/webapp/app/views/directives/dragAndDropCustomAction.html @@ -8,5 +8,5 @@ {{item.label}} - +
\ No newline at end of file diff --git a/src/main/webapp/app/views/directives/dragAndDropDegree.html b/src/main/webapp/app/views/directives/dragAndDropDegree.html index 902adf8689..f3acd3f307 100644 --- a/src/main/webapp/app/views/directives/dragAndDropDegree.html +++ b/src/main/webapp/app/views/directives/dragAndDropDegree.html @@ -1,5 +1,5 @@
{{ item.position }}. {{item[properties[0]]}} ({{item[properties[1]].name}}) - +
diff --git a/src/main/webapp/app/views/directives/dragAndDropDepositLocation.html b/src/main/webapp/app/views/directives/dragAndDropDepositLocation.html index 23615c9ca7..c2a1958163 100644 --- a/src/main/webapp/app/views/directives/dragAndDropDepositLocation.html +++ b/src/main/webapp/app/views/directives/dragAndDropDepositLocation.html @@ -1,5 +1,5 @@
{{ item.position }}. {{item[property]}} - +
\ No newline at end of file diff --git a/src/main/webapp/app/views/directives/dragAndDropDocumentType.html b/src/main/webapp/app/views/directives/dragAndDropDocumentType.html index b2ff8a094b..8bb9363492 100644 --- a/src/main/webapp/app/views/directives/dragAndDropDocumentType.html +++ b/src/main/webapp/app/views/directives/dragAndDropDocumentType.html @@ -4,5 +4,5 @@ {{item[property]}} - + diff --git a/src/main/webapp/app/views/directives/dragAndDropEmailTemplates.html b/src/main/webapp/app/views/directives/dragAndDropEmailTemplates.html index dce24e8a56..9d681cd9e9 100644 --- a/src/main/webapp/app/views/directives/dragAndDropEmailTemplates.html +++ b/src/main/webapp/app/views/directives/dragAndDropEmailTemplates.html @@ -3,5 +3,5 @@ {{item[property]}} - + diff --git a/src/main/webapp/app/views/directives/dragAndDropFieldGloss.html b/src/main/webapp/app/views/directives/dragAndDropFieldGloss.html index 628c1b9562..35e5c9726f 100644 --- a/src/main/webapp/app/views/directives/dragAndDropFieldGloss.html +++ b/src/main/webapp/app/views/directives/dragAndDropFieldGloss.html @@ -4,5 +4,5 @@ {{item[property]}} - + diff --git a/src/main/webapp/app/views/directives/dragAndDropFieldPredicate.html b/src/main/webapp/app/views/directives/dragAndDropFieldPredicate.html index 628c1b9562..35e5c9726f 100644 --- a/src/main/webapp/app/views/directives/dragAndDropFieldPredicate.html +++ b/src/main/webapp/app/views/directives/dragAndDropFieldPredicate.html @@ -4,5 +4,5 @@ {{item[property]}} - + diff --git a/src/main/webapp/app/views/directives/dragAndDropFieldProfile.html b/src/main/webapp/app/views/directives/dragAndDropFieldProfile.html index a606c48c29..20e80e4c5e 100644 --- a/src/main/webapp/app/views/directives/dragAndDropFieldProfile.html +++ b/src/main/webapp/app/views/directives/dragAndDropFieldProfile.html @@ -3,6 +3,6 @@ {{ item[property] }}* - + diff --git a/src/main/webapp/app/views/directives/dragAndDropGraduationMonth.html b/src/main/webapp/app/views/directives/dragAndDropGraduationMonth.html index 491e2c399b..4a3876aeb8 100644 --- a/src/main/webapp/app/views/directives/dragAndDropGraduationMonth.html +++ b/src/main/webapp/app/views/directives/dragAndDropGraduationMonth.html @@ -1,5 +1,5 @@
{{ item.position }}. {{toString({month:item[property]})}} - +
\ No newline at end of file diff --git a/src/main/webapp/app/views/directives/dragAndDropLanguage.html b/src/main/webapp/app/views/directives/dragAndDropLanguage.html index 2ff9c304bd..d4d31c672f 100644 --- a/src/main/webapp/app/views/directives/dragAndDropLanguage.html +++ b/src/main/webapp/app/views/directives/dragAndDropLanguage.html @@ -4,5 +4,5 @@ {{ item[property] }} - + \ No newline at end of file diff --git a/src/main/webapp/app/views/directives/dragAndDropNote.html b/src/main/webapp/app/views/directives/dragAndDropNote.html index b4889dc057..7a8cd0eb2c 100644 --- a/src/main/webapp/app/views/directives/dragAndDropNote.html +++ b/src/main/webapp/app/views/directives/dragAndDropNote.html @@ -1,6 +1,6 @@
{{ item.position }}. {{ item[property] }} - +
diff --git a/src/main/webapp/app/views/directives/dragAndDropOrganizationCategory.html b/src/main/webapp/app/views/directives/dragAndDropOrganizationCategory.html index ab73542b79..0fe583a200 100644 --- a/src/main/webapp/app/views/directives/dragAndDropOrganizationCategory.html +++ b/src/main/webapp/app/views/directives/dragAndDropOrganizationCategory.html @@ -1,4 +1,4 @@
{{item[property]}} - +
\ No newline at end of file diff --git a/src/main/webapp/app/views/directives/lockingTextArea.html b/src/main/webapp/app/views/directives/lockingTextArea.html index 7b0a509735..b01a41d2fd 100644 --- a/src/main/webapp/app/views/directives/lockingTextArea.html +++ b/src/main/webapp/app/views/directives/lockingTextArea.html @@ -7,7 +7,7 @@

{{ label }}
- This field is unlocked and may be edited. Leaving the editable area will save and re-lock the field. + This field is unlocked and may be edited. Leaving the editable area will save and re-lock the field.

diff --git a/src/main/webapp/app/views/directives/submissionInfo.html b/src/main/webapp/app/views/directives/submissionInfo.html index 9fed99683f..782f423377 100644 --- a/src/main/webapp/app/views/directives/submissionInfo.html +++ b/src/main/webapp/app/views/directives/submissionInfo.html @@ -70,7 +70,7 @@ - + diff --git a/src/main/webapp/app/views/myprofile.html b/src/main/webapp/app/views/myprofile.html index 886d9343aa..8949fe9770 100644 --- a/src/main/webapp/app/views/myprofile.html +++ b/src/main/webapp/app/views/myprofile.html @@ -59,7 +59,7 @@

Personal Information

- + {{settings.user.displayName}} @@ -122,7 +122,7 @@

Phone & Address

- + {{settings.user.preferedEmail}} diff --git a/src/main/webapp/app/views/sideboxes/submissionStatus.html b/src/main/webapp/app/views/sideboxes/submissionStatus.html index 4a85431e37..10e5da5f23 100644 --- a/src/main/webapp/app/views/sideboxes/submissionStatus.html +++ b/src/main/webapp/app/views/sideboxes/submissionStatus.html @@ -3,7 +3,7 @@
  • Assignee:
  • - +
  • Last Action:
  • {{box.getLastActionDate() | date : 'short'}}
  • @@ -20,7 +20,7 @@ is-open="date" close-text="Close" stringtodate> - {{box.submission.submissionDate || "not submitted" | date: 'M/d/yyyy' : 'UTC'}} + {{box.submission.submissionDate || "not submitted" | date: 'M/d/yyyy' : 'UTC'}}
  • From 8024af1cf858c4550396de84a0c988aaff631e7b Mon Sep 17 00:00:00 2001 From: frank Date: Wed, 14 Oct 2026 13:07:43 -0500 Subject: [PATCH 2/2] Issue 2176: Make the labelled edit icons keyboard operable The alt text added for the pencil icons marked them as role="button" and gave them a tab stop, but nothing activated them from the keyboard and most were hidden in a way that kept them out of the tab order entirely. Add a keyboardActivate directive that activates role="button" elements on enter and space by dispatching a click, which also reaches the handler when it sits on an ancestor, as it does for the email workflow rules. Reveal the hover-only icons on focus as well as hover. They were hidden with display: none and visibility: hidden, neither of which leaves an element focusable, so hide them with opacity instead. The pencil in the custom action list sits outside the element carrying the click handler, so mark it decorative and label that element instead. Co-Authored-By: Claude Opus 5 (1M context) --- .../directives/keyboardActivateDirective.js | 34 +++++ .../webapp/app/resources/styles/sass/app.scss | 27 +++- .../organization/emailWorkflowRule.html | 2 +- src/main/webapp/app/views/admin/view.html | 4 +- .../dragAndDropControlledVocabulary.html | 2 +- .../directives/dragAndDropCustomAction.html | 10 +- .../views/directives/dragAndDropDegree.html | 2 +- .../dragAndDropDepositLocation.html | 2 +- .../directives/dragAndDropDocumentType.html | 2 +- .../directives/dragAndDropEmailTemplates.html | 2 +- .../directives/dragAndDropFieldGloss.html | 2 +- .../directives/dragAndDropFieldPredicate.html | 2 +- .../directives/dragAndDropFieldProfile.html | 2 +- .../dragAndDropGraduationMonth.html | 2 +- .../views/directives/dragAndDropLanguage.html | 2 +- .../app/views/directives/dragAndDropNote.html | 2 +- .../dragAndDropOrganizationCategory.html | 2 +- .../app/views/directives/submissionInfo.html | 2 +- src/main/webapp/app/views/myprofile.html | 4 +- .../keyboardActivateDirectiveTest.js | 135 ++++++++++++++++++ 20 files changed, 219 insertions(+), 23 deletions(-) create mode 100644 src/main/webapp/app/directives/keyboardActivateDirective.js create mode 100644 src/main/webapp/tests/unit/directives/keyboardActivateDirectiveTest.js diff --git a/src/main/webapp/app/directives/keyboardActivateDirective.js b/src/main/webapp/app/directives/keyboardActivateDirective.js new file mode 100644 index 0000000000..8d122dea75 --- /dev/null +++ b/src/main/webapp/app/directives/keyboardActivateDirective.js @@ -0,0 +1,34 @@ +vireo.directive('keyboardActivate', function() { + return { + restrict: 'A', + link: function($scope, element) { + + // Anything exposed as role="button" must also respond to Enter and + // Space. Native buttons and links already do, so leave those alone + // rather than activating them twice. + var nativelyActivated = ['A', 'BUTTON', 'INPUT', 'SELECT', 'TEXTAREA']; + + if (nativelyActivated.indexOf(element[0].nodeName) > -1) { + return; + } + + // Bound natively instead of with ng-keydown. ng-keydown would run + // inside a digest, and the click dispatched below starts its own, + // which would throw "$apply already in progress". + element.on('keydown', function(event) { + + if (event.which !== 13 && event.which !== 32) { + return; + } + + // Space would otherwise scroll the page. + event.preventDefault(); + + // A real click rather than the scope expression, so it bubbles + // to whichever element owns the ng-click. For some of the edit + // icons that is an ancestor, not the icon itself. + element[0].click(); + }); + } + }; +}); diff --git a/src/main/webapp/app/resources/styles/sass/app.scss b/src/main/webapp/app/resources/styles/sass/app.scss index 1ba8ab43ed..2ac804a76a 100644 --- a/src/main/webapp/app/resources/styles/sass/app.scss +++ b/src/main/webapp/app/resources/styles/sass/app.scss @@ -672,6 +672,20 @@ h4 { cursor: pointer; } +// Revealed on row hover, but kept in the layout rather than removed, so that it +// stays focusable for keyboard users. Focus reveals it the same way hover does. +.edit-setting-icon.edit-setting-icon-hidden { + opacity: 0; + pointer-events: none; +} + +.edit-setting-icon:focus, +.edit-setting-icon.edit-setting-icon-hidden:focus { + opacity: 1; + outline: 1px dotted; + pointer-events: auto; +} + .td-center-middle { text-align: center; vertical-align: middle; @@ -1649,12 +1663,19 @@ input[type=color]:focus { cursor: pointer; } +// Hidden with opacity rather than visibility so the icon stays focusable; a +// visibility: hidden element is dropped from the tab order entirely. .email-workflow-rule-row span.glyphicon-pencil { - visibility: hidden; + opacity: 0; } -.email-workflow-rule-row:hover span.glyphicon-pencil { - visibility: visible; +.email-workflow-rule-row:hover span.glyphicon-pencil, +.email-workflow-rule-row span.glyphicon-pencil:focus { + opacity: 1; +} + +.email-workflow-rule-row span.glyphicon-pencil:focus { + outline: 1px dotted; } .submission-review-item { diff --git a/src/main/webapp/app/views/admin/settings/organization/emailWorkflowRule.html b/src/main/webapp/app/views/admin/settings/organization/emailWorkflowRule.html index 2f22dc5e30..99dca12281 100644 --- a/src/main/webapp/app/views/admin/settings/organization/emailWorkflowRule.html +++ b/src/main/webapp/app/views/admin/settings/organization/emailWorkflowRule.html @@ -21,7 +21,7 @@ ng-repeat="rule in getSelectedOrganizationEmailWorkflowRules()" class="email-workflow-rule-row"> - + {{rule.emailTemplate.name}} diff --git a/src/main/webapp/app/views/admin/view.html b/src/main/webapp/app/views/admin/view.html index 59db44f114..3391b93976 100644 --- a/src/main/webapp/app/views/admin/view.html +++ b/src/main/webapp/app/views/admin/view.html @@ -32,7 +32,7 @@

    REVIEWER NOTES

    - + {{submission.reviewerNotes || 'none'}}
    @@ -82,7 +82,7 @@

    ALL FILES

    {{documentFieldValue.fileInfo.time | date : 'MM/dd/yyyy h:mm:ss a' }} - + diff --git a/src/main/webapp/app/views/directives/dragAndDropControlledVocabulary.html b/src/main/webapp/app/views/directives/dragAndDropControlledVocabulary.html index 91eac841e2..8000809350 100644 --- a/src/main/webapp/app/views/directives/dragAndDropControlledVocabulary.html +++ b/src/main/webapp/app/views/directives/dragAndDropControlledVocabulary.html @@ -3,5 +3,5 @@ {{ item[property] }} - +
    \ No newline at end of file diff --git a/src/main/webapp/app/views/directives/dragAndDropCustomAction.html b/src/main/webapp/app/views/directives/dragAndDropCustomAction.html index 3db2a76fb2..38533c781d 100644 --- a/src/main/webapp/app/views/directives/dragAndDropCustomAction.html +++ b/src/main/webapp/app/views/directives/dragAndDropCustomAction.html @@ -1,12 +1,18 @@
    {{ item.position }}. + ng-mouseleave="isMouseHover=false" + ng-focus="isMouseHover=true" + ng-blur="isMouseHover=false"> {{item.label}} - +
    \ No newline at end of file diff --git a/src/main/webapp/app/views/directives/dragAndDropDegree.html b/src/main/webapp/app/views/directives/dragAndDropDegree.html index f3acd3f307..3ce018a4b4 100644 --- a/src/main/webapp/app/views/directives/dragAndDropDegree.html +++ b/src/main/webapp/app/views/directives/dragAndDropDegree.html @@ -1,5 +1,5 @@
    {{ item.position }}. {{item[properties[0]]}} ({{item[properties[1]].name}}) - +
    diff --git a/src/main/webapp/app/views/directives/dragAndDropDepositLocation.html b/src/main/webapp/app/views/directives/dragAndDropDepositLocation.html index c2a1958163..6f193bcae1 100644 --- a/src/main/webapp/app/views/directives/dragAndDropDepositLocation.html +++ b/src/main/webapp/app/views/directives/dragAndDropDepositLocation.html @@ -1,5 +1,5 @@
    {{ item.position }}. {{item[property]}} - +
    \ No newline at end of file diff --git a/src/main/webapp/app/views/directives/dragAndDropDocumentType.html b/src/main/webapp/app/views/directives/dragAndDropDocumentType.html index 8bb9363492..3e4ac4dc41 100644 --- a/src/main/webapp/app/views/directives/dragAndDropDocumentType.html +++ b/src/main/webapp/app/views/directives/dragAndDropDocumentType.html @@ -4,5 +4,5 @@ {{item[property]}} - +
    diff --git a/src/main/webapp/app/views/directives/dragAndDropEmailTemplates.html b/src/main/webapp/app/views/directives/dragAndDropEmailTemplates.html index 9d681cd9e9..33ad7cac9c 100644 --- a/src/main/webapp/app/views/directives/dragAndDropEmailTemplates.html +++ b/src/main/webapp/app/views/directives/dragAndDropEmailTemplates.html @@ -3,5 +3,5 @@ {{item[property]}} - +
    diff --git a/src/main/webapp/app/views/directives/dragAndDropFieldGloss.html b/src/main/webapp/app/views/directives/dragAndDropFieldGloss.html index 35e5c9726f..22d52cf8a4 100644 --- a/src/main/webapp/app/views/directives/dragAndDropFieldGloss.html +++ b/src/main/webapp/app/views/directives/dragAndDropFieldGloss.html @@ -4,5 +4,5 @@ {{item[property]}} - + diff --git a/src/main/webapp/app/views/directives/dragAndDropFieldPredicate.html b/src/main/webapp/app/views/directives/dragAndDropFieldPredicate.html index 35e5c9726f..22d52cf8a4 100644 --- a/src/main/webapp/app/views/directives/dragAndDropFieldPredicate.html +++ b/src/main/webapp/app/views/directives/dragAndDropFieldPredicate.html @@ -4,5 +4,5 @@ {{item[property]}} - + diff --git a/src/main/webapp/app/views/directives/dragAndDropFieldProfile.html b/src/main/webapp/app/views/directives/dragAndDropFieldProfile.html index 20e80e4c5e..2a2566a05d 100644 --- a/src/main/webapp/app/views/directives/dragAndDropFieldProfile.html +++ b/src/main/webapp/app/views/directives/dragAndDropFieldProfile.html @@ -3,6 +3,6 @@ {{ item[property] }}* - + diff --git a/src/main/webapp/app/views/directives/dragAndDropGraduationMonth.html b/src/main/webapp/app/views/directives/dragAndDropGraduationMonth.html index 4a3876aeb8..cfd6d05494 100644 --- a/src/main/webapp/app/views/directives/dragAndDropGraduationMonth.html +++ b/src/main/webapp/app/views/directives/dragAndDropGraduationMonth.html @@ -1,5 +1,5 @@
    {{ item.position }}. {{toString({month:item[property]})}} - +
    \ No newline at end of file diff --git a/src/main/webapp/app/views/directives/dragAndDropLanguage.html b/src/main/webapp/app/views/directives/dragAndDropLanguage.html index d4d31c672f..0e0a626f9e 100644 --- a/src/main/webapp/app/views/directives/dragAndDropLanguage.html +++ b/src/main/webapp/app/views/directives/dragAndDropLanguage.html @@ -4,5 +4,5 @@ {{ item[property] }} - + \ No newline at end of file diff --git a/src/main/webapp/app/views/directives/dragAndDropNote.html b/src/main/webapp/app/views/directives/dragAndDropNote.html index 7a8cd0eb2c..08e1215a1e 100644 --- a/src/main/webapp/app/views/directives/dragAndDropNote.html +++ b/src/main/webapp/app/views/directives/dragAndDropNote.html @@ -1,6 +1,6 @@
    {{ item.position }}. {{ item[property] }} - +
    diff --git a/src/main/webapp/app/views/directives/dragAndDropOrganizationCategory.html b/src/main/webapp/app/views/directives/dragAndDropOrganizationCategory.html index 0fe583a200..cdbff2ea6a 100644 --- a/src/main/webapp/app/views/directives/dragAndDropOrganizationCategory.html +++ b/src/main/webapp/app/views/directives/dragAndDropOrganizationCategory.html @@ -1,4 +1,4 @@
    {{item[property]}} - +
    \ No newline at end of file diff --git a/src/main/webapp/app/views/directives/submissionInfo.html b/src/main/webapp/app/views/directives/submissionInfo.html index 782f423377..645700e293 100644 --- a/src/main/webapp/app/views/directives/submissionInfo.html +++ b/src/main/webapp/app/views/directives/submissionInfo.html @@ -70,7 +70,7 @@ - + diff --git a/src/main/webapp/app/views/myprofile.html b/src/main/webapp/app/views/myprofile.html index 8949fe9770..9db456e974 100644 --- a/src/main/webapp/app/views/myprofile.html +++ b/src/main/webapp/app/views/myprofile.html @@ -59,7 +59,7 @@

    Personal Information

    - + {{settings.user.displayName}} @@ -122,7 +122,7 @@

    Phone & Address

    - + {{settings.user.preferedEmail}} diff --git a/src/main/webapp/tests/unit/directives/keyboardActivateDirectiveTest.js b/src/main/webapp/tests/unit/directives/keyboardActivateDirectiveTest.js new file mode 100644 index 0000000000..8d1dc0bdfa --- /dev/null +++ b/src/main/webapp/tests/unit/directives/keyboardActivateDirectiveTest.js @@ -0,0 +1,135 @@ +describe('directive: keyboardActivate', function () { + var compile, directive, httpBackend, rootScope, scope, templateCache, window, MockedUser; + + var ENTER = 13; + var SPACE = 32; + + var initializeVariables = function () { + inject(function ($q, $compile, $httpBackend, $rootScope, $templateCache, $window) { + compile = $compile; + httpBackend = $httpBackend; + rootScope = $rootScope; + templateCache = $templateCache; + window = $window; + MockedUser = new mockUser($q); + }); + }; + + var initializeDirective = function (markup) { + inject(function () { + scope = rootScope.$new(); + scope.activate = jasmine.createSpy('activate'); + + directive = compile(markup || '')(scope); + + scope.$digest(); + }); + }; + + // The event object is extended onto whatever event the element library + // hands the handler, so a spy here is called in place of the real + // preventDefault whether jqLite or jQuery is in play. + var keydown = function (element, which) { + var event = { + type: 'keydown', + which: which, + preventDefault: jasmine.createSpy('preventDefault') + }; + + element.triggerHandler(event); + + return event; + }; + + beforeEach(function() { + module('core'); + module('vireo'); + module("mock.user", function ($provide) { + var User = function () { + return MockedUser; + }; + $provide.value("User", User); + }); + module("mock.userService"); + + installPromiseMatchers(); + initializeVariables(); + }); + + describe('Does the directive compile', function () { + it('should be defined', function () { + initializeDirective(); + expect(directive).toBeDefined(); + }); + }); + + describe('Is the element activated by the keyboard', function () { + it('should activate on enter', function () { + initializeDirective(); + + keydown(directive, ENTER); + + expect(scope.activate).toHaveBeenCalled(); + }); + + it('should activate on space', function () { + initializeDirective(); + + keydown(directive, SPACE); + + expect(scope.activate).toHaveBeenCalled(); + }); + + it('should not activate on any other key', function () { + initializeDirective(); + + keydown(directive, 65); + + expect(scope.activate).not.toHaveBeenCalled(); + }); + + it('should prevent the default action when activating', function () { + initializeDirective(); + + var event = keydown(directive, SPACE); + + expect(event.preventDefault).toHaveBeenCalled(); + }); + + it('should leave the default action alone for any other key', function () { + initializeDirective(); + + var event = keydown(directive, 65); + + expect(event.preventDefault).not.toHaveBeenCalled(); + }); + }); + + describe('Is an ancestor handler reached', function () { + it('should activate a handler on a parent element', function () { + initializeDirective('
    '); + + keydown(angular.element(directive[0].querySelector('span')), ENTER); + + expect(scope.activate).toHaveBeenCalled(); + }); + }); + + describe('Are natively activated elements left alone', function () { + it('should not bind to a button, which the browser already activates', function () { + initializeDirective(''); + + keydown(directive, ENTER); + + expect(scope.activate).not.toHaveBeenCalled(); + }); + + it('should not bind to an anchor, which the browser already activates', function () { + initializeDirective(''); + + keydown(directive, ENTER); + + expect(scope.activate).not.toHaveBeenCalled(); + }); + }); +});