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

Commit 519ca02

Browse files
committed
Temp
Signed-off-by: Šimon Brandner <[email protected]>
1 parent 644f933 commit 519ca02

File tree

2 files changed

+19
-9
lines changed

2 files changed

+19
-9
lines changed

src/components/views/context_menus/MessageContextMenu.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -248,6 +248,7 @@ export default class MessageContextMenu extends React.Component<IProps, IState>
248248
};
249249

250250
private onCopyClick = (): void => {
251+
console.log("Hello");
251252
copyPlaintext(getSelectedText());
252253
this.closeMenu();
253254
};

test/components/views/context_menus/MessageContextMenu-test.tsx

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1313
See the License for the specific language governing permissions and
1414
limitations under the License.
1515
*/
16+
/* eslint-disable @typescript-eslint/no-var-requires */
1617

1718
import React from 'react';
1819
import { mount } from 'enzyme';
@@ -22,11 +23,18 @@ import { PendingEventOrdering } from 'matrix-js-sdk/src/matrix';
2223
import { ExtensibleEvent, MessageEvent, M_POLL_KIND_DISCLOSED, PollStartEvent } from 'matrix-events-sdk';
2324

2425
import * as TestUtils from '../../../test-utils';
25-
import MessageContextMenu from '../../../../src/components/views/context_menus/MessageContextMenu';
2626
import { MatrixClientPeg } from '../../../../src/MatrixClientPeg';
27-
import { copyPlaintext, getSelectedText } from "../../../../src/utils/strings";
27+
28+
const PATH_TO_STRING_UTILS = "../../../../src/utils/strings";
29+
30+
jest.mock(PATH_TO_STRING_UTILS);
31+
const { copyPlaintext, getSelectedText } = require(PATH_TO_STRING_UTILS);
2832

2933
describe('MessageContextMenu', () => {
34+
beforeAll(() => {
35+
jest.resetAllMocks();
36+
});
37+
3038
it('allows forwarding a room message', () => {
3139
const eventContent = MessageEvent.from("hello");
3240
const menu = createMessageContextMenu(eventContent);
@@ -41,7 +49,7 @@ describe('MessageContextMenu', () => {
4149

4250
it('does show copy link button when supplied a link', () => {
4351
const eventContent = MessageEvent.from("hello");
44-
const props: Partial<React.ComponentProps<typeof MessageContextMenu>> = {
52+
const props = {
4553
link: "https://google.com/",
4654
};
4755
const menu = createMessageContextMenu(eventContent, props);
@@ -52,24 +60,25 @@ describe('MessageContextMenu', () => {
5260

5361
it('does show copy button when we have selected text and we are requesting a right-click menu', () => {
5462
const eventContent = MessageEvent.from("hello");
55-
const props: Partial<React.ComponentProps<typeof MessageContextMenu>> = {
63+
const props = {
5664
rightClick: true,
5765
};
58-
getSelectedText = jest.fn().mockReturnValue("hello");
66+
getSelectedText.mockReturnValue("hello");
67+
5968
const menu = createMessageContextMenu(eventContent, props);
60-
const copyLinkButton = menu.find('a[aria-label="Copy"]').first();
61-
expect(copyLinkButton).toBeDefined();
62-
(copyLinkButton?.getDOMNode() as HTMLDivElement)?.click();
69+
const copyButton = menu.find('div[aria-label="Copy"]');
70+
copyButton.first().first().simulate("click");
6371
expect(copyPlaintext).toHaveBeenCalled();
6472
});
6573
});
6674

6775
function createMessageContextMenu(
6876
eventContent: ExtensibleEvent,
69-
props?: Partial<React.ComponentProps<typeof MessageContextMenu>>,
77+
props?,
7078
) {
7179
TestUtils.stubClient();
7280
const client = MatrixClientPeg.get();
81+
const MessageContextMenu = require("../../../../src/components/views/context_menus/MessageContextMenu")["default"];
7382

7483
const room = new Room(
7584
"roomid",

0 commit comments

Comments
 (0)