Skip to content
This repository was archived by the owner on Sep 11, 2024. It is now read-only.

Commit b07bd4d

Browse files
authored
Show initial broadcast position in seekbar (#9796)
1 parent e9224f6 commit b07bd4d

File tree

3 files changed

+40
-13
lines changed

3 files changed

+40
-13
lines changed

src/components/views/audio_messages/SeekBar.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ export default class SeekBar extends React.PureComponent<IProps, IState> {
6060
super(props);
6161

6262
this.state = {
63-
percentage: 0,
63+
percentage: percentageOf(this.props.playback.timeSeconds, 0, this.props.playback.durationSeconds),
6464
};
6565

6666
// We don't need to de-register: the class handles this for us internally

test/components/views/audio_messages/SeekBar-test.tsx

Lines changed: 21 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -42,24 +42,36 @@ describe("SeekBar", () => {
4242
});
4343

4444
describe("when rendering a SeekBar", () => {
45-
beforeEach(async () => {
45+
beforeEach(() => {
4646
renderResult = render(<SeekBar ref={seekBarRef} playback={playback} />);
47-
act(() => {
48-
playback.liveData.update([playback.timeSeconds, playback.durationSeconds]);
49-
frameRequestCallback(0);
50-
});
5147
});
5248

53-
it("should render as expected", () => {
49+
it("should render the initial position", () => {
5450
// expected value 3141 / 31415 ~ 0.099984084
5551
expect(renderResult.container).toMatchSnapshot();
5652
});
5753

54+
describe("and the playback proceeds", () => {
55+
beforeEach(async () => {
56+
// @ts-ignore
57+
playback.timeSeconds = 6969;
58+
act(() => {
59+
playback.liveData.update([playback.timeSeconds, playback.durationSeconds]);
60+
frameRequestCallback(0);
61+
});
62+
});
63+
64+
it("should render as expected", () => {
65+
// expected value 6969 / 31415 ~ 0.221836702
66+
expect(renderResult.container).toMatchSnapshot();
67+
});
68+
});
69+
5870
describe("and seeking position with the slider", () => {
5971
beforeEach(() => {
6072
const rangeInput = renderResult.container.querySelector("[type='range']");
6173
act(() => {
62-
fireEvent.change(rangeInput, { target: { value: 0.5 } });
74+
fireEvent.change(rangeInput!, { target: { value: 0.5 } });
6375
});
6476
});
6577

@@ -71,7 +83,7 @@ describe("SeekBar", () => {
7183
beforeEach(() => {
7284
mocked(playback.skipTo).mockClear();
7385
act(() => {
74-
seekBarRef.current.left();
86+
seekBarRef.current!.left();
7587
});
7688
});
7789

@@ -84,7 +96,7 @@ describe("SeekBar", () => {
8496
beforeEach(() => {
8597
mocked(playback.skipTo).mockClear();
8698
act(() => {
87-
seekBarRef.current.right();
99+
seekBarRef.current!.right();
88100
});
89101
});
90102

test/components/views/audio_messages/__snapshots__/SeekBar-test.tsx.snap

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,21 @@
11
// Jest Snapshot v1, https://goo.gl/fbAQLP
22

3-
exports[`SeekBar when rendering a SeekBar should render as expected 1`] = `
3+
exports[`SeekBar when rendering a SeekBar and the playback proceeds should render as expected 1`] = `
4+
<div>
5+
<input
6+
class="mx_SeekBar"
7+
max="1"
8+
min="0"
9+
step="0.001"
10+
style="--fillTo: 0.22183670221231896;"
11+
tabindex="0"
12+
type="range"
13+
value="0.22183670221231896"
14+
/>
15+
</div>
16+
`;
17+
18+
exports[`SeekBar when rendering a SeekBar should render the initial position 1`] = `
419
<div>
520
<input
621
class="mx_SeekBar"
@@ -23,10 +38,10 @@ exports[`SeekBar when rendering a disabled SeekBar should render as expected 1`]
2338
max="1"
2439
min="0"
2540
step="0.001"
26-
style="--fillTo: 0;"
41+
style="--fillTo: 0.0999840840362884;"
2742
tabindex="0"
2843
type="range"
29-
value="0"
44+
value="0.0999840840362884"
3045
/>
3146
</div>
3247
`;

0 commit comments

Comments
 (0)