Commit 49c7ca2a authored by Luke Bennett's avatar Luke Bennett

Fixed spec and improved formatting

parent f91fd18f
...@@ -690,8 +690,8 @@ ...@@ -690,8 +690,8 @@
if (!index) { if (!index) {
$dropdownContent.scrollTop(0) $dropdownContent.scrollTop(0)
} else if (index === ($listItems.length - 1)) { } else if (index === ($listItems.length - 1)) {
$dropdownContent.scrollTop $dropdownContent.prop('scrollHeight'); $dropdownContent.scrollTop($dropdownContent.prop('scrollHeight'));
} else if (listItemBottom > (dropdownContentBottom + dropdownScrollTop)) } else if (listItemBottom > (dropdownContentBottom + dropdownScrollTop)) {
$dropdownContent.scrollTop(listItemBottom - dropdownContentBottom + CURSOR_SELECT_SCROLL_PADDING); $dropdownContent.scrollTop(listItemBottom - dropdownContentBottom + CURSOR_SELECT_SCROLL_PADDING);
} else if (listItemTop < (dropdownContentTop + dropdownScrollTop)) { } else if (listItemTop < (dropdownContentTop + dropdownScrollTop)) {
return $dropdownContent.scrollTop(listItemTop - dropdownContentTop - CURSOR_SELECT_SCROLL_PADDING); return $dropdownContent.scrollTop(listItemTop - dropdownContentTop - CURSOR_SELECT_SCROLL_PADDING);
......
...@@ -228,7 +228,7 @@ ...@@ -228,7 +228,7 @@
case KEYCODE.ENTER: case KEYCODE.ENTER:
this.disableAutocomplete(); this.disableAutocomplete();
break; break;
case KEYCODE.UP, case KEYCODE.UP:
case KEYCODE.DOWN: case KEYCODE.DOWN:
return; return;
default: default:
......
...@@ -16,12 +16,13 @@ ...@@ -16,12 +16,13 @@
ESC: 27 ESC: 27
}; };
var navigateWithKeys = function navigateWithKeys(direction, steps, cb, i) { let navigateWithKeys = function navigateWithKeys(direction, steps, cb, i) {
i = i || 0; i = i || 0;
if (!i) direction = direction.toUpperCase();
$('body').trigger({ $('body').trigger({
type: 'keydown', type: 'keydown',
which: ARROW_KEYS[direction.toUpperCase()], which: ARROW_KEYS[direction],
keyCode: ARROW_KEYS[direction.toUpperCase()] keyCode: ARROW_KEYS[direction]
}); });
i++; i++;
if (i <= steps) { if (i <= steps) {
...@@ -31,35 +32,31 @@ ...@@ -31,35 +32,31 @@
} }
}; };
var initDropdown = function initDropdown() {
this.dropdownContainerElement = $('.dropdown.inline');
this.dropdownMenuElement = $('.dropdown-menu', this.dropdownContainerElement);
this.projectsData = fixture.load('projects.json')[0];
this.dropdownButtonElement = $('#js-project-dropdown', this.dropdownContainerElement).glDropdown({
selectable: true,
data: this.projectsData,
text: (project) => {
(project.name_with_namespace || project.name)
},
id: (project) => {
project.id
}
});
};
describe('Dropdown', function describeDropdown() { describe('Dropdown', function describeDropdown() {
fixture.preload('gl_dropdown.html'); fixture.preload('gl_dropdown.html');
fixture.preload('projects.json'); fixture.preload('projects.json');
function beforeEach() { beforeEach(() => {
fixture.load('gl_dropdown.html'); fixture.load('gl_dropdown.html');
initDropdown.call(this); this.dropdownContainerElement = $('.dropdown.inline');
} this.dropdownMenuElement = $('.dropdown-menu', this.dropdownContainerElement);
this.projectsData = fixture.load('projects.json')[0];
this.dropdownButtonElement = $('#js-project-dropdown', this.dropdownContainerElement).glDropdown({
selectable: true,
data: this.projectsData,
text: (project) => {
(project.name_with_namespace || project.name)
},
id: (project) => {
project.id
}
});
});
function afterEach() { afterEach(() => {
$('body').unbind('keydown'); $('body').unbind('keydown');
this.dropdownContainerElement.unbind('keyup'); this.dropdownContainerElement.unbind('keyup');
} });
it('should open on click', () => { it('should open on click', () => {
expect(this.dropdownContainerElement).not.toHaveClass('open'); expect(this.dropdownContainerElement).not.toHaveClass('open');
...@@ -67,10 +64,10 @@ ...@@ -67,10 +64,10 @@
expect(this.dropdownContainerElement).toHaveClass('open'); expect(this.dropdownContainerElement).toHaveClass('open');
}); });
describe('that is open', function describeThatIsOpen() { describe('that is open', () => {
function beforeEach() { beforeEach(() => {
this.dropdownButtonElement.click(); this.dropdownButtonElement.click();
} });
it('should select a following item on DOWN keypress', () => { it('should select a following item on DOWN keypress', () => {
expect($(FOCUSED_ITEM_SELECTOR, this.dropdownMenuElement).length).toBe(0); expect($(FOCUSED_ITEM_SELECTOR, this.dropdownMenuElement).length).toBe(0);
...@@ -119,4 +116,4 @@ ...@@ -119,4 +116,4 @@
}); });
}); });
}); });
})(window); })();
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment