123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191 |
- // Copyright 2011 The Closure Library Authors. All Rights Reserved.
- //
- // Licensed under the Apache License, Version 2.0 (the "License");
- // you may not use this file except in compliance with the License.
- // You may obtain a copy of the License at
- //
- // http://www.apache.org/licenses/LICENSE-2.0
- //
- // Unless required by applicable law or agreed to in writing, software
- // distributed under the License is distributed on an "AS-IS" BASIS,
- // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- // See the License for the specific language governing permissions and
- // limitations under the License.
- goog.provide('goog.ui.AnimatedZippyTest');
- goog.setTestOnly('goog.ui.AnimatedZippyTest');
- goog.require('goog.a11y.aria');
- goog.require('goog.a11y.aria.State');
- goog.require('goog.asserts');
- goog.require('goog.dom');
- goog.require('goog.events');
- goog.require('goog.functions');
- goog.require('goog.fx.Animation');
- goog.require('goog.fx.Transition');
- goog.require('goog.testing.PropertyReplacer');
- goog.require('goog.testing.asserts');
- goog.require('goog.testing.jsunit');
- goog.require('goog.ui.AnimatedZippy');
- goog.require('goog.ui.Zippy');
- var animatedZippy;
- var animatedZippyHeaderEl;
- var propertyReplacer;
- function setUp() {
- animatedZippyHeaderEl = goog.dom.getElement('t1');
- goog.asserts.assert(animatedZippyHeaderEl);
- animatedZippy = new goog.ui.AnimatedZippy(
- animatedZippyHeaderEl, goog.dom.getElement('c1'));
- propertyReplacer = new goog.testing.PropertyReplacer();
- }
- function tearDown() {
- propertyReplacer.reset();
- animatedZippy.dispose();
- }
- function testConstructor() {
- assertNotNull('must not be null', animatedZippy);
- }
- function testExpandCollapse() {
- var animationsPlayed = 0;
- var toggleEventsFired = 0;
- propertyReplacer.replace(goog.fx.Animation.prototype, 'play', function() {
- animationsPlayed++;
- this.dispatchAnimationEvent(goog.fx.Transition.EventType.END);
- });
- propertyReplacer.replace(
- goog.ui.AnimatedZippy.prototype, 'onAnimate_', goog.functions.NULL);
- goog.events.listenOnce(
- animatedZippy, goog.ui.Zippy.Events.TOGGLE, function(e) {
- toggleEventsFired++;
- assertTrue('TOGGLE event must be for expansion', e.expanded);
- assertEquals('expanded must be true', true, animatedZippy.isExpanded());
- assertEquals(
- 'aria-expanded must be true', 'true',
- goog.a11y.aria.getState(
- animatedZippyHeaderEl, goog.a11y.aria.State.EXPANDED));
- });
- animatedZippy.expand();
- goog.events.listenOnce(
- animatedZippy, goog.ui.Zippy.Events.TOGGLE, function(e) {
- toggleEventsFired++;
- assertFalse('TOGGLE event must be for collapse', e.expanded);
- assertEquals(
- 'expanded must be false', false, animatedZippy.isExpanded());
- assertEquals(
- 'aria-expanded must be false', 'false',
- goog.a11y.aria.getState(
- animatedZippyHeaderEl, goog.a11y.aria.State.EXPANDED));
- });
- animatedZippy.collapse();
- assertEquals('animations must play', 2, animationsPlayed);
- assertEquals('TOGGLE events must fire', 2, toggleEventsFired);
- }
- /** Tests the TOGGLE_ANIMATION_BEGIN event. */
- function testToggleBegin() {
- var animationsPlayed = 0;
- var toggleEventsFired = 0;
- propertyReplacer.replace(goog.fx.Animation.prototype, 'play', function() {
- animationsPlayed++;
- this.dispatchAnimationEvent(goog.fx.Transition.EventType.BEGIN);
- this.dispatchAnimationEvent(goog.fx.Transition.EventType.END);
- });
- propertyReplacer.replace(
- goog.ui.AnimatedZippy.prototype, 'onAnimate_', goog.functions.NULL);
- goog.events.listenOnce(
- animatedZippy, goog.ui.AnimatedZippy.Events.TOGGLE_ANIMATION_BEGIN,
- function(e) {
- toggleEventsFired++;
- assertTrue(
- 'TOGGLE_ANIMATION_BEGIN event must be for expansion', e.expanded);
- assertEquals(
- 'expanded must be false', false, animatedZippy.isExpanded());
- assertEquals(
- 'aria-expanded must be true', 'true',
- goog.a11y.aria.getState(
- animatedZippyHeaderEl, goog.a11y.aria.State.EXPANDED));
- });
- animatedZippy.expand();
- goog.events.listenOnce(
- animatedZippy, goog.ui.AnimatedZippy.Events.TOGGLE_ANIMATION_BEGIN,
- function(e) {
- toggleEventsFired++;
- assertFalse(
- 'TOGGLE_ANIMATION_BEGIN event must be for collapse', e.expanded);
- assertEquals('expanded must be true', true, animatedZippy.isExpanded());
- assertEquals(
- 'aria-expanded must be false', 'false',
- goog.a11y.aria.getState(
- animatedZippyHeaderEl, goog.a11y.aria.State.EXPANDED));
- });
- animatedZippy.collapse();
- assertEquals('animations must play', 2, animationsPlayed);
- assertEquals('TOGGLE_ANIMATION_BEGIN events must fire', 2, toggleEventsFired);
- }
- /** Tests the TOGGLE_ANIMATION_END event. */
- function testToggleEnd() {
- var animationsPlayed = 0;
- var toggleEventsFired = 0;
- propertyReplacer.replace(goog.fx.Animation.prototype, 'play', function() {
- animationsPlayed++;
- this.dispatchAnimationEvent(goog.fx.Transition.EventType.END);
- });
- propertyReplacer.replace(
- goog.ui.AnimatedZippy.prototype, 'onAnimate_', goog.functions.NULL);
- goog.events.listenOnce(
- animatedZippy, goog.ui.AnimatedZippy.Events.TOGGLE_ANIMATION_END,
- function(e) {
- toggleEventsFired++;
- assertTrue(
- 'TOGGLE_ANIMATION_END event must be for expansion', e.expanded);
- assertEquals('expanded must be true', true, animatedZippy.isExpanded());
- assertEquals(
- 'aria-expanded must be true', 'true',
- goog.a11y.aria.getState(
- animatedZippyHeaderEl, goog.a11y.aria.State.EXPANDED));
- });
- animatedZippy.expand();
- goog.events.listenOnce(
- animatedZippy, goog.ui.AnimatedZippy.Events.TOGGLE_ANIMATION_END,
- function(e) {
- toggleEventsFired++;
- assertFalse(
- 'TOGGLE_ANIMATION_END event must be for collapse', e.expanded);
- assertEquals(
- 'expanded must be false', false, animatedZippy.isExpanded());
- assertEquals(
- 'aria-expanded must be false', 'false',
- goog.a11y.aria.getState(
- animatedZippyHeaderEl, goog.a11y.aria.State.EXPANDED));
- });
- animatedZippy.collapse();
- assertEquals('animations must play', 2, animationsPlayed);
- assertEquals('TOGGLE_ANIMATION_END events must fire', 2, toggleEventsFired);
- }
|