Skip to content

Commit

Permalink
fix(floating-label): achieved 100% test coverage (#2523)
Browse files Browse the repository at this point in the history
  • Loading branch information
Matty Goo authored Apr 6, 2018
1 parent 4876cf2 commit 2e7f904
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
import {assert} from 'chai';
import td from 'testdouble';

import {verifyDefaultAdapter} from '../helpers/foundation';
import {captureHandlers, verifyDefaultAdapter} from '../helpers/foundation';
import {setupFoundationTest} from '../helpers/setup';
import MDCFloatingLabelFoundation from '../../../packages/mdc-floating-label/foundation';

Expand Down Expand Up @@ -92,3 +92,11 @@ test('#handleShakeAnimationEnd_ should remove LABEL_SHAKE class', () => {
foundation.handleShakeAnimationEnd_();
td.verify(mockAdapter.removeClass(cssClasses.LABEL_SHAKE));
});

test(`on animationend removes ${cssClasses.LABEL_SHAKE} class`, () => {
const {foundation, mockAdapter} = setupFoundationTest(MDCFloatingLabelFoundation);
const handlers = captureHandlers(mockAdapter, 'registerInteractionHandler');
foundation.init();
handlers.animationend();
td.verify(mockAdapter.removeClass(cssClasses.LABEL_SHAKE));
});
22 changes: 22 additions & 0 deletions test/unit/mdc-floating-label/mdc-floating-label.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
*/

import bel from 'bel';
import td from 'testdouble';
import {assert} from 'chai';

import {MDCFloatingLabel} from '../../../packages/mdc-floating-label/index';
Expand All @@ -35,6 +36,27 @@ function setupTest() {
return {root, component};
}

test('#shake calls the foundation shake method', () => {
const {component} = setupTest();
component.foundation_.shake = td.func();
component.shake(true);
td.verify(component.foundation_.shake(true), {times: 1});
});

test('#getWidth calls the foundation getWidth method', () => {
const {component} = setupTest();
component.foundation_.getWidth = td.func();
component.getWidth();
td.verify(component.foundation_.getWidth(), {times: 1});
});

test('#float calls the foundation float method', () => {
const {component} = setupTest();
component.foundation_.float = td.func();
component.float(true);
td.verify(component.foundation_.float(true), {times: 1});
});

test('#adapter.addClass adds a class to the element', () => {
const {root, component} = setupTest();
component.getDefaultFoundation().adapter_.addClass('foo');
Expand Down

0 comments on commit 2e7f904

Please sign in to comment.