-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(select): add tests for select label package (#2289)
- Loading branch information
Matty Goo
authored
Feb 22, 2018
1 parent
bc13750
commit b8ae66c
Showing
4 changed files
with
118 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
/** | ||
* Copyright 2016 Google Inc. All Rights Reserved. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
import {assert} from 'chai'; | ||
import td from 'testdouble'; | ||
|
||
import {setupFoundationTest} from '../helpers/setup'; | ||
import {verifyDefaultAdapter} from '../helpers/foundation'; | ||
|
||
import MDCSelectLabelFoundation from '../../../packages/mdc-select/label/foundation'; | ||
import {cssClasses} from '../../../packages/mdc-select/label/constants'; | ||
|
||
function setupTest() { | ||
return setupFoundationTest(MDCSelectLabelFoundation); | ||
} | ||
|
||
suite('MDCSelectLabelFoundation'); | ||
|
||
test('exports cssClasses', () => { | ||
assert.deepEqual(MDCSelectLabelFoundation.cssClasses, cssClasses); | ||
}); | ||
|
||
test('default adapter returns a complete adapter implementation', () => { | ||
verifyDefaultAdapter(MDCSelectLabelFoundation, [ | ||
'addClass', 'removeClass', 'getWidth', | ||
]); | ||
}); | ||
|
||
test('#styleFloat should add float above class', () => { | ||
const {foundation, mockAdapter} = setupTest(); | ||
foundation.styleFloat('selectedValue'); | ||
td.verify(mockAdapter.addClass(cssClasses.LABEL_FLOAT_ABOVE)); | ||
}); | ||
|
||
test('#styleFloat should remove float above class', () => { | ||
const {foundation, mockAdapter} = setupTest(); | ||
foundation.styleFloat(null); | ||
td.verify(mockAdapter.removeClass(cssClasses.LABEL_FLOAT_ABOVE)); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
/** | ||
* Copyright 2016 Google Inc. All Rights Reserved. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
import {assert} from 'chai'; | ||
import bel from 'bel'; | ||
import td from 'testdouble'; | ||
|
||
import {MDCSelectLabel} from '../../../packages/mdc-select/label'; | ||
|
||
function getFixture() { | ||
return bel` | ||
<div class="mdc-select__label">Label</div> | ||
`; | ||
} | ||
|
||
function setupTest() { | ||
const fixture = getFixture(); | ||
const component = new MDCSelectLabel(fixture); | ||
|
||
return {component, fixture}; | ||
} | ||
|
||
suite('MDCSelectLabel'); | ||
|
||
test('attachTo returns a component instance', () => { | ||
assert.isTrue(MDCSelectLabel.attachTo(getFixture()) instanceof MDCSelectLabel); | ||
}); | ||
|
||
test('#float should call styleFloat on foundation', () => { | ||
const {component} = setupTest(); | ||
const value = 'value'; | ||
component.foundation_.styleFloat = td.func(); | ||
component.float(value); | ||
td.verify(component.foundation_.styleFloat(value)); | ||
}); | ||
|
||
test('adapter#addClass adds a class to the root element', () => { | ||
const {component, fixture} = setupTest(); | ||
|
||
component.getDefaultFoundation().adapter_.addClass('foo'); | ||
assert.isTrue(fixture.classList.contains('foo')); | ||
}); | ||
|
||
|
||
test('adapter#removeClass removes a class from the root element', () => { | ||
const {component, fixture} = setupTest(); | ||
|
||
fixture.classList.add('foo'); | ||
component.getDefaultFoundation().adapter_.removeClass('foo'); | ||
assert.isFalse(fixture.classList.contains('foo')); | ||
}); |