624675c154cbb5186e8c760b853ca79835987c9eEric FerraiuoloYUI.add('widget-stdmod-test', function (Y) {
624675c154cbb5186e8c760b853ca79835987c9eEric Ferraiuolo
624675c154cbb5186e8c760b853ca79835987c9eEric Ferraiuolovar Assert = Y.Assert,
624675c154cbb5186e8c760b853ca79835987c9eEric Ferraiuolo ArrayAssert = Y.ArrayAssert,
624675c154cbb5186e8c760b853ca79835987c9eEric Ferraiuolo
f386d69afd040f61944cff1eaad6cf615c147a6dEric Ferraiuolo suite, TestWidget;
624675c154cbb5186e8c760b853ca79835987c9eEric Ferraiuolo
624675c154cbb5186e8c760b853ca79835987c9eEric Ferraiuolo// -- Suite --------------------------------------------------------------------
624675c154cbb5186e8c760b853ca79835987c9eEric Ferraiuolosuite = new Y.Test.Suite('WidgetStdMod');
624675c154cbb5186e8c760b853ca79835987c9eEric FerraiuoloTestWidget = Y.Base.create('testWidget', Y.Widget, [Y.WidgetStdMod]);
624675c154cbb5186e8c760b853ca79835987c9eEric Ferraiuolo
624675c154cbb5186e8c760b853ca79835987c9eEric Ferraiuolo// -- Lifecycle ----------------------------------------------------------------
624675c154cbb5186e8c760b853ca79835987c9eEric Ferraiuolosuite.add(new Y.Test.Case({
624675c154cbb5186e8c760b853ca79835987c9eEric Ferraiuolo name: 'Lifecycle',
624675c154cbb5186e8c760b853ca79835987c9eEric Ferraiuolo
624675c154cbb5186e8c760b853ca79835987c9eEric Ferraiuolo tearDown: function () {
624675c154cbb5186e8c760b853ca79835987c9eEric Ferraiuolo this.widget && this.widget.destroy();
624675c154cbb5186e8c760b853ca79835987c9eEric Ferraiuolo delete this.widget;
624675c154cbb5186e8c760b853ca79835987c9eEric Ferraiuolo Y.one('#test').empty();
624675c154cbb5186e8c760b853ca79835987c9eEric Ferraiuolo },
624675c154cbb5186e8c760b853ca79835987c9eEric Ferraiuolo
039c1e71e8a73e299b06634cb4a9897393179cf2Eric Ferraiuolo 'WidgetStdMod should add `headerContent`, `bodyContent`, `footerContent`, and `fillHeight` attributes': function () {
039c1e71e8a73e299b06634cb4a9897393179cf2Eric Ferraiuolo this.widget = new TestWidget({
039c1e71e8a73e299b06634cb4a9897393179cf2Eric Ferraiuolo headerContent: 'foo',
039c1e71e8a73e299b06634cb4a9897393179cf2Eric Ferraiuolo bodyContent : 'bar',
039c1e71e8a73e299b06634cb4a9897393179cf2Eric Ferraiuolo footerContent: 'baz',
039c1e71e8a73e299b06634cb4a9897393179cf2Eric Ferraiuolo render : '#test'
039c1e71e8a73e299b06634cb4a9897393179cf2Eric Ferraiuolo });
039c1e71e8a73e299b06634cb4a9897393179cf2Eric Ferraiuolo
039c1e71e8a73e299b06634cb4a9897393179cf2Eric Ferraiuolo Assert.areSame('foo', this.widget.get('headerContent').item(0).get('text'), '`headerContent` is not "foo".');
039c1e71e8a73e299b06634cb4a9897393179cf2Eric Ferraiuolo Assert.areSame('bar', this.widget.get('bodyContent').item(0).get('text'), '`bodyContent` is not "bar".');
039c1e71e8a73e299b06634cb4a9897393179cf2Eric Ferraiuolo Assert.areSame('baz', this.widget.get('footerContent').item(0).get('text'), '`footerContent` is not "baz".');
624675c154cbb5186e8c760b853ca79835987c9eEric Ferraiuolo Assert.areSame('body', this.widget.get('fillHeight'), '`fillHeight` is not "body".');
624675c154cbb5186e8c760b853ca79835987c9eEric Ferraiuolo }
624675c154cbb5186e8c760b853ca79835987c9eEric Ferraiuolo}));
624675c154cbb5186e8c760b853ca79835987c9eEric Ferraiuolo
f386d69afd040f61944cff1eaad6cf615c147a6dEric Ferraiuolo// -- Methods ------------------------------------------------------------------
f386d69afd040f61944cff1eaad6cf615c147a6dEric Ferraiuolosuite.add(new Y.Test.Case({
f386d69afd040f61944cff1eaad6cf615c147a6dEric Ferraiuolo name: 'Methods',
f386d69afd040f61944cff1eaad6cf615c147a6dEric Ferraiuolo
f386d69afd040f61944cff1eaad6cf615c147a6dEric Ferraiuolo tearDown: function () {
f386d69afd040f61944cff1eaad6cf615c147a6dEric Ferraiuolo this.widget && this.widget.destroy();
f386d69afd040f61944cff1eaad6cf615c147a6dEric Ferraiuolo delete this.widget;
f386d69afd040f61944cff1eaad6cf615c147a6dEric Ferraiuolo Y.one('#test').empty();
f386d69afd040f61944cff1eaad6cf615c147a6dEric Ferraiuolo },
f386d69afd040f61944cff1eaad6cf615c147a6dEric Ferraiuolo
f386d69afd040f61944cff1eaad6cf615c147a6dEric Ferraiuolo 'getStdModNode() should return the section node if there is content': function () {
f386d69afd040f61944cff1eaad6cf615c147a6dEric Ferraiuolo this.widget = new TestWidget({render: '#test'});
f386d69afd040f61944cff1eaad6cf615c147a6dEric Ferraiuolo
f386d69afd040f61944cff1eaad6cf615c147a6dEric Ferraiuolo Assert.isNull(this.widget.getStdModNode('header'), 'Header node was not null.');
f386d69afd040f61944cff1eaad6cf615c147a6dEric Ferraiuolo
f386d69afd040f61944cff1eaad6cf615c147a6dEric Ferraiuolo this.widget.set('headerContent', 'foo');
f386d69afd040f61944cff1eaad6cf615c147a6dEric Ferraiuolo
f386d69afd040f61944cff1eaad6cf615c147a6dEric Ferraiuolo Assert.isNotNull(this.widget.getStdModNode('header'), 'Header node was null.');
f386d69afd040f61944cff1eaad6cf615c147a6dEric Ferraiuolo },
f386d69afd040f61944cff1eaad6cf615c147a6dEric Ferraiuolo
f386d69afd040f61944cff1eaad6cf615c147a6dEric Ferraiuolo 'getStdModNode() should create the section node when `forceCreate` is truthy': function () {
f386d69afd040f61944cff1eaad6cf615c147a6dEric Ferraiuolo this.widget = new TestWidget({render: '#test'});
f386d69afd040f61944cff1eaad6cf615c147a6dEric Ferraiuolo
f386d69afd040f61944cff1eaad6cf615c147a6dEric Ferraiuolo Assert.isNull(this.widget.getStdModNode('header'), 'Header node was not null.');
f386d69afd040f61944cff1eaad6cf615c147a6dEric Ferraiuolo Assert.isNotNull(this.widget.getStdModNode('header', true), 'Header node was null.');
039c1e71e8a73e299b06634cb4a9897393179cf2Eric Ferraiuolo },
039c1e71e8a73e299b06634cb4a9897393179cf2Eric Ferraiuolo
039c1e71e8a73e299b06634cb4a9897393179cf2Eric Ferraiuolo 'fillHeight() should fill the a widget height using the provided node': function () {
039c1e71e8a73e299b06634cb4a9897393179cf2Eric Ferraiuolo var bb, header;
039c1e71e8a73e299b06634cb4a9897393179cf2Eric Ferraiuolo
039c1e71e8a73e299b06634cb4a9897393179cf2Eric Ferraiuolo this.widget = new TestWidget({
039c1e71e8a73e299b06634cb4a9897393179cf2Eric Ferraiuolo headerContent: 'foo',
039c1e71e8a73e299b06634cb4a9897393179cf2Eric Ferraiuolo height : 200,
039c1e71e8a73e299b06634cb4a9897393179cf2Eric Ferraiuolo render : '#test'
039c1e71e8a73e299b06634cb4a9897393179cf2Eric Ferraiuolo });
039c1e71e8a73e299b06634cb4a9897393179cf2Eric Ferraiuolo
039c1e71e8a73e299b06634cb4a9897393179cf2Eric Ferraiuolo bb = this.widget.get('boundingBox');
039c1e71e8a73e299b06634cb4a9897393179cf2Eric Ferraiuolo header = this.widget.getStdModNode('header');
039c1e71e8a73e299b06634cb4a9897393179cf2Eric Ferraiuolo
039c1e71e8a73e299b06634cb4a9897393179cf2Eric Ferraiuolo Assert.areSame('200px', bb.getStyle('height'), 'widget is not 200px in height.');
039c1e71e8a73e299b06634cb4a9897393179cf2Eric Ferraiuolo Assert.areNotSame('200px', header.getStyle('height'), 'header is 200px in height.');
039c1e71e8a73e299b06634cb4a9897393179cf2Eric Ferraiuolo
039c1e71e8a73e299b06634cb4a9897393179cf2Eric Ferraiuolo this.widget.fillHeight(header);
039c1e71e8a73e299b06634cb4a9897393179cf2Eric Ferraiuolo
039c1e71e8a73e299b06634cb4a9897393179cf2Eric Ferraiuolo Assert.areSame('200px', bb.getStyle('height'), 'widget is not 200px in height.');
039c1e71e8a73e299b06634cb4a9897393179cf2Eric Ferraiuolo Assert.areSame('200px', header.getStyle('height'), 'header is not 200px in height.');
f386d69afd040f61944cff1eaad6cf615c147a6dEric Ferraiuolo }
f386d69afd040f61944cff1eaad6cf615c147a6dEric Ferraiuolo}));
f386d69afd040f61944cff1eaad6cf615c147a6dEric Ferraiuolo
624675c154cbb5186e8c760b853ca79835987c9eEric FerraiuoloY.Test.Runner.add(suite);
624675c154cbb5186e8c760b853ca79835987c9eEric Ferraiuolo
624675c154cbb5186e8c760b853ca79835987c9eEric Ferraiuolo}, '@VERSION@', {
624675c154cbb5186e8c760b853ca79835987c9eEric Ferraiuolo requires: ['widget-stdmod', 'test']
624675c154cbb5186e8c760b853ca79835987c9eEric Ferraiuolo});