(function($) {
describe("TreeDropdownField", function() {
$.entwine.warningLevel = $.entwine.WARN_LEVEL_BESTPRACTISE;
$.entwine.synchronous_mode();
// helpers
var loadTree = function(container, html) {
if(!html) html = readFixtures('fixtures/tree.html');
container.entwine('ss').loadTree();
var request = mostRecentAjaxRequest();
request.response({
status: 200,
contentType: 'text/html',
responseText: html
});
// loaded doesnt trigger automatically in test mode
container.find('.tree-holder').jstree('loaded');
}
describe('when field is basic', function() {
beforeEach(function() {
// load fixture
$('body').append(
'
' +
'' +
'
'
);
});
afterEach(function() {
$('#testfield').remove();
});
it('displays the default title', function() {
expect($('#testfield').entwine('ss').getTitle()).toEqual('Selected');
});
it('opens the tree panel when edit link is clicked', function() {
var panel = $('#testfield').entwine('ss').getPanel();
expect(panel).toBeHidden();
$('#testfield a.toggle-panel-link').click();
expect(panel).toBeVisible();
});
it('loads the tree when panel is first shown', function() {
var panel = $('#testfield').entwine('ss').getPanel();
$('#testfield').entwine('ss').openPanel();
var request = mostRecentAjaxRequest();
request.response({
status: 200,
contentType: 'text/html',
responseText: readFixtures('fixtures/tree.html')
});
expect(panel).toContain('ul');
});
describe('when an item is selected', function() {
it('closes the panel', function() {
var f = $('#testfield'), panel = f.entwine('ss').getPanel();
loadTree(f);
f.entwine('ss').openPanel();
panel.find('li[data-id=2] a').click();
expect(panel).toBeHidden();
});
it('it sets the selected value on the input field', function() {
var f = $('#testfield'), panel = f.entwine('ss').getPanel();
loadTree(f);
panel.find('li[data-id=2] a').click();
expect(f.entwine('ss').getValue()).toEqual('2');
});
it('it sets the selected title', function() {
var f = $('#testfield'), panel = f.entwine('ss').getPanel();
loadTree(f);
panel.find('li[data-id=2] a').click();
expect(f.entwine('ss').getTitle()).toEqual('Child node 1');
});
});
});
describe('when field is searchable', function() {
beforeEach(function() {
// load fixture
$('body').append(
'