forked from element-hq/element-web
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request element-hq#43 from verji/rm/1921-HoC-part3
Rm/1921 ho c part3
- Loading branch information
Showing
8 changed files
with
266 additions
and
72 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
94 changes: 94 additions & 0 deletions
94
test/components/structures/ReactionsRowButtonTooltip-test.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,94 @@ | ||
/* | ||
Copyright 2024 Verji Tech AS. All rights reserved. | ||
Unauthorized copying or distribution of this file, via any medium, is strictly prohibited. | ||
*/ | ||
|
||
import React from "react"; | ||
import { render, screen } from "@testing-library/react"; | ||
import { MatrixClient, MatrixEvent, Room } from "matrix-js-sdk/src/matrix"; | ||
import { | ||
CustomComponentLifecycle, | ||
CustomComponentOpts, | ||
} from "@matrix-org/react-sdk-module-api/lib/lifecycles/CustomComponentLifecycle"; | ||
|
||
import ReactionsRowButtonTooltip from "../../../src/components/views/messages/ReactionsRowButtonTooltip"; | ||
import { getMockClientWithEventEmitter } from "../../test-utils"; | ||
import MatrixClientContext from "../../../src/contexts/MatrixClientContext"; | ||
import { ModuleRunner } from "../../../src/modules/ModuleRunner"; | ||
|
||
describe("ReactionsRowButtonTooltip", () => { | ||
const content = "Hello world!"; | ||
const reactionEvents = [] as any; | ||
const visible = true; | ||
const roomId = "myRoomId"; | ||
const mockClient = getMockClientWithEventEmitter({ | ||
mxcUrlToHttp: jest.fn().mockReturnValue("https://not.a.real.url"), | ||
getRoom: jest.fn(), | ||
}); | ||
const userId = "@alice:server"; | ||
const room = new Room(roomId, mockClient, userId); | ||
|
||
const customReactionImagesEnabled = true; | ||
|
||
const mxEvent = { | ||
getRoomId: jest.fn().mockReturnValue(roomId), | ||
pushDetails: {}, | ||
_replacingEvent: null, | ||
_localRedactionEvent: null, | ||
_isCancelled: false, | ||
} as unknown as MatrixEvent; | ||
|
||
const getComp = () => | ||
render( | ||
<MatrixClientContext.Provider | ||
value={{ getRoom: jest.fn().mockReturnValue(room) } as unknown as MatrixClient} | ||
> | ||
<ReactionsRowButtonTooltip | ||
mxEvent={mxEvent} | ||
content={content} | ||
reactionEvents={reactionEvents} | ||
visible={visible} | ||
customReactionImagesEnabled={customReactionImagesEnabled} | ||
/> | ||
</MatrixClientContext.Provider>, | ||
); | ||
|
||
beforeEach(() => { | ||
jest.clearAllMocks(); | ||
}); | ||
|
||
it("should render", () => { | ||
const { asFragment } = getComp(); | ||
screen.debug(); | ||
expect(asFragment()).toMatchSnapshot(); | ||
}); | ||
|
||
describe("wrap the ReactionsRowButtonTooltip with a React.Fragment", () => { | ||
it("should wrap the ReactionsRowButtonTooltip with a React.Fragment", () => { | ||
jest.spyOn(ModuleRunner.instance, "invoke").mockImplementation((lifecycleEvent, opts) => { | ||
if (lifecycleEvent === CustomComponentLifecycle.ReactionsRowButtonTooltip) { | ||
(opts as CustomComponentOpts).CustomComponent = ({ children }) => { | ||
return ( | ||
<> | ||
<div data-testid="wrapper-header">Header</div> | ||
<div data-testid="wrapper-ReactionsRowButtonTooltip">{children}</div> | ||
<div data-testid="wrapper-footer">Footer</div> | ||
</> | ||
); | ||
}; | ||
} | ||
}); | ||
|
||
getComp(); | ||
expect(screen.getByTestId("wrapper-header")).toBeDefined(); | ||
expect(screen.getByTestId("wrapper-ReactionsRowButtonTooltip")).toBeDefined(); | ||
expect(screen.getByTestId("wrapper-footer")).toBeDefined(); | ||
expect(screen.getByTestId("wrapper-header").nextSibling).toBe( | ||
screen.getByTestId("wrapper-ReactionsRowButtonTooltip"), | ||
); | ||
expect(screen.getByTestId("wrapper-ReactionsRowButtonTooltip").nextSibling).toBe( | ||
screen.getByTestId("wrapper-footer"), | ||
); | ||
}); | ||
}); | ||
}); |
7 changes: 7 additions & 0 deletions
7
test/components/structures/__snapshots__/ReactionsRowButtonTooltip-test.tsx.snap
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
// Jest Snapshot v1, https://goo.gl/fbAQLP | ||
|
||
exports[`ReactionsRowButtonTooltip should render 1`] = ` | ||
<DocumentFragment> | ||
<div /> | ||
</DocumentFragment> | ||
`; |
Oops, something went wrong.