Skip to content
This repository has been archived by the owner on May 24, 2021. It is now read-only.

Commit

Permalink
fix(tests): Adapts tests for transcripts
Browse files Browse the repository at this point in the history
  • Loading branch information
alexander-heimbuch committed Jan 6, 2018
1 parent 7bdc324 commit 215bb53
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 30 deletions.
1 change: 0 additions & 1 deletion src/store/effects/player.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,6 @@ export default mediaPlayer => (store, action) => {
player && player.actions.setPlaytime(millisecondsToSeconds(action.payload))
break
case 'SET_VOLUME':
console.log(player)
player && player.actions.setVolume(action.payload)
break
case 'SET_RATE':
Expand Down
8 changes: 4 additions & 4 deletions src/store/effects/transcripts/active.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ playtimeTypes.forEach(type => {

activeEffect(store, {
type: 'SET_PLAYTIME',
payload: 350
payload: 350000
})

t.deepEqual(store.dispatch.getCall(1).args[0], {
Expand All @@ -62,7 +62,7 @@ playtimeTypes.forEach(type => {

activeEffect(store, {
type: 'SET_PLAYTIME',
payload: 700
payload: 700000
})

t.is(store.dispatch.getCalls().length, 1)
Expand Down Expand Up @@ -126,12 +126,12 @@ test.cb(`transcripts - active: calls interval search debounced with payload on S

activeEffect(store, {
type: 'SIMULATE_PLAYTIME',
payload: 350
payload: 350000
})

activeEffect(store, {
type: 'SIMULATE_PLAYTIME',
payload: 350
payload: 350000
})
})

Expand Down
22 changes: 12 additions & 10 deletions src/store/effects/transcripts/fetch.js
Original file line number Diff line number Diff line change
@@ -1,18 +1,20 @@
import actions from 'store/actions'
import { get, last, find } from 'lodash'
import { get, last, find, isNumber } from 'lodash'
import { compose, map, concat, orderBy, reduce } from 'lodash/fp'
import request from 'utils/request'

import { toPlayerTime } from 'utils/time'
import { toPlayerTime, secondsToMilliseconds } from 'utils/time'

const transformTime = time => isNumber(time) ? secondsToMilliseconds(time) : toPlayerTime(time)

const transformTranscript = reduce((transcripts, chunk) => {
const lastChunk = last(transcripts)
if (lastChunk && lastChunk.speaker && lastChunk.speaker === chunk.speaker) {
transcripts[transcripts.length - 1].end = toPlayerTime(chunk.end)
transcripts[transcripts.length - 1].end = transformTime(chunk.end)

transcripts[transcripts.length - 1].texts.push({
start: toPlayerTime(chunk.start),
end: toPlayerTime(chunk.end),
start: transformTime(chunk.start),
end: transformTime(chunk.end),
text: chunk.text
})

Expand All @@ -23,13 +25,13 @@ const transformTranscript = reduce((transcripts, chunk) => {
...transcripts,
{
type: 'transcript',
start: toPlayerTime(chunk.start),
end: toPlayerTime(chunk.end),
start: transformTime(chunk.start),
end: transformTime(chunk.end),
speaker: chunk.speaker,
texts: [
{
start: toPlayerTime(chunk.start),
end: toPlayerTime(chunk.end),
start: transformTime(chunk.start),
end: transformTime(chunk.end),
text: chunk.text
}
]
Expand All @@ -41,7 +43,7 @@ const transformChapters = (chapter, index) => ({
...chapter,
type: 'chapter',
index: index + 1,
start: toPlayerTime(chapter.start)
start: transformTime(chapter.start)
})

const mapSpeakers = speakers =>
Expand Down
31 changes: 17 additions & 14 deletions src/store/effects/transcripts/fixtures.js
Original file line number Diff line number Diff line change
Expand Up @@ -71,64 +71,67 @@ export const timeline = [
{
type: 'transcript',
start: 0,
end: 200,
end: 200000,
speaker: {
id: 'speaker-1',
name: 'Speaker One',
avatar: 'http://avatar/speaker/one'
},
texts: [
{
start: 0,
end: 100,
end: 100000,
text: 'fooo'
},
{
start: 100,
end: 200,
start: 100000,
end: 200000,
text: 'blaa'
}
]
},
{
title: 'Chapter Two',
start: 200,
start: 200000,
type: 'chapter',
index: 2
},
{
type: 'transcript',
start: 200,
end: 300,
start: 200000,
end: 300000,
speaker: {
id: 'speaker-2',
name: 'Speaker Two',
avatar: 'http://avatar/speaker/two'
},
texts: [
{
start: 200,
end: 300,
start: 200000,
end: 300000,
text: 'bar'
}
]
},
{
title: 'Chapter Three',
start: 250,
start: 250000,
type: 'chapter',
index: 3
},
{
type: 'transcript',
start: 300,
end: 400,
start: 300000,
end: 400000,
speaker: {
id: 'speaker-3',
name: 'Speaker Three',
avatar: 'http://avatar/speaker/three'
},
texts: [
{
start: 300,
end: 400,
start: 300000,
end: 400000,
text: 'baz'
}
]
Expand Down
2 changes: 1 addition & 1 deletion src/utils/time.js
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ export const parseMilliseconds = (time = '0') => {
// Transforms a h:mm:ss.f or mm:ss.ffff or ss time to milliseconds
export const toPlayerTime = (time = '0') => {
if (isNumber(time)) {
return secondsToMilliseconds(time)
return time
}

time = time || '0'
Expand Down

0 comments on commit 215bb53

Please sign in to comment.