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

Show initial broadcast position in seekbar #9796

Merged
merged 6 commits into from
Dec 22, 2022
Merged
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
2 changes: 1 addition & 1 deletion src/components/views/audio_messages/SeekBar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ export default class SeekBar extends React.PureComponent<IProps, IState> {
super(props);

this.state = {
percentage: 0,
percentage: percentageOf(this.props.playback.timeSeconds, 0, this.props.playback.durationSeconds),
weeman1337 marked this conversation as resolved.
Show resolved Hide resolved
};

// We don't need to de-register: the class handles this for us internally
Expand Down
30 changes: 21 additions & 9 deletions test/components/views/audio_messages/SeekBar-test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -42,24 +42,36 @@ describe("SeekBar", () => {
});

describe("when rendering a SeekBar", () => {
beforeEach(async () => {
beforeEach(() => {
renderResult = render(<SeekBar ref={seekBarRef} playback={playback} />);
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 } });
});
});

Expand All @@ -71,7 +83,7 @@ describe("SeekBar", () => {
beforeEach(() => {
mocked(playback.skipTo).mockClear();
act(() => {
seekBarRef.current.left();
seekBarRef.current!.left();
});
});

Expand All @@ -84,7 +96,7 @@ describe("SeekBar", () => {
beforeEach(() => {
mocked(playback.skipTo).mockClear();
act(() => {
seekBarRef.current.right();
seekBarRef.current!.right();
});
});

Expand Down
Original file line number Diff line number Diff line change
@@ -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`] = `
<div>
<input
class="mx_SeekBar"
max="1"
min="0"
step="0.001"
style="--fillTo: 0.22183670221231896;"
tabindex="0"
type="range"
value="0.22183670221231896"
/>
</div>
`;

exports[`SeekBar when rendering a SeekBar should render the initial position 1`] = `
<div>
<input
class="mx_SeekBar"
Expand All @@ -23,10 +38,10 @@ exports[`SeekBar when rendering a disabled SeekBar should render as expected 1`]
max="1"
min="0"
step="0.001"
style="--fillTo: 0;"
style="--fillTo: 0.0999840840362884;"
tabindex="0"
type="range"
value="0"
value="0.0999840840362884"
/>
</div>
`;