Skip to content
This repository has been archived by the owner on Jan 13, 2025. It is now read-only.

fix(dialog): Expose numbers on foundation #3346

Merged
merged 1 commit into from
Aug 14, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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