diff --git a/kb.js b/kb.js index a0d8243..7fa4392 100644 --- a/kb.js +++ b/kb.js @@ -863,7 +863,7 @@ }; $scope.showHelp = function(event) { - if(!event.srcElement || (event.srcElement.nodeName !== "INPUT" && event.srcElement.nodeName !== "TEXTAREA")) { + if(!document.activeElement || (document.activeElement.nodeName !== "INPUT" && document.activeElement.nodeName !== "TEXTAREA")) { if(activeModal) activeModal.dismiss('cancel'); activeModal = $modal.open({ templateUrl:"helpDialog.html", diff --git a/tests/kb-spec.js b/tests/kb-spec.js index 43d12cf..0333b5f 100644 --- a/tests/kb-spec.js +++ b/tests/kb-spec.js @@ -15,12 +15,33 @@ describe('keyboard-layout-editor', function() { capture.snap(getSpecName(), $('#keyboard')); }; + beforeEach(function() { + // Hacky workaround to prevent alert dialogs from breaking all the tests + browser.executeScript("window.onbeforeunload = function(){};"); + }); + // Simple launch test it('should launch without an error', function() { browser.get(''); kbScreenshot(); }); + describe('show-help', function() { + it('should appear I press "?"', function() { + browser.get(''); + element(by.css('body')).sendKeys('?'); // try to type a question-mark + expect(element(by.css('.modal-dialog')).isPresent()).toBeTruthy(); + }); + + it('should not appear when I press "?" in an edit field', function() { + browser.get(''); + element(by.id('keyboard')).sendKeys('j'); // select a key + element(by.id('labeleditor0')).sendKeys('?'); // try to type a question-mark + expect(element(by.css('.modal-dialog')).isPresent()).toBeFalsy(); + expect(element(by.id('labeleditor0')).getAttribute('value')).toContain('?'); + }); + }); + // Test renderings of various samples describe('rendering sample', function() { it('commodore-vic20', function() {