From b07bd4d102913a87bd10f13e7c43799c25e887d6 Mon Sep 17 00:00:00 2001 From: Michael Weimann Date: Thu, 22 Dec 2022 15:30:42 +0100 Subject: [PATCH] Show initial broadcast position in seekbar (#9796) --- .../views/audio_messages/SeekBar.tsx | 2 +- .../views/audio_messages/SeekBar-test.tsx | 30 +++++++++++++------ .../__snapshots__/SeekBar-test.tsx.snap | 21 +++++++++++-- 3 files changed, 40 insertions(+), 13 deletions(-) diff --git a/src/components/views/audio_messages/SeekBar.tsx b/src/components/views/audio_messages/SeekBar.tsx index 9006016b14..a7bbc20c46 100644 --- a/src/components/views/audio_messages/SeekBar.tsx +++ b/src/components/views/audio_messages/SeekBar.tsx @@ -60,7 +60,7 @@ export default class SeekBar extends React.PureComponent { super(props); this.state = { - percentage: 0, + percentage: percentageOf(this.props.playback.timeSeconds, 0, this.props.playback.durationSeconds), }; // We don't need to de-register: the class handles this for us internally diff --git a/test/components/views/audio_messages/SeekBar-test.tsx b/test/components/views/audio_messages/SeekBar-test.tsx index fae947483b..e957daf0fe 100644 --- a/test/components/views/audio_messages/SeekBar-test.tsx +++ b/test/components/views/audio_messages/SeekBar-test.tsx @@ -42,24 +42,36 @@ describe("SeekBar", () => { }); describe("when rendering a SeekBar", () => { - beforeEach(async () => { + beforeEach(() => { renderResult = render(); - act(() => { - playback.liveData.update([playback.timeSeconds, playback.durationSeconds]); - frameRequestCallback(0); - }); }); - it("should render as expected", () => { + it("should render the initial position", () => { // expected value 3141 / 31415 ~ 0.099984084 expect(renderResult.container).toMatchSnapshot(); }); + describe("and the playback proceeds", () => { + beforeEach(async () => { + // @ts-ignore + playback.timeSeconds = 6969; + act(() => { + playback.liveData.update([playback.timeSeconds, playback.durationSeconds]); + frameRequestCallback(0); + }); + }); + + it("should render as expected", () => { + // expected value 6969 / 31415 ~ 0.221836702 + expect(renderResult.container).toMatchSnapshot(); + }); + }); + describe("and seeking position with the slider", () => { beforeEach(() => { const rangeInput = renderResult.container.querySelector("[type='range']"); act(() => { - fireEvent.change(rangeInput, { target: { value: 0.5 } }); + fireEvent.change(rangeInput!, { target: { value: 0.5 } }); }); }); @@ -71,7 +83,7 @@ describe("SeekBar", () => { beforeEach(() => { mocked(playback.skipTo).mockClear(); act(() => { - seekBarRef.current.left(); + seekBarRef.current!.left(); }); }); @@ -84,7 +96,7 @@ describe("SeekBar", () => { beforeEach(() => { mocked(playback.skipTo).mockClear(); act(() => { - seekBarRef.current.right(); + seekBarRef.current!.right(); }); }); diff --git a/test/components/views/audio_messages/__snapshots__/SeekBar-test.tsx.snap b/test/components/views/audio_messages/__snapshots__/SeekBar-test.tsx.snap index f545f94d74..8c66fda4d7 100644 --- a/test/components/views/audio_messages/__snapshots__/SeekBar-test.tsx.snap +++ b/test/components/views/audio_messages/__snapshots__/SeekBar-test.tsx.snap @@ -1,6 +1,21 @@ // Jest Snapshot v1, https://goo.gl/fbAQLP -exports[`SeekBar when rendering a SeekBar should render as expected 1`] = ` +exports[`SeekBar when rendering a SeekBar and the playback proceeds should render as expected 1`] = ` +
+ +
+`; + +exports[`SeekBar when rendering a SeekBar should render the initial position 1`] = `
`;