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

Commit

Permalink
Add new button visibility tests
Browse files Browse the repository at this point in the history
Signed-off-by: Šimon Brandner <[email protected]>
  • Loading branch information
SimonBrandner committed May 10, 2022
1 parent 38d9dbc commit b73dd49
Showing 1 changed file with 155 additions and 1 deletion.
156 changes: 155 additions & 1 deletion test/components/views/context_menus/MessageContextMenu-test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,162 @@ describe('MessageContextMenu', () => {
const menu = createMenuWithContent(eventContent);
expect(menu.find('div[aria-label="Forward"]')).toHaveLength(0);
});
});

it('does show copy link button when supplied a link', () => {
const eventContent = MessageEvent.from("hello");
const props = {
link: "https://google.com/",
};
const menu = createMenuWithContent(eventContent, props);
const copyLinkButton = menu.find('a[aria-label="Copy link"]');
expect(copyLinkButton).toHaveLength(1);
expect((copyLinkButton.getDOMNode() as HTMLAnchorElement)?.href).toBe(props.link);
});

it('does not show copy link button when not supplied a link', () => {
const eventContent = MessageEvent.from("hello");
const menu = createMenuWithContent(eventContent);
const copyLinkButton = menu.find('a[aria-label="Copy link"]');
expect(copyLinkButton).toHaveLength(0);
});

it('(right click) copy button does work as expected', () => {
const text = "hello";
const eventContent = MessageEvent.from(text);
const props = {
rightClick: true,
};
getSelectedText.mockReturnValue(text);

const menu = createMenuWithContent(eventContent, props);
const copyButton = menu.find('div[aria-label="Copy"]');
copyButton.simulate("mousedown");
expect(copyPlaintext).toHaveBeenCalledWith(text);
});

it('(right click) copy button is not shown when there is nothing to copy', () => {
const text = "hello";
const eventContent = MessageEvent.from(text);
const props = {
rightClick: true,
};
getSelectedText.mockReturnValue("");

const menu = createMenuWithContent(eventContent, props);
const copyButton = menu.find('div[aria-label="Copy"]');
expect(copyButton).toHaveLength(0);
});

it('(right click) shows edit button when we can edit', () => {
const eventContent = MessageEvent.from("hello");
const props = {
rightClick: true,
};
canEditContent.mockReturnValue(true);

const menu = createMenuWithContent(eventContent, props);
const editButton = menu.find('div[aria-label="Edit"]');
expect(editButton).toHaveLength(1);
});

it('(right click) does not show edit button when we cannot edit', () => {
const eventContent = MessageEvent.from("hello");
const props = {
rightClick: true,
};
canEditContent.mockReturnValue(false);

const menu = createMenuWithContent(eventContent, props);
const editButton = menu.find('div[aria-label="Edit"]');
expect(editButton).toHaveLength(0);
});

it('(right click) shows reply button when we can reply', () => {
const eventContent = MessageEvent.from("hello");
const props = {
rightClick: true,
};
const context = {
canSendMessages: true,
};
isContentActionable.mockReturnValue(true);

const menu = createMenuWithContent(eventContent, props, context);
const replyButton = menu.find('div[aria-label="Reply"]');
expect(replyButton).toHaveLength(1);
});

it('(right click) does not show reply button when we cannot reply', () => {
const eventContent = MessageEvent.from("hello");
const props = {
rightClick: true,
};
const context = {
canSendMessages: true,
};
isContentActionable.mockReturnValue(false);

const menu = createMenuWithContent(eventContent, props, context);
const replyButton = menu.find('div[aria-label="Reply"]');
expect(replyButton).toHaveLength(0);
});

it('(right click) shows react button when we can react', () => {
const eventContent = MessageEvent.from("hello");
const props = {
rightClick: true,
};
const context = {
canReact: true,
};
isContentActionable.mockReturnValue(true);

const menu = createMenuWithContent(eventContent, props, context);
const reactButton = menu.find('div[aria-label="React"]');
expect(reactButton).toHaveLength(1);
});

it('(right click) does not show react button when we cannot react', () => {
const eventContent = MessageEvent.from("hello");
const props = {
rightClick: true,
};
const context = {
canReact: false,
};

const menu = createMenuWithContent(eventContent, props, context);
const reactButton = menu.find('div[aria-label="React"]');
expect(reactButton).toHaveLength(0);
});

it('(right click) shows view in room button when the event is a thread root', () => {
const eventContent = MessageEvent.from("hello");
const mxEvent = new MatrixEvent(eventContent.serialize());
mxEvent.getThread = () => ({ rootEvent: mxEvent }) as Thread;
const props = {
rightClick: true,
};
const context = {
timelineRenderingType: TimelineRenderingType.Thread,
};

const menu = createMenu(mxEvent, props, context);
const reactButton = menu.find('div[aria-label="View in room"]');
expect(reactButton).toHaveLength(1);
});

it('(right click) does not show view in room button when the event is not a thread root', () => {
const eventContent = MessageEvent.from("hello");
const props = {
rightClick: true,
};

const menu = createMenuWithContent(eventContent, props);
const reactButton = menu.find('div[aria-label="View in room"]');
expect(reactButton).toHaveLength(0);
});
});

function createMenuWithContent(
eventContent: ExtensibleEvent,
Expand Down

0 comments on commit b73dd49

Please sign in to comment.