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

Commit be1e575

Browse files
committed
Snap in PiP widget when content changed (#9797)
1 parent 20d9eb3 commit be1e575

File tree

3 files changed

+112
-0
lines changed

3 files changed

+112
-0
lines changed

src/components/views/voip/PictureInPictureDragger.tsx

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,10 @@ export default class PictureInPictureDragger extends React.Component<IProps> {
8585
UIStore.instance.off(UI_EVENTS.Resize, this.onResize);
8686
}
8787

88+
public componentDidUpdate(prevProps: Readonly<IProps>): void {
89+
if (prevProps.children !== this.props.children) this.snap(true);
90+
}
91+
8892
private animationCallback = () => {
8993
if (
9094
!this.moving &&
Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
/*
2+
Copyright 2022 The Matrix.org Foundation C.I.C.
3+
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
http://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.
15+
*/
16+
17+
import React from "react";
18+
import { render, RenderResult } from "@testing-library/react";
19+
20+
import PictureInPictureDragger, {
21+
CreatePipChildren,
22+
} from "../../../../src/components/views/voip/PictureInPictureDragger";
23+
24+
describe("PictureInPictureDragger", () => {
25+
let renderResult: RenderResult;
26+
27+
const mkContent1: CreatePipChildren = () => {
28+
return <div>content 1</div>;
29+
};
30+
31+
const mkContent2: CreatePipChildren = () => {
32+
return (
33+
<div>
34+
content 2<br />
35+
content 2.2
36+
</div>
37+
);
38+
};
39+
40+
describe("when rendering the dragger with PiP content 1", () => {
41+
beforeEach(() => {
42+
renderResult = render(<PictureInPictureDragger draggable={true}>{mkContent1}</PictureInPictureDragger>);
43+
});
44+
45+
it("should render the PiP content", () => {
46+
expect(renderResult.container).toMatchSnapshot("pip-content-1");
47+
});
48+
49+
describe("and rerendering PiP content 1", () => {
50+
beforeEach(() => {
51+
renderResult.rerender(<PictureInPictureDragger draggable={true}>{mkContent1}</PictureInPictureDragger>);
52+
});
53+
54+
it("should not change the PiP content", () => {
55+
expect(renderResult.container).toMatchSnapshot("pip-content-1");
56+
});
57+
});
58+
59+
describe("and rendering PiP content 2", () => {
60+
beforeEach(() => {
61+
renderResult.rerender(<PictureInPictureDragger draggable={true}>{mkContent2}</PictureInPictureDragger>);
62+
});
63+
64+
it("should update the PiP content", () => {
65+
expect(renderResult.container).toMatchSnapshot();
66+
});
67+
});
68+
});
69+
});
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
// Jest Snapshot v1, https://goo.gl/fbAQLP
2+
3+
exports[`PictureInPictureDragger when rendering the dragger with PiP content 1 and rendering PiP content 2 should update the PiP content 1`] = `
4+
<div>
5+
<aside
6+
style="transform: translateX(680px) translateY(478px);"
7+
>
8+
<div>
9+
content 2
10+
<br />
11+
content 2.2
12+
</div>
13+
</aside>
14+
</div>
15+
`;
16+
17+
exports[`PictureInPictureDragger when rendering the dragger with PiP content 1 and rerendering PiP content 1 should not change the PiP content: pip-content-1 1`] = `
18+
<div>
19+
<aside
20+
style="transform: translateX(680px) translateY(478px);"
21+
>
22+
<div>
23+
content 1
24+
</div>
25+
</aside>
26+
</div>
27+
`;
28+
29+
exports[`PictureInPictureDragger when rendering the dragger with PiP content 1 should render the PiP content: pip-content-1 1`] = `
30+
<div>
31+
<aside
32+
style="transform: translateX(680px) translateY(478px);"
33+
>
34+
<div>
35+
content 1
36+
</div>
37+
</aside>
38+
</div>
39+
`;

0 commit comments

Comments
 (0)