Skip to content

Commit

Permalink
fix: Rename API tmp. #1601
Browse files Browse the repository at this point in the history
  • Loading branch information
mturoci committed Nov 18, 2022
1 parent 0f7e86e commit 1e5788b
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 42 deletions.
76 changes: 38 additions & 38 deletions ui/src/audio_annotator.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -235,8 +235,8 @@ describe('AudioAnnotator.tsx', () => {
fireEvent.mouseMove(canvasEl, { clientX: 10 + moveOffset, clientY: 60, buttons: 1 })
fireEvent.click(canvasEl, { clientX: 10 + moveOffset, clientY: 60 })

const { from, to } = items[0]
expect(wave.args[name]).toMatchObject([{ ...items[0], range_from: from + moveOffset, range_to: to + moveOffset }, items[1]])
const { range_from, range_to } = items[0]
expect(wave.args[name]).toMatchObject([{ ...items[0], range_from: range_from + moveOffset, range_to: range_to + moveOffset }, items[1]])
})

it('Does not move annotation if left mouse btn not pressed (dragging)', async () => {
Expand All @@ -258,28 +258,28 @@ describe('AudioAnnotator.tsx', () => {
expect(wave.args[name]).toMatchObject(items)
const canvasEl = container.querySelector('canvas')!
const moveOffset = 5
const { from } = items[1]
const { range_from } = items[1]
fireEvent.click(canvasEl, { clientX: 70, clientY: 50 })
fireEvent.mouseDown(canvasEl, { clientX: from, clientY: 50, buttons: 1 })
fireEvent.mouseMove(canvasEl, { clientX: from - moveOffset, clientY: 60, buttons: 1 })
fireEvent.click(canvasEl, { clientX: from - moveOffset, clientY: 60 })
fireEvent.mouseDown(canvasEl, { clientX: range_from, clientY: 50, buttons: 1 })
fireEvent.mouseMove(canvasEl, { clientX: range_from - moveOffset, clientY: 60, buttons: 1 })
fireEvent.click(canvasEl, { clientX: range_from - moveOffset, clientY: 60 })

expect(wave.args[name]).toMatchObject([items[0], { ...items[1], range_from: from - moveOffset }])
expect(wave.args[name]).toMatchObject([items[0], { ...items[1], range_from: range_from - moveOffset }])
})

it('Resizes annotation from and exceeds the "to"', async () => {
const { container } = render(<XAudioAnnotator model={model} />)
await waitForComponentLoad()
expect(wave.args[name]).toMatchObject(items)
const canvasEl = container.querySelector('canvas')!
const { from, to } = items[1]
const moveOffset = to - from + 5
const { range_from, range_to } = items[1]
const moveOffset = range_to - range_from + 5
fireEvent.click(canvasEl, { clientX: 70, clientY: 50 })
fireEvent.mouseDown(canvasEl, { clientX: from, clientY: 50, buttons: 1 })
fireEvent.mouseMove(canvasEl, { clientX: from + moveOffset, clientY: 60, buttons: 1 })
fireEvent.click(canvasEl, { clientX: from + moveOffset, clientY: 60 })
fireEvent.mouseDown(canvasEl, { clientX: range_from, clientY: 50, buttons: 1 })
fireEvent.mouseMove(canvasEl, { clientX: range_from + moveOffset, clientY: 60, buttons: 1 })
fireEvent.click(canvasEl, { clientX: range_from + moveOffset, clientY: 60 })

expect(wave.args[name]).toMatchObject([items[0], { ...items[1], range_from: to, range_to: to + 5 }])
expect(wave.args[name]).toMatchObject([items[0], { ...items[1], range_from: range_to, range_to: range_to + 5 }])
})

it('Resizes annotation to', async () => {
Expand All @@ -288,28 +288,28 @@ describe('AudioAnnotator.tsx', () => {
expect(wave.args[name]).toMatchObject(items)
const canvasEl = container.querySelector('canvas')!
const moveOffset = 5
const { to } = items[0]
const { range_to } = items[0]
fireEvent.click(canvasEl, { clientX: 10, clientY: 50 })
fireEvent.mouseDown(canvasEl, { clientX: to, clientY: 50, buttons: 1 })
fireEvent.mouseMove(canvasEl, { clientX: to + moveOffset, clientY: 60, buttons: 1 })
fireEvent.click(canvasEl, { clientX: to + moveOffset, clientY: 60 })
fireEvent.mouseDown(canvasEl, { clientX: range_to, clientY: 50, buttons: 1 })
fireEvent.mouseMove(canvasEl, { clientX: range_to + moveOffset, clientY: 60, buttons: 1 })
fireEvent.click(canvasEl, { clientX: range_to + moveOffset, clientY: 60 })

expect(wave.args[name]).toMatchObject([{ ...items[0], range_to: to + moveOffset }, items[1]])
expect(wave.args[name]).toMatchObject([{ ...items[0], range_to: range_to + moveOffset }, items[1]])
})

it('Resizes annotation to and exceeds the "from"', async () => {
const { container } = render(<XAudioAnnotator model={model} />)
await waitForComponentLoad()
expect(wave.args[name]).toMatchObject(items)
const canvasEl = container.querySelector('canvas')!
const { from, to } = items[1]
const moveOffset = to - from + 5
const { range_from, range_to } = items[1]
const moveOffset = range_to - range_from + 5
fireEvent.click(canvasEl, { clientX: 70, clientY: 50 })
fireEvent.mouseDown(canvasEl, { clientX: to, clientY: 50, buttons: 1 })
fireEvent.mouseMove(canvasEl, { clientX: to - moveOffset, clientY: 60, buttons: 1 })
fireEvent.click(canvasEl, { clientX: to - moveOffset, clientY: 60 })
fireEvent.mouseDown(canvasEl, { clientX: range_to, clientY: 50, buttons: 1 })
fireEvent.mouseMove(canvasEl, { clientX: range_to - moveOffset, clientY: 60, buttons: 1 })
fireEvent.click(canvasEl, { clientX: range_to - moveOffset, clientY: 60 })

expect(wave.args[name]).toMatchObject([items[0], { ...items[1], range_from: to - moveOffset, range_to: from }])
expect(wave.args[name]).toMatchObject([items[0], { ...items[1], range_from: range_to - moveOffset, range_to: range_from }])
})

})
Expand Down Expand Up @@ -356,10 +356,10 @@ describe('AudioAnnotator.tsx', () => {
await waitForComponentLoad()
const canvasEl = container.querySelector('canvas')!
const moveOffset = 5
const { from } = items[1]
const { range_from } = items[1]
fireEvent.click(canvasEl, { clientX: 70, clientY: 50 })
fireEvent.mouseDown(canvasEl, { clientX: from, clientY: 50, buttons: 1 })
fireEvent.mouseMove(canvasEl, { clientX: from - moveOffset, clientY: 60, buttons: 1 })
fireEvent.mouseDown(canvasEl, { clientX: range_from, clientY: 50, buttons: 1 })
fireEvent.mouseMove(canvasEl, { clientX: range_from - moveOffset, clientY: 60, buttons: 1 })
expect(getByTestId('audio-annotator-tooltip')).toBeVisible()
})

Expand All @@ -368,10 +368,10 @@ describe('AudioAnnotator.tsx', () => {
await waitForComponentLoad()
const canvasEl = container.querySelector('canvas')!
const moveOffset = 5
const { to } = items[0]
const { range_to } = items[0]
fireEvent.click(canvasEl, { clientX: 10, clientY: 50 })
fireEvent.mouseDown(canvasEl, { clientX: to, clientY: 50, buttons: 1 })
fireEvent.mouseMove(canvasEl, { clientX: to + moveOffset, clientY: 60, buttons: 1 })
fireEvent.mouseDown(canvasEl, { clientX: range_to, clientY: 50, buttons: 1 })
fireEvent.mouseMove(canvasEl, { clientX: range_to + moveOffset, clientY: 60, buttons: 1 })
expect(getByTestId('audio-annotator-tooltip')).toBeVisible()
})

Expand Down Expand Up @@ -424,11 +424,11 @@ describe('AudioAnnotator.tsx', () => {
expect(wave.args[name]).toMatchObject(items)
const canvasEl = container.querySelector('canvas')!
const moveOffset = 5
const { from } = items[1]
const { range_from } = items[1]
fireEvent.click(canvasEl, { clientX: 70, clientY: 50 })
fireEvent.mouseDown(canvasEl, { clientX: from, clientY: 50, buttons: 1 })
fireEvent.mouseMove(canvasEl, { clientX: from - moveOffset, clientY: 60, buttons: 1 })
fireEvent.click(canvasEl, { clientX: from - moveOffset, clientY: 60 })
fireEvent.mouseDown(canvasEl, { clientX: range_from, clientY: 50, buttons: 1 })
fireEvent.mouseMove(canvasEl, { clientX: range_from - moveOffset, clientY: 60, buttons: 1 })
fireEvent.click(canvasEl, { clientX: range_from - moveOffset, clientY: 60 })

expect(pushMock).toHaveBeenCalledTimes(1)
})
Expand All @@ -439,11 +439,11 @@ describe('AudioAnnotator.tsx', () => {
expect(wave.args[name]).toMatchObject(items)
const canvasEl = container.querySelector('canvas')!
const moveOffset = 5
const { to } = items[0]
const { range_to } = items[0]
fireEvent.click(canvasEl, { clientX: 10, clientY: 50 })
fireEvent.mouseDown(canvasEl, { clientX: to, clientY: 50, buttons: 1 })
fireEvent.mouseMove(canvasEl, { clientX: to + moveOffset, clientY: 60, buttons: 1 })
fireEvent.click(canvasEl, { clientX: to + moveOffset, clientY: 60 })
fireEvent.mouseDown(canvasEl, { clientX: range_to, clientY: 50, buttons: 1 })
fireEvent.mouseMove(canvasEl, { clientX: range_to + moveOffset, clientY: 60, buttons: 1 })
fireEvent.click(canvasEl, { clientX: range_to + moveOffset, clientY: 60 })

expect(pushMock).toHaveBeenCalledTimes(1)
})
Expand Down
8 changes: 4 additions & 4 deletions ui/src/audio_annotator.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -134,8 +134,8 @@ const
return (a2.range_from >= a1.range_from && a2.range_from <= a1.range_to) || (a1.range_from >= a2.range_from && a1.range_from <= a2.range_to)
},
createAnnotation = (start: U, end: U, tag: S) => ({
from: Math.min(start, end),
to: Math.max(start, end),
range_from: Math.min(start, end),
range_to: Math.max(start, end),
tag,
canvasHeight: WAVEFORM_HEIGHT,
canvasY: 0
Expand Down Expand Up @@ -263,7 +263,7 @@ const
let tooltipTo = 0
const { action, intersected: currIntersected } = currDrawnAnnotation.current
if (action === 'new') {
const { from, to } = createAnnotation(currDrawnAnnotation.current.from, cursor_x, activeTag)
const { range_from: from, range_to: to } = createAnnotation(currDrawnAnnotation.current.from, cursor_x, activeTag)
tooltipFrom = from
tooltipTo = to
currDrawnAnnotation.current = { from, to, action: 'new' }
Expand Down Expand Up @@ -418,7 +418,7 @@ export const XAudioAnnotator = ({ model }: { model: AudioAnnotator }) => {
fetchedAudioUrlRef = React.useRef<S>(),
audioPositionIntervalRef = React.useRef<U>(),
setWaveArgs = (annotations: DrawnAudioAnnotatorItem[]) => {
wave.args[model.name] = annotations.map(({ range_from: from, range_to: to, tag }) => ({ from, to, tag })) as unknown as Rec[]
wave.args[model.name] = annotations.map(({ range_from, range_to, tag }) => ({ range_from, range_to, tag })) as unknown as Rec[]
if (model.trigger) wave.push()
},
activateTag = (tagName: S) => () => {
Expand Down

0 comments on commit 1e5788b

Please sign in to comment.