Fix a problem where you couldn't type a question-mark

-- For some reason, showHelp() was no longer able to detect which
element had raised the event when you typed a question-mark, so the help
dialog would pop up when you were trying to edit a legend.
-- Fixed by consulting document.activeElement instead of the event's
srcElement
-- Also added some unit tests for this.
This commit is contained in:
Ian Prest 2015-07-26 22:03:58 -04:00
parent 66b278b84d
commit 8f09fbfdbd
2 changed files with 22 additions and 1 deletions

2
kb.js
View file

@ -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",

View file

@ -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() {