Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: add hidden property to polymer based components #171

Merged
merged 2 commits into from
Dec 13, 2023
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
2 changes: 1 addition & 1 deletion src/utils/createComponent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ export function createComponent<I extends HTMLElement, E extends EventNames = {}
elementClass: {
// @ts-expect-error: it is a specific workaround for Polymer classes.
name: elementClass.name,
prototype: elementClass._properties,
prototype: { ...elementClass._properties, hidden: Boolean },
},
}
: options,
Expand Down
27 changes: 26 additions & 1 deletion test/Select.spec.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import chaiDom from 'chai-dom';
import type { ReactElement } from 'react';
import { ListBox } from '../src/ListBox.js';
import { Item } from '../src/Item.js';
import { Select } from '../src/Select.js';
import { Select, SelectElement } from '../src/Select.js';
import { findByQuerySelector } from './utils/findByQuerySelector.js';

useChaiPlugin(chaiDom);
Expand Down Expand Up @@ -143,4 +143,29 @@ describe('Select', () => {
await expect(findByQuerySelector('div[slot="prefix"]')).to.eventually.have.text('Value:');
});
});

describe('boolean property', () => {
const booleanProperties: Array<keyof typeof SelectElement.prototype & string> = [
'disabled',
'hidden',
'opened',
'draggable',
];

booleanProperties.forEach((property) => {
describe(property, () => {
it(`should be true in the element if ${property} prop is true`, async () => {
render(<Select items={[{ label: 'foo', value: 'foo' }]} {...{ [property]: true }} />);
const select = await findByQuerySelector('vaadin-select');
expect(select[property]).to.be.ok;
});

it(`should be false in the element if ${property} prop is false`, async () => {
render(<Select items={[{ label: 'foo', value: 'foo' }]} {...{ [property]: false }} />);
const select = await findByQuerySelector('vaadin-select');
expect(select[property]).not.to.be.ok;
});
});
});
});
});
33 changes: 33 additions & 0 deletions test/SideNav.spec.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import { expect, use as useChaiPlugin } from '@esm-bundle/chai';
import { render } from '@testing-library/react';
import chaiDom from 'chai-dom';
import { SideNav, SideNavElement } from '../src/SideNav.js';
import { findByQuerySelector } from './utils/findByQuerySelector.js';

useChaiPlugin(chaiDom);

describe('SideNav', () => {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added tests for SideNav because it's LitElement based and behaves differently from the other, PolymerElement based components.

describe('boolean property', () => {
const booleanProperties: Array<keyof typeof SideNavElement.prototype & string> = [
'hidden',
'collapsed',
'draggable',
];

booleanProperties.forEach((property) => {
describe(property, () => {
it(`should be true in the element if ${property} prop is true`, async () => {
render(<SideNav {...{ [property]: true }} />);
const sideNav = await findByQuerySelector('vaadin-side-nav');
expect(sideNav[property]).to.be.ok;
});

it(`should be false in the element if ${property} prop is false`, async () => {
render(<SideNav {...{ [property]: false }} />);
const sideNav = await findByQuerySelector('vaadin-side-nav');
expect(sideNav[property]).not.to.be.ok;
});
});
});
});
});