From cea81eb80ccd2c714c9a591d47ccccf232eb3f30 Mon Sep 17 00:00:00 2001 From: "Kenneth G. Franqueiro" Date: Tue, 14 Aug 2018 10:34:14 -0400 Subject: [PATCH] fix(dialog): Expose numbers on foundation --- packages/mdc-dialog/foundation.js | 6 +++++- test/unit/mdc-dialog/foundation.test.js | 23 +++++++++++++++++------ 2 files changed, 22 insertions(+), 7 deletions(-) diff --git a/packages/mdc-dialog/foundation.js b/packages/mdc-dialog/foundation.js index 665c5cafd55..7f3b569c2d0 100644 --- a/packages/mdc-dialog/foundation.js +++ b/packages/mdc-dialog/foundation.js @@ -15,7 +15,7 @@ */ import {MDCFoundation} from '@material/base/index'; -import {cssClasses, strings} from './constants'; +import {cssClasses, strings, numbers} from './constants'; export default class MDCDialogFoundation extends MDCFoundation { static get cssClasses() { @@ -26,6 +26,10 @@ export default class MDCDialogFoundation extends MDCFoundation { return strings; } + static get numbers() { + return numbers; + } + static get defaultAdapter() { return ({ addClass: (/* className: string */) => {}, diff --git a/test/unit/mdc-dialog/foundation.test.js b/test/unit/mdc-dialog/foundation.test.js index 86f9fb76751..7a4041295e5 100644 --- a/test/unit/mdc-dialog/foundation.test.js +++ b/test/unit/mdc-dialog/foundation.test.js @@ -20,17 +20,21 @@ import lolex from 'lolex'; import {setupFoundationTest} from '../helpers/setup'; import {verifyDefaultAdapter, captureHandlers} from '../helpers/foundation'; -import {cssClasses} from '../../../packages/mdc-dialog/constants'; +import {cssClasses, strings, numbers} from '../../../packages/mdc-dialog/constants'; import MDCDialogFoundation from '../../../packages/mdc-dialog/foundation'; suite('MDCDialogFoundation'); test('exports cssClasses', () => { - assert.isTrue('cssClasses' in MDCDialogFoundation); + assert.deepEqual(MDCDialogFoundation.cssClasses, cssClasses); }); test('exports strings', () => { - assert.isTrue('strings' in MDCDialogFoundation); + assert.deepEqual(MDCDialogFoundation.strings, strings); +}); + +test('exports numbers', () => { + assert.deepEqual(MDCDialogFoundation.numbers, numbers); }); test('default adapter returns a complete adapter implementation', () => { @@ -110,12 +114,17 @@ test('#close removes the open class to hide the dialog', () => { td.verify(mockAdapter.removeClass(cssClasses.OPEN)); }); -test('#open adds the animation class to start an animation', () => { +test('#open adds the animation class to start an animation, and removes it after the animation is done', () => { const {foundation, mockAdapter} = setupTest(); + const clock = lolex.install(); foundation.open(); - td.verify(mockAdapter.addClass(cssClasses.ANIMATING)); + + clock.tick(numbers.DIALOG_ANIMATION_TIME_MS); + td.verify(mockAdapter.removeClass(cssClasses.ANIMATING)); + + clock.uninstall(); }); test('#open adds scroll lock class to the body', () => { @@ -143,9 +152,11 @@ test('#open activates focus trapping on the dialog surface', () => { td.when(mockAdapter.isDialog(td.matchers.isA(Object))).thenReturn(true); foundation.open(); - clock.tick(MDCDialogFoundation.numbers.DIALOG_ANIMATION_TIME_MS); + clock.tick(numbers.DIALOG_ANIMATION_TIME_MS); td.verify(mockAdapter.trapFocusOnSurface()); + + clock.uninstall(); }); test('#close deactivates focus trapping on the dialog surface', () => {