2017-11-21 05:53:09 -05:00
|
|
|
function checkSelectKitIsNotExpanded(selector) {
|
|
|
|
if (find(selector).hasClass('is-expanded')) {
|
|
|
|
throw 'You expected select-kit to be collapsed but it is expanded.';
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function checkSelectKitIsNotCollapsed(selector) {
|
|
|
|
if (!find(selector).hasClass('is-expanded')) {
|
|
|
|
throw 'You expected select-kit to be expanded but it is collapsed.';
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
Ember.Test.registerAsyncHelper('expandSelectKit', function(app, selector) {
|
|
|
|
checkSelectKitIsNotExpanded(selector);
|
|
|
|
click(selector + ' .select-kit-header');
|
|
|
|
});
|
|
|
|
|
|
|
|
Ember.Test.registerAsyncHelper('collapseSelectKit', function(app, selector) {
|
|
|
|
checkSelectKitIsNotCollapsed(selector);
|
|
|
|
click(selector + ' .select-kit-header');
|
|
|
|
});
|
|
|
|
|
2017-12-22 07:08:12 -05:00
|
|
|
Ember.Test.registerAsyncHelper('selectKitFillInFilter', function(app, filter, selector) {
|
|
|
|
checkSelectKitIsNotCollapsed(selector);
|
|
|
|
fillIn(selector + ' .filter-input', filter);
|
2017-11-21 05:53:09 -05:00
|
|
|
});
|
|
|
|
|
2017-12-22 07:08:12 -05:00
|
|
|
Ember.Test.registerAsyncHelper('selectKitSelectRowByValue', function(app, value, selector) {
|
|
|
|
checkSelectKitIsNotCollapsed(selector);
|
|
|
|
click(selector + " .select-kit-row[data-value='" + value + "']");
|
2017-11-21 05:53:09 -05:00
|
|
|
});
|
|
|
|
|
2017-12-22 07:08:12 -05:00
|
|
|
Ember.Test.registerAsyncHelper('selectKitSelectRowByName', function(app, name, selector) {
|
|
|
|
checkSelectKitIsNotCollapsed(selector);
|
|
|
|
click(selector + " .select-kit-row[data-name='" + name + "']");
|
|
|
|
});
|
2017-11-21 05:53:09 -05:00
|
|
|
|
2017-12-22 07:08:12 -05:00
|
|
|
Ember.Test.registerAsyncHelper('selectKitSelectNoneRow', function(app, selector) {
|
|
|
|
checkSelectKitIsNotCollapsed(selector);
|
|
|
|
click(selector + " .select-kit-row.none");
|
|
|
|
});
|
2017-11-21 05:53:09 -05:00
|
|
|
|
2017-12-22 07:08:12 -05:00
|
|
|
Ember.Test.registerAsyncHelper('selectKitSelectRowByIndex', function(app, index, selector) {
|
|
|
|
checkSelectKitIsNotCollapsed(selector);
|
|
|
|
click(find(selector + " .select-kit-row").eq(index));
|
2017-11-21 05:53:09 -05:00
|
|
|
});
|
|
|
|
|
|
|
|
function selectKit(selector) { // eslint-disable-line no-unused-vars
|
2017-12-22 07:08:12 -05:00
|
|
|
selector = selector || ".select-kit";
|
2017-11-21 05:53:09 -05:00
|
|
|
|
|
|
|
function rowHelper(row) {
|
|
|
|
return {
|
|
|
|
name: function() { return row.attr('data-name'); },
|
|
|
|
icon: function() { return row.find('.d-icon'); },
|
|
|
|
title: function() { return row.attr('title'); },
|
|
|
|
value: function() { return row.attr('data-value'); },
|
2017-12-22 07:08:12 -05:00
|
|
|
exists: function() { return exists(row); },
|
|
|
|
el: function() { return row; }
|
2017-11-21 05:53:09 -05:00
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
function headerHelper(header) {
|
|
|
|
return {
|
2017-12-22 07:08:12 -05:00
|
|
|
value: function() { return header.attr('data-value'); },
|
|
|
|
name: function() { return header.attr('data-name'); },
|
2017-11-21 05:53:09 -05:00
|
|
|
icon: function() { return header.find('.icon'); },
|
|
|
|
title: function() { return header.attr('title'); },
|
2017-12-22 07:08:12 -05:00
|
|
|
el: function() { return header; }
|
2017-11-21 05:53:09 -05:00
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
function filterHelper(filter) {
|
|
|
|
return {
|
|
|
|
icon: function() { return filter.find('.d-icon'); },
|
|
|
|
exists: function() { return exists(filter); },
|
2017-12-22 07:08:12 -05:00
|
|
|
el: function() { return filter; }
|
2017-11-21 05:53:09 -05:00
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2017-12-22 07:08:12 -05:00
|
|
|
function keyboardHelper(eventSelector) {
|
2017-11-21 05:53:09 -05:00
|
|
|
function createEvent(target, keyCode, options) {
|
|
|
|
target = target || ".filter-input";
|
2017-12-22 07:08:12 -05:00
|
|
|
eventSelector = find(eventSelector).find(target);
|
2017-11-21 05:53:09 -05:00
|
|
|
options = options || {};
|
|
|
|
|
|
|
|
andThen(function() {
|
|
|
|
var type = options.type || 'keydown';
|
|
|
|
var event = jQuery.Event(type);
|
|
|
|
event.keyCode = keyCode;
|
2018-01-11 03:39:51 -05:00
|
|
|
if (options && options.metaKey) { event.metaKey = true; }
|
2017-12-22 07:08:12 -05:00
|
|
|
find(eventSelector).trigger(event);
|
2017-11-21 05:53:09 -05:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
return {
|
|
|
|
down: function(target) { createEvent(target, 40); },
|
|
|
|
up: function(target) { createEvent(target, 38); },
|
|
|
|
escape: function(target) { createEvent(target, 27); },
|
|
|
|
enter: function(target) { createEvent(target, 13); },
|
|
|
|
tab: function(target) { createEvent(target, 9); },
|
|
|
|
backspace: function(target) { createEvent(target, 8); },
|
|
|
|
selectAll: function(target) { createEvent(target, 65, {metaKey: true}); },
|
|
|
|
};
|
2017-12-22 07:08:12 -05:00
|
|
|
};
|
2017-11-21 05:53:09 -05:00
|
|
|
|
|
|
|
return {
|
2017-12-22 07:08:12 -05:00
|
|
|
expand: function() {
|
|
|
|
expandSelectKit(selector);
|
|
|
|
return selectKit(selector);
|
|
|
|
},
|
2017-11-21 05:53:09 -05:00
|
|
|
|
2017-12-22 07:08:12 -05:00
|
|
|
collapse: function() {
|
|
|
|
collapseSelectKit(selector);
|
|
|
|
return selectKit(selector);
|
|
|
|
},
|
2017-11-21 05:53:09 -05:00
|
|
|
|
2017-12-22 07:08:12 -05:00
|
|
|
selectRowByIndex: function(index) {
|
|
|
|
selectKitSelectRowByIndex(index, selector);
|
|
|
|
return selectKit(selector);
|
|
|
|
},
|
2017-11-21 05:53:09 -05:00
|
|
|
|
2017-12-22 07:08:12 -05:00
|
|
|
selectRowByValue: function(value) {
|
|
|
|
selectKitSelectRowByValue(value, selector);
|
|
|
|
return selectKit(selector);
|
|
|
|
},
|
2017-11-21 05:53:09 -05:00
|
|
|
|
2017-12-22 07:08:12 -05:00
|
|
|
selectRowByName: function(name) {
|
|
|
|
selectKitSelectRowByValue(name, selector);
|
|
|
|
return selectKit(selector);
|
|
|
|
},
|
|
|
|
|
|
|
|
selectNoneRow: function() {
|
|
|
|
selectKitSelectNoneRow(selector);
|
|
|
|
return selectKit(selector);
|
|
|
|
},
|
|
|
|
|
|
|
|
fillInFilter: function(filter) {
|
|
|
|
selectKitFillInFilter(filter, selector);
|
|
|
|
return selectKit(selector);
|
|
|
|
},
|
|
|
|
|
|
|
|
keyboard: function() { return keyboardHelper(selector); },
|
2017-11-21 05:53:09 -05:00
|
|
|
|
2017-12-22 07:08:12 -05:00
|
|
|
isExpanded: function() {
|
|
|
|
return find(selector).hasClass('is-expanded');
|
|
|
|
},
|
|
|
|
|
|
|
|
isFocused: function() {
|
|
|
|
return find(selector).hasClass('is-focused');
|
|
|
|
},
|
|
|
|
|
|
|
|
isHidden: function() {
|
|
|
|
return find(selector).hasClass('is-hidden');
|
|
|
|
},
|
|
|
|
|
|
|
|
header: function() {
|
|
|
|
return headerHelper(find(selector).find('.select-kit-header'));
|
|
|
|
},
|
|
|
|
|
|
|
|
filter: function() {
|
|
|
|
return filterHelper(find(selector).find('.select-kit-filter'));
|
|
|
|
},
|
|
|
|
|
|
|
|
rows: function() {
|
|
|
|
return find(selector).find('.select-kit-row');
|
|
|
|
},
|
2017-11-21 05:53:09 -05:00
|
|
|
|
|
|
|
rowByValue: function(value) {
|
|
|
|
return rowHelper(find(selector).find('.select-kit-row[data-value="' + value + '"]'));
|
|
|
|
},
|
|
|
|
|
|
|
|
rowByName: function(name) {
|
|
|
|
return rowHelper(find(selector).find('.select-kit-row[data-name="' + name + '"]'));
|
|
|
|
},
|
|
|
|
|
|
|
|
rowByIndex: function(index) {
|
|
|
|
return rowHelper(find(selector).find('.select-kit-row:eq(' + index + ')'));
|
|
|
|
},
|
|
|
|
|
2017-12-22 07:08:12 -05:00
|
|
|
el: function() { return find(selector); },
|
2017-11-21 05:53:09 -05:00
|
|
|
|
2017-12-22 07:08:12 -05:00
|
|
|
noneRow: function() {
|
|
|
|
return rowHelper(find(selector).find('.select-kit-row.none'));
|
|
|
|
},
|
2017-11-21 05:53:09 -05:00
|
|
|
|
2017-12-22 07:08:12 -05:00
|
|
|
selectedRow: function() {
|
|
|
|
return rowHelper(find(selector).find('.select-kit-row.is-selected'));
|
|
|
|
},
|
|
|
|
|
|
|
|
highlightedRow: function() {
|
|
|
|
return rowHelper(find(selector).find('.select-kit-row.is-highlighted'));
|
|
|
|
},
|
2017-11-21 05:53:09 -05:00
|
|
|
|
2017-12-22 07:08:12 -05:00
|
|
|
exists: function() { return exists(selector); }
|
2017-11-21 05:53:09 -05:00
|
|
|
};
|
|
|
|
}
|