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

Commit b8ae66c

Browse files
author
Matty Goo
authored
fix(select): add tests for select label package (#2289)
1 parent bc13750 commit b8ae66c

File tree

4 files changed

+118
-5
lines changed

4 files changed

+118
-5
lines changed

packages/mdc-select/label/foundation.js

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ import MDCFoundation from '@material/base/foundation';
1919
import MDCSelectLabelAdapter from './adapter';
2020
import {cssClasses} from './constants';
2121

22-
2322
/**
2423
* @extends {MDCFoundation<!MDCSelectLabelAdapter>}
2524
* @final
@@ -53,8 +52,6 @@ class MDCSelectLabelFoundation extends MDCFoundation {
5352
/**
5453
* Styles the label to float or defloat as necessary.
5554
* @param {string} value The value of the input.
56-
* @param {boolean} isFocused Whether the input is focused.
57-
* @param {boolean} isBadInput The input's `validity.badInput` value.
5855
*/
5956
styleFloat(value) {
6057
const {LABEL_FLOAT_ABOVE} = MDCSelectLabelFoundation.cssClasses;

packages/mdc-select/label/index.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,10 +45,10 @@ class MDCSelectLabel extends MDCComponent {
4545
* @return {!MDCSelectLabelFoundation}
4646
*/
4747
getDefaultFoundation() {
48-
return new MDCSelectLabelFoundation(/** @type {!MDCSelectLabelAdapter} */ (Object.assign({
48+
return new MDCSelectLabelFoundation({
4949
addClass: (className) => this.root_.classList.add(className),
5050
removeClass: (className) => this.root_.classList.remove(className),
51-
})));
51+
});
5252
}
5353
}
5454

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
/**
2+
* Copyright 2016 Google Inc. All Rights Reserved.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
import {assert} from 'chai';
18+
import td from 'testdouble';
19+
20+
import {setupFoundationTest} from '../helpers/setup';
21+
import {verifyDefaultAdapter} from '../helpers/foundation';
22+
23+
import MDCSelectLabelFoundation from '../../../packages/mdc-select/label/foundation';
24+
import {cssClasses} from '../../../packages/mdc-select/label/constants';
25+
26+
function setupTest() {
27+
return setupFoundationTest(MDCSelectLabelFoundation);
28+
}
29+
30+
suite('MDCSelectLabelFoundation');
31+
32+
test('exports cssClasses', () => {
33+
assert.deepEqual(MDCSelectLabelFoundation.cssClasses, cssClasses);
34+
});
35+
36+
test('default adapter returns a complete adapter implementation', () => {
37+
verifyDefaultAdapter(MDCSelectLabelFoundation, [
38+
'addClass', 'removeClass', 'getWidth',
39+
]);
40+
});
41+
42+
test('#styleFloat should add float above class', () => {
43+
const {foundation, mockAdapter} = setupTest();
44+
foundation.styleFloat('selectedValue');
45+
td.verify(mockAdapter.addClass(cssClasses.LABEL_FLOAT_ABOVE));
46+
});
47+
48+
test('#styleFloat should remove float above class', () => {
49+
const {foundation, mockAdapter} = setupTest();
50+
foundation.styleFloat(null);
51+
td.verify(mockAdapter.removeClass(cssClasses.LABEL_FLOAT_ABOVE));
52+
});
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
/**
2+
* Copyright 2016 Google Inc. All Rights Reserved.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
import {assert} from 'chai';
18+
import bel from 'bel';
19+
import td from 'testdouble';
20+
21+
import {MDCSelectLabel} from '../../../packages/mdc-select/label';
22+
23+
function getFixture() {
24+
return bel`
25+
<div class="mdc-select__label">Label</div>
26+
`;
27+
}
28+
29+
function setupTest() {
30+
const fixture = getFixture();
31+
const component = new MDCSelectLabel(fixture);
32+
33+
return {component, fixture};
34+
}
35+
36+
suite('MDCSelectLabel');
37+
38+
test('attachTo returns a component instance', () => {
39+
assert.isTrue(MDCSelectLabel.attachTo(getFixture()) instanceof MDCSelectLabel);
40+
});
41+
42+
test('#float should call styleFloat on foundation', () => {
43+
const {component} = setupTest();
44+
const value = 'value';
45+
component.foundation_.styleFloat = td.func();
46+
component.float(value);
47+
td.verify(component.foundation_.styleFloat(value));
48+
});
49+
50+
test('adapter#addClass adds a class to the root element', () => {
51+
const {component, fixture} = setupTest();
52+
53+
component.getDefaultFoundation().adapter_.addClass('foo');
54+
assert.isTrue(fixture.classList.contains('foo'));
55+
});
56+
57+
58+
test('adapter#removeClass removes a class from the root element', () => {
59+
const {component, fixture} = setupTest();
60+
61+
fixture.classList.add('foo');
62+
component.getDefaultFoundation().adapter_.removeClass('foo');
63+
assert.isFalse(fixture.classList.contains('foo'));
64+
});

0 commit comments

Comments
 (0)