add test and move style in stylesheet

This commit is contained in:
lukas 2021-06-22 22:01:35 +02:00
parent 8d50ec54e7
commit c7a0368a26
3 changed files with 39 additions and 35 deletions

View File

@ -8,6 +8,11 @@
margin-top: 25px; margin-top: 25px;
} }
.sortbyLabel {
color: grey;
margin-right: 5px;
margin-left: 25px;
}
/* Style The Dropdown Button */ /* Style The Dropdown Button */
.dropbtn { .dropbtn {

View File

@ -1,8 +1,10 @@
import {shallow} from 'enzyme'; import {shallow} from 'enzyme';
import React from 'react'; import React from 'react';
import {HomePage} from './HomePage'; import {HomePage, SortBy} from './HomePage';
import VideoContainer from '../../elements/VideoContainer/VideoContainer'; import VideoContainer from '../../elements/VideoContainer/VideoContainer';
import {SearchHandling} from './SearchHandling'; import {SearchHandling} from './SearchHandling';
import exp from "constants";
import {DefaultTags} from "../../types/GeneralTypes";
describe('<HomePage/>', function () { describe('<HomePage/>', function () {
it('renders without crashing ', function () { it('renders without crashing ', function () {
@ -83,6 +85,20 @@ describe('<HomePage/>', function () {
testBtn(tags.first()); testBtn(tags.first());
}); });
it('test sortby type change', function () {
const wrapper = shallow(<HomePage/>);
// expect those default values
expect(wrapper.state().sortby).toBe('Date Added');
expect(wrapper.instance().sortState).toBe(SortBy.date);
expect(wrapper.instance().tagState).toBe(DefaultTags.all);
wrapper.instance().onDropDownItemClick(SortBy.name, 'namesort');
expect(wrapper.state().sortby).toBe('namesort');
expect(wrapper.instance().sortState).toBe(SortBy.name);
});
}); });
describe('<SearchHandling/>', () => { describe('<SearchHandling/>', () => {

View File

@ -15,7 +15,7 @@ import {FontAwesomeIcon} from '@fortawesome/react-fontawesome';
import {faSortDown} from '@fortawesome/free-solid-svg-icons'; import {faSortDown} from '@fortawesome/free-solid-svg-icons';
// eslint-disable-next-line no-shadow // eslint-disable-next-line no-shadow
enum SortBy { export enum SortBy {
date, date,
likes, likes,
random, random,
@ -178,45 +178,17 @@ export class HomePage extends React.Component<Props, state> {
/> />
</SideBar> </SideBar>
<div> <div>
<span style={{color: 'grey', marginRight: 5}}>Sort By: </span> <span className={style.sortbyLabel}>Sort By: </span>
<div className={style.dropdown}> <div className={style.dropdown}>
<span className={style.dropbtn}> <span className={style.dropbtn}>
<span>{this.state.sortby}</span> <span>{this.state.sortby}</span>
<FontAwesomeIcon style={{marginLeft: 3, paddingBottom: 3}} icon={faSortDown} size='1x' /> <FontAwesomeIcon style={{marginLeft: 3, paddingBottom: 3}} icon={faSortDown} size='1x' />
</span> </span>
<div className={style.dropdownContent}> <div className={style.dropdownContent}>
<span <span onClick={(): void => this.onDropDownItemClick(SortBy.date, 'Date Added')}>Date Added</span>
onClick={(): void => { <span onClick={(): void => this.onDropDownItemClick(SortBy.likes, 'Most likes')}>Most likes</span>
this.sortState = SortBy.date; <span onClick={(): void => this.onDropDownItemClick(SortBy.random, 'Random')}>Random</span>
this.setState({sortby: 'Date Added '}); <span onClick={(): void => this.onDropDownItemClick(SortBy.name, 'Name')}>Name</span>
this.fetchVideoData();
}}>
Date Added
</span>
<span
onClick={(): void => {
this.sortState = SortBy.likes;
this.setState({sortby: 'Most likes'});
this.fetchVideoData();
}}>
Most likes
</span>
<span
onClick={(): void => {
this.sortState = SortBy.random;
this.setState({sortby: 'Random'});
this.fetchVideoData();
}}>
Random
</span>
<span
onClick={(): void => {
this.sortState = SortBy.name;
this.setState({sortby: 'Name'});
this.fetchVideoData();
}}>
Name
</span>
</div> </div>
</div> </div>
</div> </div>
@ -228,6 +200,17 @@ export class HomePage extends React.Component<Props, state> {
</> </>
); );
} }
/**
* click handler for sortby dropdown item click
* @param type type of sort action
* @param name new header title
*/
onDropDownItemClick(type: SortBy, name: string): void {
this.sortState = type;
this.setState({sortby: name});
this.fetchVideoData();
}
} }
export default withRouter(HomePage); export default withRouter(HomePage);