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/jest-warnings #19

Open
wants to merge 3 commits into
base: revert-17-revert-13-feat/eslint
Choose a base branch
from
Open
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
30 changes: 3 additions & 27 deletions front/.eslintrc.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"env": {
"browser": false,
"browser": true,
"es6": true,
"mocha": false,
"node": true
Expand All @@ -15,32 +15,8 @@
"sourceType": "module"
},
"rules": {
"arrow-spacing": "error",
"brace-style": "error",
"comma-dangle": ["error", "always-multiline"],
"comma-spacing": ["error", { "before": false, "after": true }],
"indent": ["error", 2],
"keyword-spacing": ["error"],
"line-comment-position": ["error", { "position": "above" }],
"max-len": [
"error",
{
"ignoreStrings": true,
"ignoreRegExpLiterals": true,
"ignoreUrls": true,
"ignoreTemplateLiterals": true,
"code": 80
}
],
"multiline-comment-style": ["error", "starred-block"],
"object-curly-spacing": ["error", "always"],
"quotes": ["error", "double"],
"react/jsx-curly-spacing": ["error", { "when": "always" }],
"react/prop-types": "off",
"semi": ["error", "always"],
"sort-imports": "error",
"sort-keys": "error",
"spaced-comment": ["error", "always"]
"no-unused-vars": ["error", { "argsIgnorePattern": "_" }],
"react/prop-types": "off"
},
"settings": {
"react": {
Expand Down
2 changes: 1 addition & 1 deletion front/src/Component/App.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ const App = ({
be able to insert images or youtube videos.
</p>
<p>
I'm doing my best to have tweet insertion fixed asap. Happy testing !
I`&lsquo;m doing my best to have tweet insertion fixed asap. Happy testing !
</p>
</TextEditor>
</main>
Expand Down
4 changes: 2 additions & 2 deletions front/src/Component/Container/MediaPicker/MediaPicker.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ import { searchVideos } from '../../../Redux/State/MediaPicker/VideoPicker'
import MediaPicker from '../../View/MediaPicker/MediaPicker'
import { componentWillUnmount } from 'react-functional-lifecycle'

// mapStateToProps :: (State, Props) -> Props
const mapStateToProps = (state, ownProps) => ({
// mapStateToProps :: State -> Props
const mapStateToProps = state => ({
isOpened: state.MediaPicker.Display.opened,
isFetchingImages: state.MediaPicker.ImagePicker.isFetching,
isFetchingVideos: state.MediaPicker.VideoPicker.isFetching,
Expand Down
1 change: 0 additions & 1 deletion front/src/Component/View/MediaPicker/MediaPicker.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ const MediaPicker = ({
searchImages,
searchVideos,
openImagePicker,
openVideoPicker,
}) =>
<div data-is="media-picker" className={`${!isOpened ? 'closed' : ''}`}>
<div className="search-images">
Expand Down
2 changes: 1 addition & 1 deletion front/src/Epic/BrightcovePlayer.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ export const renderVideoEpic = (action$, state$, { window }) =>
map(compose(getVideoElement, prop('id'))),
filter(complement(isNil)),
withLatestFrom(state$),
filter(([ video, state ]) => state.BrightcovePlayer[`enPlayerReady`]),
filter(([ _, state ]) => state.BrightcovePlayer[`enPlayerReady`]),
// brightcove SDK is loaded from the loadPlayerEpic above
filter(() => !isNil(window['bc'])),
map(([ video ]) => ({
Expand Down
67 changes: 28 additions & 39 deletions front/src/Epic/MediaPicker/ImagePicker.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import {
PICK_IMAGE_WITH_CREDITS,
RECEIVED_IMAGES,
} from '../../Redux/State/MediaPicker/ImagePicker'
import { OPEN_IMAGE_PICKER } from '../../Redux/State/MediaPicker/MediaPicker'
import {
searchImagesEpic,
changePageEpic,
Expand Down Expand Up @@ -43,15 +42,13 @@ const dependencies = {
describe('Epic :: MediaPicker :: ImagePicker :: searchImagesEpic', () => {
const fetchImages$ = of(fetchImages());

it('dispatches receivedImages', done => {
searchImagesEpic(fetchImages$, null, dependencies)
it('dispatches receivedImages', async () => {
const action = await searchImagesEpic(fetchImages$, null, dependencies)
.toPromise(Promise)
.then(action => {
expect(action.type).toEqual(RECEIVED_IMAGES);
expect(action.images).toEqual(transformedImages);
done();
})
.catch(error => { console.error(error); done(); });
;

expect(action.type).toEqual(RECEIVED_IMAGES);
expect(action.images).toEqual(transformedImages);
}, 1000);
});

Expand All @@ -68,26 +65,22 @@ describe('Epic :: MediaPicker :: ImagePicker :: changePageEpic', () => {
});

// @TODO rewrite this using rxjs TestScheduler
it('dispatches receivedImages (after scrollLeft action)', done => {
changePageEpic(scrollLeft$, state$, dependencies)
it('dispatches receivedImages (after scrollLeft action)', async () => {
const action = await changePageEpic(scrollLeft$, state$, dependencies)
.toPromise(Promise)
.then(action => {
expect(action.type).toEqual(RECEIVED_IMAGES);
expect(action.images).toEqual(transformedImages);
done();
})
.catch(error => { console.error(error); done(); });
;

expect(action.type).toEqual(RECEIVED_IMAGES);
expect(action.images).toEqual(transformedImages);
}, 1000);

it('dispatches receivedImages (after scrollRight action)', done => {
changePageEpic(scrollRight$, state$, dependencies)
it('dispatches receivedImages (after scrollRight action)', async () => {
const action = await changePageEpic(scrollRight$, state$, dependencies)
.toPromise(Promise)
.then(action => {
expect(action.type).toEqual(RECEIVED_IMAGES);
expect(action.images).toEqual(transformedImages);
done();
})
.catch(error => { console.error(error); done(); });
;

expect(action.type).toEqual(RECEIVED_IMAGES);
expect(action.images).toEqual(transformedImages);
}, 1000);
});

Expand All @@ -103,27 +96,23 @@ describe('Epic :: MediaPicker :: ImagePicker :: ensurePickedImageHasCreditsEpic'
},
})

it('dispatches pickImageWithCredits when image has credits', done => {
it('dispatches pickImageWithCredits when image has credits', async () => {
const pickImage$ = of(pickImage(1));

ensurePickedImageHasCreditsEpic(pickImage$, state$)
const action = await ensurePickedImageHasCreditsEpic(pickImage$, state$)
.toPromise(Promise)
.then(action => {
expect(action.type).toEqual(PICK_IMAGE_WITH_CREDITS);
done();
})
.catch(error => { console.error(error); done(); });
;

expect(action.type).toEqual(PICK_IMAGE_WITH_CREDITS);
}, 1000);

it('dispatches error when picked image has no credit', done => {
it('dispatches error when picked image has no credit', async() => {
const pickImage$ = of(pickImage(2));

ensurePickedImageHasCreditsEpic(pickImage$, state$)
const action = await ensurePickedImageHasCreditsEpic(pickImage$, state$)
.toPromise(Promise)
.then(action => {
expect(action.type).toEqual(ERROR);
done();
})
.catch(error => { console.error(error); done(); });
;

expect(action.type).toEqual(ERROR);
}, 1000);
});
2 changes: 1 addition & 1 deletion front/src/Epic/MediaPicker/MediaPicker.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ describe('Epic :: ArticleEditor :: closeMediaPickerEpic', () => {
expect(actual).toEqual(expected);
});

testScheduler.run(({ hot, cold, expectObservable }) => {
testScheduler.run(({ hot, expectObservable }) => {
const action$ = hot('ab-ef-gh-ij', {
a: open(),
b: pickImageWithCredits(),
Expand Down
2 changes: 1 addition & 1 deletion front/src/Epic/MediaPicker/VideoPicker.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ export const fetchVideosEpic = (action$, state$, { fetchApi }) =>
action$.pipe(
ofType(FETCH_VIDEOS),
withLatestFrom(state$),
mergeMap(([ action, state ]) => fetchApi(join('', [
mergeMap(([ _, state ]) => fetchApi(join('', [
`${process.env.REACT_APP_MOCK_SERVER_API_URL}/videos`,
`?q=${state.MediaPicker.VideoPicker.searchString}`,
`&page=${state.MediaPicker.VideoPicker.page}`,
Expand Down
13 changes: 5 additions & 8 deletions front/src/Epic/MediaPicker/VideoPicker.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import {
} from '../../Redux/State/MediaPicker/VideoPicker'

describe('Epic :: MediaPicker :: VideoPicker :: fetchVideosEpic', () => {
it('dispatches videosReceived', done => {
it('dispatches videosReceived', async () => {
const fetchVideos$ = of(fetchVideos());
const state$ = new StateObservable(new Subject(), {
MediaPicker: {
Expand All @@ -30,14 +30,11 @@ describe('Epic :: MediaPicker :: VideoPicker :: fetchVideosEpic', () => {
fetchApi: () => new Promise(resolve => resolve({})),
};

fetchVideosEpic(fetchVideos$, state$, dependencies)
const action = await fetchVideosEpic(fetchVideos$, state$, dependencies)
.toPromise(Promise)
.then(action => {
expect(action.type).toEqual(VIDEOS_RECEIVED)
;

done()
})
.catch(err => { console.error(err); done() });
expect(action.type).toEqual(VIDEOS_RECEIVED);
}, 1000);
});

Expand All @@ -47,7 +44,7 @@ describe('Epic :: MediaPicker :: VideoPicker :: searchVideosEpic', () => {
expect(actual).toEqual(expected);
});

testScheduler.run(({ hot, cold, expectObservable }) => {
testScheduler.run(({ hot, expectObservable }) => {
const action$ = hot('a-b----c', {
a: scrollLeft(),
b: scrollRight(),
Expand Down
55 changes: 20 additions & 35 deletions front/src/Epic/TextEditor/InsertTweet.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,34 +28,28 @@ describe('Epic :: TextEditor :: InsertTweet :: fetchEmbedTweetEpic', () => {
const insertTweet$ = of(insertTweet());
const state$ = new StateObservable(new Subject(), {});

it('dispatches embedTweetFetched action', done => {
it('dispatches embedTweetFetched action', async () => {
const dependencies = {
fetchApi: () => Promise.resolve({ body: {}}),
};

fetchEmbedTweetEpic(insertTweet$, state$, dependencies)
const action = await fetchEmbedTweetEpic(insertTweet$, state$, dependencies)
.toPromise(Promise)
.then(action => {
expect(action.type).toEqual(EMBED_TWEET_FETCHED)
;

done()
})
.catch(err => { console.error(err); done() });
expect(action.type).toEqual(EMBED_TWEET_FETCHED);
}, 1000);

it('dispatches error action', done => {
it('dispatches error action', async () => {
const dependencies = {
fetchApi: () => Promise.reject('fail !'),
};

fetchEmbedTweetEpic(insertTweet$, state$, dependencies)
const action = await fetchEmbedTweetEpic(insertTweet$, state$, dependencies)
.toPromise(Promise)
.then(action => {
expect(action.type).toEqual(ERROR)
;

done()
})
.catch(err => { console.error(err); done() });
expect(action.type).toEqual(ERROR);
}, 1000);
});

Expand All @@ -70,53 +64,44 @@ describe('Epic :: TextEditor :: InsertTweet :: insertTweetEpic', () => {
},
});

it('dispatches tweetInserted action', done => {
it('dispatches tweetInserted action', async () => {
const embedTweetFetched$ = of(embedTweetFetched(
'editor-name',
'<blockquote><p>test</p></blockquote>',
'https://twitter.com/realDonaldTrump/status/1083756525196320773'
));

insertTweetEpic(embedTweetFetched$, state$)
const action = await insertTweetEpic(embedTweetFetched$, state$)
.toPromise(Promise)
.then(action => {
expect(action.type).toEqual(TWEET_INSERTED)
;

done()
})
.catch(err => { console.error(err); done() });
expect(action.type).toEqual(TWEET_INSERTED);
}, 1000);

it('dispatches error action', done => {
it('dispatches error action', async () => {
const embedTweetFetched$ = of(embedTweetFetched(
'wrong-editor-name',
'badly formatted html string',
'wrong url',
));

insertTweetEpic(embedTweetFetched$, state$)
const action = await insertTweetEpic(embedTweetFetched$, state$)
.toPromise(Promise)
.then(action => {
expect(action.type).toEqual(ERROR)
;

done()
})
.catch(err => { console.error(err); done() });
expect(action.type).toEqual(ERROR);
}, 1000);
});

describe('Epic :: TextEditor :: InsertTweet', () => {
it('dispatches renderTweet action', done => {
it('dispatches renderTweet action', async () => {
const tweetInserted$ = of(tweetInserted('editor-name', '1', 'zxylog', '<p></p>'));
const state$ = new StateObservable(new Subject(), {});

renderInsertedTweetEpic(tweetInserted$, state$)
const action = await renderInsertedTweetEpic(tweetInserted$, state$)
.toPromise(Promise)
.then(action => {
expect(action.type).toEqual(RENDER_TWEET)
;

done()
})
.catch(err => { console.error(err); done() });
expect(action.type).toEqual(RENDER_TWEET);
}, 1000);
});
Loading