+
-
@@ -41,9 +41,10 @@ test('attachTo returns an MDCChipSet instance', () => {
});
class FakeChip {
- constructor() {
+ constructor(el) {
+ this.id = el.id;
this.destroy = td.func('.destroy');
- this.isSelected = td.func('.isSelected');
+ this.selected = false;
}
}
@@ -81,24 +82,6 @@ test('#addChip adds a new chip to the chip set', () => {
assert.instanceOf(component.chips[3], FakeChip);
});
-class FakeSelectedChip {
- constructor() {
- this.foundation = td.object({
- setSelected: () => {},
- });
- this.destroy = td.func('.destroy');
- this.isSelected = () => true;
- }
-}
-
-test('#initialSyncWithDOM sets selects chips with mdc-chip--selected class', () => {
- const root = getFixture();
- const component = new MDCChipSet(root, undefined, (el) => new FakeSelectedChip(el));
- td.verify(component.foundation_.select(component.chips[0].foundation));
- td.verify(component.foundation_.select(component.chips[1].foundation));
- td.verify(component.foundation_.select(component.chips[2].foundation));
-});
-
function setupTest() {
const root = getFixture();
const component = new MDCChipSet(root);
@@ -115,7 +98,15 @@ test('#adapter.removeChip removes the chip object from the chip set', () => {
const root = getFixture();
const component = new MDCChipSet(root, undefined, (el) => new FakeChip(el));
const chip = component.chips[0];
- component.getDefaultFoundation().adapter_.removeChip(chip);
+ component.getDefaultFoundation().adapter_.removeChip(chip.id);
assert.equal(component.chips.length, 2);
td.verify(chip.destroy());
});
+
+test('#adapter.setSelected sets selected on chip object', () => {
+ const root = getFixture();
+ const component = new MDCChipSet(root, undefined, (el) => new FakeChip(el));
+ const chip = component.chips[0];
+ component.getDefaultFoundation().adapter_.setSelected(chip.id, true);
+ assert.equal(chip.selected, true);
+});
diff --git a/test/unit/mdc-chips/mdc-chip.test.js b/test/unit/mdc-chips/mdc-chip.test.js
index 9d3b0bce73d..25d40a7a5e4 100644
--- a/test/unit/mdc-chips/mdc-chip.test.js
+++ b/test/unit/mdc-chips/mdc-chip.test.js
@@ -48,6 +48,16 @@ test('get ripple returns MDCRipple instance', () => {
assert.isTrue(component.ripple instanceof MDCRipple);
});
+test('sets id on chip if attribute exists', () => {
+ const root = bel`
+
+ `;
+ const component = new MDCChip(root);
+ assert.equal(component.id, 'hello-chip');
+});
+
test('#adapter.hasClass returns true if class is set on chip set element', () => {
const {root, component} = setupTest();
root.classList.add('foo');
@@ -146,10 +156,15 @@ function setupMockFoundationTest(root = getFixture()) {
return {root, component, mockFoundation};
}
-test('#isSelected proxies to foundation', () => {
+test('#get selected proxies to foundation', () => {
+ const {component, mockFoundation} = setupMockFoundationTest();
+ assert.equal(component.selected, mockFoundation.isSelected());
+});
+
+test('#set selected proxies to foundation', () => {
const {component, mockFoundation} = setupMockFoundationTest();
- component.isSelected();
- td.verify(mockFoundation.isSelected());
+ component.selected = true;
+ td.verify(mockFoundation.setSelected(true));
});
test('#get shouldRemoveOnTrailingIconClick proxies to foundation', () => {