Skip to content

Commit

Permalink
Merge pull request #76 from SAP/unit-test-cleanup
Browse files Browse the repository at this point in the history
updated unit test coverage and eslint warnings
  • Loading branch information
chrismanciero committed Nov 21, 2018
2 parents f2ca7ab + c9a5749 commit f575a9b
Show file tree
Hide file tree
Showing 14 changed files with 118 additions and 111 deletions.
2 changes: 1 addition & 1 deletion src/Identifier/Identifier.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ export const Identifier = props => {
const { glyph, size, modifier, color, label, children } = props;
return (
<span
className={`${size ? ' fd-identifier--' + size : ''}${
className={`${'fd-identifier--' + size}${
glyph ? ' sap-icon--' + glyph : ''
}${modifier ? ' fd-identifier--' + modifier : ''}${
color ? ' fd-has-background-color-accent-' + color : ''
Expand Down
2 changes: 1 addition & 1 deletion src/Identifier/Identifier.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ describe('<Identifier />', () => {
<Identifier size="m" glyph="washing-machine" modifier="circle" />
);
const transparent = (
<Identifier glyph="washing-machine" modifier="transparent" />
<Identifier glyph="washing-machine" modifier="transparent" size="m" />
);
const accentColor = <Identifier size="m" glyph="money-bills" color={9} />;

Expand Down
10 changes: 5 additions & 5 deletions src/Identifier/__snapshots__/Identifier.test.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,15 @@

exports[`<Identifier /> Create identifier 1`] = `
<span
className=" fd-identifier--s sap-icon--washing-machine"
className="fd-identifier--s sap-icon--washing-machine"
role="presentation"
/>
`;

exports[`<Identifier /> Create identifier 2`] = `
<span
aria-label="Wendy Wallace"
className=" fd-identifier--m"
className="fd-identifier--m"
role=""
>
WW
Expand All @@ -19,21 +19,21 @@ exports[`<Identifier /> Create identifier 2`] = `

exports[`<Identifier /> Create identifier 3`] = `
<span
className=" fd-identifier--m sap-icon--washing-machine fd-identifier--circle"
className="fd-identifier--m sap-icon--washing-machine fd-identifier--circle"
role="presentation"
/>
`;

exports[`<Identifier /> Create identifier 4`] = `
<span
className=" sap-icon--washing-machine fd-identifier--transparent"
className="fd-identifier--m sap-icon--washing-machine fd-identifier--transparent"
role="presentation"
/>
`;

exports[`<Identifier /> Create identifier 5`] = `
<span
className=" fd-identifier--m sap-icon--money-bills fd-has-background-color-accent-9"
className="fd-identifier--m sap-icon--money-bills fd-has-background-color-accent-9"
role="presentation"
/>
`;
4 changes: 1 addition & 3 deletions src/Image/Image.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,7 @@ export const Image = props => {
const { size, type, photo } = props;
return (
<span
className={`${size ? 'fd-image--' + size : 'm'}${
type ? ' fd-image--' + type : ''
}`}
className={`${'fd-image--' + size}${type ? ' fd-image--' + type : ''}`}
style={{ backgroundImage: 'url(' + photo + ')' }}
/>
);
Expand Down
2 changes: 1 addition & 1 deletion src/Image/Image.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ Enzyme.configure({ adapter: new Adapter() });
describe('<Image />', () => {
const image = <Image size="s" photo="https://placeimg.com/400/400/nature" />;
const circleImage = (
<Image type="circle" photo="https://placeimg.com/400/400/nature" />
<Image type="circle" size="m" photo="https://placeimg.com/400/400/nature" />
);
test('create image', () => {
let component = renderer.create(image);
Expand Down
2 changes: 1 addition & 1 deletion src/Image/__snapshots__/Image.test.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ exports[`<Image /> create image 1`] = `

exports[`<Image /> create image 2`] = `
<span
className="m fd-image--circle"
className="fd-image--m fd-image--circle"
style={
Object {
"backgroundImage": "url(https://placeimg.com/400/400/nature)",
Expand Down
2 changes: 1 addition & 1 deletion src/ListGroup/ListGroup.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ describe('<ListGroup />', () => {
<ListGroupItem>
List item 1
<ListGroupItemActions>
<Button type="light" glyph="edit" />
<Button type="standard" glyph="edit" />
</ListGroupItemActions>
</ListGroupItem>
</ListGroup>
Expand Down
2 changes: 1 addition & 1 deletion src/ListGroup/__snapshots__/ListGroup.test.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ exports[`<ListGroup /> create list group 2`] = `
className="fd-list-group__action"
>
<button
className=" fd-button fd-button--light sap-icon--edit"
className=" fd-button fd-button--standard sap-icon--edit"
disabled={false}
selected={false}
/>
Expand Down
2 changes: 1 addition & 1 deletion src/Navbar/__snapshots__/Navbar.test.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ exports[`<Navbar /> create navbar 1`] = `
selected={false}
>
<span
className=" fd-identifier--s fd-identifier--circle"
className="fd-identifier--s fd-identifier--circle"
role=""
>
WW
Expand Down
157 changes: 78 additions & 79 deletions src/Popover/Popover.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,95 +3,94 @@ import PropTypes from 'prop-types';

// ---------------------------------------- Popover ----------------------------------------
export class Popover extends Component {
constructor(props) {
super(props);
this.triggerBody = this.triggerBody.bind(this);
this.pressEsc = this.pressEsc.bind(this);
this.handleOutsideClick = this.handleOutsideClick.bind(this);
this.state = {
isExpanded: false,
isDisabled: this.props.disabled
};
}
constructor(props) {
super(props);
this.triggerBody = this.triggerBody.bind(this);
this.pressEsc = this.pressEsc.bind(this);
this.handleOutsideClick = this.handleOutsideClick.bind(this);
this.state = {
isExpanded: false,
isDisabled: this.props.disabled
};
}

triggerBody() {
if (!this.state.isDisabled) {
if (!this.state.isExpanded) {
document.addEventListener('click', this.handleOutsideClick, false);
} else {
document.removeEventListener('click', this.handleOutsideClick, false);
}
triggerBody() {
if (!this.state.isDisabled) {
if (!this.state.isExpanded) {
document.addEventListener('click', this.handleOutsideClick, false);
} else {
document.removeEventListener('click', this.handleOutsideClick, false);
}

this.setState(prevState => ({
isExpanded: !prevState.isExpanded
}));
}
this.setState(prevState => ({
isExpanded: !prevState.isExpanded
}));
}
}

pressEsc(event) {
if (event.keyCode === 27 && this.state.isExpanded === true) {
this.setState({
isExpanded: false
});
}
pressEsc(event) {
if (event.keyCode === 27 && this.state.isExpanded === true) {
this.setState({
isExpanded: false
});
}
}

handleOutsideClick(e) {
if (!this.node.contains(e.target)) {
if (this.state.isExpanded) {
this.setState({
isExpanded: false
});
} else {
return;
}
}
handleOutsideClick(e) {
if (this.node && !this.node.contains(e.target)) {
if (this.state.isExpanded) {
this.setState({
isExpanded: false
});
} else {
return;
}
}
}

componentDidMount() {
document.addEventListener('keydown', this.pressEsc, false);
document.addEventListener('click', this.handleOutsideClick, false);
}
componentWillUnmount() {
document.removeEventListener('keydown', this.pressEsc, false);
document.removeEventListener('click', this.handleOutsideClick, false);
}
componentDidMount() {
document.addEventListener('keydown', this.pressEsc, false);
document.addEventListener('click', this.handleOutsideClick, false);
}
componentWillUnmount() {
document.removeEventListener('keydown', this.pressEsc, false);
document.removeEventListener('click', this.handleOutsideClick, false);
}

render() {
const { id, alignment, noArrow, control, body } = this.props;
return (
<div
className={`fd-popover${alignment ? ' fd-popover--' + alignment : ''}`}
ref={this.setWrapperRef}
ref={node => {
this.node = node;
}}
>
<div
className="fd-popover__control"
aria-expanded={this.state.isExpanded}
onClick={this.triggerBody}
aria-controls={id}
>
{control}
</div>
<div
className={`fd-popover__body${alignment ? ' fd-popover__body--' + alignment : ''}${
noArrow ? ' fd-popover__body--no-arrow' : ''
}`}
aria-hidden={!this.state.isExpanded}
id={id}
>
{body}
</div>
</div>
);
}
render() {
const { id, alignment, noArrow, control, body } = this.props;
return (
<div
className={`fd-popover${alignment ? ' fd-popover--' + alignment : ''}`}
ref={node => {
this.node = node;
}}
>
<div
className="fd-popover__control"
aria-expanded={this.state.isExpanded}
onClick={this.triggerBody}
aria-controls={id}
>
{control}
</div>
<div
className={`fd-popover__body${
alignment ? ' fd-popover__body--' + alignment : ''
}${noArrow ? ' fd-popover__body--no-arrow' : ''}`}
aria-hidden={!this.state.isExpanded}
id={id}
>
{body}
</div>
</div>
);
}
}

Popover.propTypes = {
id: PropTypes.string,
alignment: PropTypes.oneOf(['', 'right']),
noArrow: PropTypes.bool,
disabled: PropTypes.bool
id: PropTypes.string,
alignment: PropTypes.oneOf(['', 'right']),
noArrow: PropTypes.bool,
disabled: PropTypes.bool
};
34 changes: 22 additions & 12 deletions src/Popover/Popover.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -125,16 +125,26 @@ describe('<Popover />', () => {
expect(wrapper.state('isExpanded')).toBeFalsy();
});

// test('handle document click to close popover', () => {
// const wrapper = mount(popOver);

// // click on popover to show
// wrapper.find('div.fd-popover__control').simulate('click');
// expect(wrapper.state('isExpanded')).toBeTruthy();

// // handle click on document
// let event = new MouseEvent('click', { target: 'h' });
// document.dispatchEvent(event);
// expect(wrapper.state('isExpanded')).toBeFalsy();
// });
test('handle document click to close popover', () => {
const wrapper = mount(popOver);

// click on popover to show
wrapper.find('div.fd-popover__control').simulate('click');
expect(wrapper.state('isExpanded')).toBeTruthy();

// handle click on document
let event = new MouseEvent('click', {
target: document.querySelector('body')
});
document.dispatchEvent(event);
expect(wrapper.state('isExpanded')).toBeFalsy();
});

test('handle document click to close popover', () => {
const wrapper = mount(popOverDisabled);

// click on popover to show
wrapper.find('div.fd-popover__control').simulate('click');
expect(wrapper.state('isExpanded')).toBeFalsy();
});
});
4 changes: 2 additions & 2 deletions src/Tabs/Tabs.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,11 @@ export class TabComponent extends Component {
super(props);
let initialStates = [];

props.ids.forEach(ids => {
initialStates = props.ids.forEach(ids => {
let obj = {};
let id = ids.id;
obj[id] = false;
initialStates.push(obj);
return obj;
});
this.state = {
selectedTab: '1',
Expand Down
2 changes: 1 addition & 1 deletion src/Tile/Tile.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ describe('<Tile />', () => {
<TileContent title="Tile Title" />
<TileActions>
<Popover
control={<Button type="secondary" glyph="vertical-grip" />}
control={<Button type="standard" glyph="vertical-grip" />}
body={
<Menu>
<MenuList>
Expand Down
4 changes: 2 additions & 2 deletions src/Tile/__snapshots__/Tile.test.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ exports[`<Tile /> create tile component 3`] = `
className="fd-tile__media"
>
<span
className=" fd-identifier--m sap-icon--home fd-has-background-color-accent-3"
className="fd-identifier--m sap-icon--home fd-has-background-color-accent-3"
role="presentation"
/>
</div>
Expand Down Expand Up @@ -94,7 +94,7 @@ exports[`<Tile /> create tile component 4`] = `
onClick={[Function]}
>
<button
className=" fd-button fd-button--secondary sap-icon--vertical-grip"
className=" fd-button fd-button--standard sap-icon--vertical-grip"
disabled={false}
selected={false}
/>
Expand Down

0 comments on commit f575a9b

Please sign in to comment.