fix some tests
fix merge issues
This commit is contained in:
@@ -1,35 +0,0 @@
|
||||
import React from 'react';
|
||||
|
||||
import styles from './Tag.module.css';
|
||||
import CategoryPage from '../../pages/CategoryPage/CategoryPage';
|
||||
import GlobalInfos from '../../utils/GlobalInfos';
|
||||
|
||||
/**
|
||||
* A Component representing a single Category tag
|
||||
*/
|
||||
class Tag extends React.Component {
|
||||
render() {
|
||||
return (
|
||||
<button className={styles.tagbtn} onClick={() => this.TagClick()}
|
||||
data-testid='Test-Tag'>{this.props.children}</button>
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* click handling for a Tag
|
||||
*/
|
||||
TagClick() {
|
||||
const tag = this.props.children.toString().toLowerCase();
|
||||
|
||||
if (this.props.onclick) {
|
||||
this.props.onclick(tag);
|
||||
return;
|
||||
}
|
||||
|
||||
// call callback functin to switch to category page with specified tag
|
||||
GlobalInfos.getViewBinding().changeRootElement(
|
||||
<CategoryPage category={tag}/>);
|
||||
}
|
||||
}
|
||||
|
||||
export default Tag;
|
@@ -6,33 +6,20 @@ import {shallow} from 'enzyme';
|
||||
|
||||
describe('<Tag/>', function () {
|
||||
it('renders without crashing ', function () {
|
||||
const wrapper = shallow(<Tag>test</Tag>);
|
||||
const wrapper = shallow(<Tag tagInfo={{tag_name: 'testname', tag_id: 1}}/>);
|
||||
wrapper.unmount();
|
||||
});
|
||||
|
||||
it('renders childs correctly', function () {
|
||||
const wrapper = shallow(<Tag>test</Tag>);
|
||||
const wrapper = shallow(<Tag tagInfo={{tag_name: 'test', tag_id: 1}}/>);
|
||||
expect(wrapper.children().text()).toBe('test');
|
||||
});
|
||||
|
||||
it('click event triggered and setvideo callback called', function () {
|
||||
global.fetch = prepareFetchApi({});
|
||||
const func = jest.fn();
|
||||
prepareViewBinding(func);
|
||||
|
||||
const wrapper = shallow(<Tag>test</Tag>);
|
||||
|
||||
expect(func).toBeCalledTimes(0);
|
||||
|
||||
wrapper.simulate('click');
|
||||
|
||||
expect(func).toBeCalledTimes(1);
|
||||
});
|
||||
|
||||
it('test custom onclick function', function () {
|
||||
const func = jest.fn();
|
||||
|
||||
const wrapper = shallow(<Tag
|
||||
tagInfo={{tag_name: 'test', tag_id: 1}}
|
||||
onclick={() => {func();}}>test</Tag>);
|
||||
|
||||
expect(func).toBeCalledTimes(0);
|
||||
|
47
src/elements/Tag/Tag.tsx
Normal file
47
src/elements/Tag/Tag.tsx
Normal file
@@ -0,0 +1,47 @@
|
||||
import React from 'react';
|
||||
|
||||
import styles from './Tag.module.css';
|
||||
import {Link} from 'react-router-dom';
|
||||
import {TagType} from '../../api/VideoTypes';
|
||||
|
||||
interface props {
|
||||
onclick?: (_: string) => void
|
||||
tagInfo: TagType
|
||||
}
|
||||
|
||||
/**
|
||||
* A Component representing a single Category tag
|
||||
*/
|
||||
class Tag extends React.Component<props> {
|
||||
render(): JSX.Element {
|
||||
if (this.props.onclick) {
|
||||
return this.renderButton();
|
||||
} else {
|
||||
return (
|
||||
<Link to={'/categories/' + this.props.tagInfo.tag_id}>
|
||||
{this.renderButton()}
|
||||
</Link>
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
renderButton(): JSX.Element {
|
||||
return (
|
||||
<button className={styles.tagbtn} onClick={(): void => this.TagClick()}
|
||||
data-testid='Test-Tag'>{this.props.tagInfo.tag_name}</button>
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* click handling for a Tag
|
||||
*/
|
||||
TagClick(): void {
|
||||
if (this.props.onclick) {
|
||||
// call custom onclick handling
|
||||
this.props.onclick(this.props.tagInfo.tag_name); // todo check if param is neccessary
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
export default Tag;
|
Reference in New Issue
Block a user