1
/* Copyright (c) 2011, Canonical Ltd. All rights reserved. */
3
YUI.add('lp.baseconfigutils.test', function(Y) {
5
var baseconfigutils_test = Y.namespace('lp.baseconfigutils.test');
7
var suite = new Y.Test.Suite('BaseConfigUtil Tests');
11
suite.add(new Y.Test.Case({
13
name: 'baseconfigutils_widget_tests',
15
tearDown: function() {
16
if (Y.Lang.isValue(this.baseconfig)) {
17
this.baseconfig.destroy();
21
_makeSrcNode: function(id) {
22
var src_node = Y.Node.create('<div></div>').set('id', id);
23
Y.one('body').appendChild(src_node);
26
test_base_config_render: function() {
27
// The div rendered should have sprite and config
28
// class names added to it.
30
this.baseconfig = new Y.lp.configutils.BaseConfigUtil({
31
srcNode: Y.one('#test-div')
33
this.baseconfig.render();
34
var config_a = Y.one('.yui3-baseconfigutil a');
35
Assert.isTrue(config_a.hasClass('sprite'));
36
Assert.isTrue(config_a.hasClass('config'));
39
test_base_config_anchor_attribute: function() {
40
// BaseConfigUtil keeps a reference to the DOM node it created.
42
this.baseconfig = new Y.lp.configutils.BaseConfigUtil({
43
srcNode: Y.one('#test-div')
45
// anchor should be null before render.
46
Assert.isNull(this.baseconfig.get('anchor'));
47
// After render, "anchor" attribute should match the node via DOM.
48
this.baseconfig.render();
49
var config_via_dom = Y.one('.yui3-baseconfigutil a');
50
Assert.areEqual(config_via_dom, this.baseconfig.get('anchor'));
53
test_base_config_click_callback: function() {
54
// _handleClick should be called when the settings
57
this.baseconfig = new Y.lp.configutils.BaseConfigUtil({
58
srcNode: Y.one('#test-div')
60
// _handleClick already exists but does nothing.
61
Assert.areSame(this.baseconfig._handleClick(), undefined);
62
var click_handled = false;
63
this.baseconfig._handleClick = function(e) {
66
this.baseconfig.render();
67
Y.one('.config').simulate('click');
68
Assert.isTrue(click_handled);
71
test_base_config_extra_render_ui: function() {
72
// BaseConfigUtil provides a hook for subclasses to do
73
// additional renderUI work.
75
this.baseconfig = new Y.lp.configutils.BaseConfigUtil({
76
srcNode: Y.one('#test-div')
78
// _extraRenderUI already exists but does nothing.
79
Assert.areSame(this.baseconfig._extraRenderUI(), undefined);
80
var href = 'http://example.com/';
81
var html = 'This is some sample text to add.';
83
this.baseconfig._extraRenderUI = function() {
84
var anchor = that.baseconfig.get('anchor');
85
anchor.set('href', href);
86
anchor.set('innerHTML', html);
88
this.baseconfig.render();
89
var anchor = this.baseconfig.get('anchor');
90
Assert.areEqual(href, anchor.get('href'));
91
Assert.areEqual(html, anchor.get('innerHTML'));
96
baseconfigutils_test.suite = suite;
98
}, '0.1', {'requires': ['test', 'node-event-simulate', 'lp.configutils']});