Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix failing tests. #48

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
76 changes: 24 additions & 52 deletions tests/lib/LayerList.test.html
Original file line number Diff line number Diff line change
Expand Up @@ -322,14 +322,8 @@
}

function test_destroy(t) {
var funcToStringSupported = !!(Function.prototype.toString);

if (funcToStringSupported) {
t.plan(9);
} else {
t.plan(6);
}

t.plan(9);

t.delay_call(1, function(){
var map = new OpenLayers.Map({
layers: [
Expand All @@ -339,92 +333,70 @@
],
controls: []
});

var mappanel = Ext.create('GXM.Map', {
map: map,
title: 'foo',
iconCls: 'user'
});

// remove existing default handlers to make comparison easy:
map.events.listeners.changelayer = [];
map.events.listeners.addlayer = [];
map.events.listeners.removelayer = [];

var layerlist = {
xtype: 'gxm_layerlist',
map: mappanel,
title: 'bar',
iconCls: 'user'
};

var myTabPanel = Ext.create('Ext.TabPanel', {
items: [mappanel, layerlist],
fullscreen: true
});

t.delay_call(1, function() {

//

var map = myTabPanel.items.get(2).olMap;

// 3 tests
// have the events been registered?
// have the events been registered?
t.eq(map.events.listeners.changelayer.length, 1,
'A changelayer eventlistener was added to the map');
t.eq(map.events.listeners.addlayer.length, 1,
'A addlayer eventlistener was added to the map');
t.eq(map.events.listeners.removelayer.length, 1,
'A removelayer eventlistener was added to the map');

if (funcToStringSupported) {

// keep this formatting due to toString() comparison
//TODO implement a better comparison
var onChangeLayerFunc = "function (evt) {\n" +
" this.refresh();\n" +
" }";
var onAddLayerFunc = "function (evt) {\n" +
" if(evt && evt.layer) {\n" +
" this.getStore().add(evt.layer);\n" +
" }\n" +
" }";
var onRemoveLayerFunc = "function (evt) {\n" +
" if(evt && evt.layer) {\n" +
" var layer = evt.layer;\n" +
" var record = this.getStore().findRecord('id', layer.id);\n" +
" this.getStore().remove(record);\n" +
" }\n" +
" }";

// 3 tests
// have the correct event listeners been registered?
t.eq(map.events.listeners.changelayer[0].func.toString(),
onChangeLayerFunc,
'The correct changelayer eventlistener was added to the map');
t.eq(map.events.listeners.addlayer[0].func.toString(), onAddLayerFunc,
'The correct addlayer eventlistener was added to the map');
t.eq(map.events.listeners.removelayer[0].func.toString(), onRemoveLayerFunc,
'The correct removelayer eventlistener was added to the map');
}


// 3 tests
// have the correct event listeners been registered?
var listeners = map.events.listeners,
proto = GXM.LayerList.prototype;
t.ok(listeners.changelayer[0].func === proto.onChangeLayer,
'The correct changelayer eventlistener was added to the map');
t.ok(listeners.addlayer[0].func === proto.onAddLayer,
'The correct addlayer eventlistener was added to the map');
t.ok(listeners.removelayer[0].func === proto.onRemoveLayer,
'The correct removelayer eventlistener was added to the map');

myTabPanel.items.get(2).destroy();

// 3 tests
t.eq(map.events.listeners.changelayer.length, 0,
'The changelayer eventlistener was removed from the map');
t.eq(map.events.listeners.addlayer.length, 0,
'The addlayer eventlistener was removed from the map');
t.eq(map.events.listeners.removelayer.length, 0,
'The removelayer eventlistener was removed from the map');

mappanel.destroy()
myTabPanel.destroy();
});
});
}


</script>
</head>
<body></body>
Expand Down