Skip to content

Commit

Permalink
fix(dialog): Expose numbers on foundation
Browse files Browse the repository at this point in the history
  • Loading branch information
Kenneth G. Franqueiro committed Aug 14, 2018
1 parent 4cc16d9 commit cea81eb
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 7 deletions.
6 changes: 5 additions & 1 deletion packages/mdc-dialog/foundation.js
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand All @@ -26,6 +26,10 @@ export default class MDCDialogFoundation extends MDCFoundation {
return strings;
}

static get numbers() {
return numbers;
}

static get defaultAdapter() {
return ({
addClass: (/* className: string */) => {},
Expand Down
23 changes: 17 additions & 6 deletions test/unit/mdc-dialog/foundation.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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', () => {
Expand Down Expand Up @@ -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', () => {
Expand Down Expand Up @@ -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', () => {
Expand Down

0 comments on commit cea81eb

Please sign in to comment.