build electron app
implement new fetch api calls use typescript
This commit is contained in:
@ -2,7 +2,8 @@ import React from 'react';
|
||||
import style from './Preview.module.css';
|
||||
import Player from '../../pages/Player/Player';
|
||||
import {Spinner} from 'react-bootstrap';
|
||||
import GlobalInfos from '../../GlobalInfos';
|
||||
import GlobalInfos from '../../utils/GlobalInfos';
|
||||
import {callAPIPlain} from '../../utils/Api';
|
||||
|
||||
/**
|
||||
* Component for single preview tile
|
||||
@ -19,22 +20,12 @@ class Preview extends React.Component {
|
||||
}
|
||||
|
||||
componentDidMount() {
|
||||
this.setState({
|
||||
previewpicture: null,
|
||||
name: this.props.name
|
||||
callAPIPlain('video.php', {action: 'readThumbnail', movieid: this.props.movie_id}, (result) => {
|
||||
this.setState({
|
||||
previewpicture: result,
|
||||
name: this.props.name
|
||||
});
|
||||
});
|
||||
|
||||
const updateRequest = new FormData();
|
||||
updateRequest.append('action', 'readThumbnail');
|
||||
updateRequest.append('movieid', this.props.movie_id);
|
||||
|
||||
fetch('/api/video.php', {method: 'POST', body: updateRequest})
|
||||
.then((response) => response.text()
|
||||
.then((result) => {
|
||||
this.setState({
|
||||
previewpicture: result
|
||||
});
|
||||
}));
|
||||
}
|
||||
|
||||
render() {
|
||||
|
@ -9,12 +9,6 @@ describe('<Preview/>', function () {
|
||||
wrapper.unmount();
|
||||
});
|
||||
|
||||
// check if preview title renders correctly
|
||||
it('renders title', () => {
|
||||
const wrapper = shallow(<Preview name='test'/>);
|
||||
expect(wrapper.find('.previewtitle').text()).toBe('test');
|
||||
});
|
||||
|
||||
|
||||
it('click event triggered', () => {
|
||||
const func = jest.fn();
|
||||
@ -36,7 +30,7 @@ describe('<Preview/>', function () {
|
||||
});
|
||||
global.fetch = jest.fn().mockImplementation(() => mockFetchPromise);
|
||||
|
||||
const wrapper = shallow(<Preview/>);
|
||||
const wrapper = shallow(<Preview name='test'/>);
|
||||
|
||||
// now called 1 times
|
||||
expect(global.fetch).toHaveBeenCalledTimes(1);
|
||||
@ -44,6 +38,8 @@ describe('<Preview/>', function () {
|
||||
process.nextTick(() => {
|
||||
// received picture should be rendered into wrapper
|
||||
expect(wrapper.find('.previewimage').props().src).not.toBeNull();
|
||||
// check if preview title renders correctly
|
||||
expect(wrapper.find('.previewtitle').text()).toBe('test');
|
||||
|
||||
global.fetch.mockClear();
|
||||
done();
|
||||
|
Reference in New Issue
Block a user