Add basic plain text editor
This commit is contained in:
parent
6e73a853a8
commit
50279c8870
18 changed files with 316 additions and 62 deletions
|
@ -163,7 +163,7 @@ describe('EditWysiwygComposer', () => {
|
|||
|
||||
// Then
|
||||
const expectedContent = {
|
||||
"body": mockContent,
|
||||
"body": ` * ${mockContent}`,
|
||||
"format": "org.matrix.custom.html",
|
||||
"formatted_body": ` * ${mockContent}`,
|
||||
"m.new_content": {
|
||||
|
|
|
@ -72,7 +72,7 @@ describe('SendWysiwygComposer', () => {
|
|||
return render(
|
||||
<MatrixClientContext.Provider value={mockClient}>
|
||||
<RoomContext.Provider value={defaultRoomContext}>
|
||||
<SendWysiwygComposer onChange={onChange} onSend={onSend} disabled={disabled} />
|
||||
<SendWysiwygComposer onChange={onChange} onSend={onSend} disabled={disabled} isRichTextEnabled={true} />
|
||||
</RoomContext.Provider>
|
||||
</MatrixClientContext.Provider>,
|
||||
);
|
||||
|
|
|
@ -40,11 +40,11 @@ describe('createMessageContent', () => {
|
|||
|
||||
it("Should create html message", () => {
|
||||
// When
|
||||
const content = createMessageContent(message, { permalinkCreator });
|
||||
const content = createMessageContent(message, true, { permalinkCreator });
|
||||
|
||||
// Then
|
||||
expect(content).toEqual({
|
||||
"body": message,
|
||||
"body": "hello world",
|
||||
"format": "org.matrix.custom.html",
|
||||
"formatted_body": message,
|
||||
"msgtype": "m.text",
|
||||
|
@ -53,11 +53,11 @@ describe('createMessageContent', () => {
|
|||
|
||||
it('Should add reply to message content', () => {
|
||||
// When
|
||||
const content = createMessageContent(message, { permalinkCreator, replyToEvent: mockEvent });
|
||||
const content = createMessageContent(message, true, { permalinkCreator, replyToEvent: mockEvent });
|
||||
|
||||
// Then
|
||||
expect(content).toEqual({
|
||||
"body": "> <myfakeuser> Replying to this\n\n<i><b>hello</b> world</i>",
|
||||
"body": "> <myfakeuser> Replying to this\n\nhello world",
|
||||
"format": "org.matrix.custom.html",
|
||||
"formatted_body": "<mx-reply><blockquote><a href=\"$$permalink$$\">In reply to</a>" +
|
||||
" <a href=\"https://matrix.to/#/myfakeuser\">myfakeuser</a>"+
|
||||
|
@ -77,11 +77,11 @@ describe('createMessageContent', () => {
|
|||
rel_type: "m.thread",
|
||||
event_id: "myFakeThreadId",
|
||||
};
|
||||
const content = createMessageContent(message, { permalinkCreator, relation });
|
||||
const content = createMessageContent(message, true, { permalinkCreator, relation });
|
||||
|
||||
// Then
|
||||
expect(content).toEqual({
|
||||
"body": message,
|
||||
"body": "hello world",
|
||||
"format": "org.matrix.custom.html",
|
||||
"formatted_body": message,
|
||||
"msgtype": "m.text",
|
||||
|
@ -110,16 +110,16 @@ describe('createMessageContent', () => {
|
|||
event: true,
|
||||
});
|
||||
const content =
|
||||
createMessageContent(message, { permalinkCreator, editedEvent });
|
||||
createMessageContent(message, true, { permalinkCreator, editedEvent });
|
||||
|
||||
// Then
|
||||
expect(content).toEqual({
|
||||
"body": message,
|
||||
"body": " * hello world",
|
||||
"format": "org.matrix.custom.html",
|
||||
"formatted_body": ` * ${message}`,
|
||||
"msgtype": "m.text",
|
||||
"m.new_content": {
|
||||
"body": message,
|
||||
"body": "hello world",
|
||||
"format": "org.matrix.custom.html",
|
||||
"formatted_body": message,
|
||||
"msgtype": "m.text",
|
||||
|
|
|
@ -65,7 +65,7 @@ describe('message', () => {
|
|||
describe('sendMessage', () => {
|
||||
it('Should not send empty html message', async () => {
|
||||
// When
|
||||
await sendMessage('', { roomContext: defaultRoomContext, mxClient: mockClient, permalinkCreator });
|
||||
await sendMessage('', true, { roomContext: defaultRoomContext, mxClient: mockClient, permalinkCreator });
|
||||
|
||||
// Then
|
||||
expect(mockClient.sendMessage).toBeCalledTimes(0);
|
||||
|
@ -74,11 +74,15 @@ describe('message', () => {
|
|||
|
||||
it('Should send html message', async () => {
|
||||
// When
|
||||
await sendMessage(message, { roomContext: defaultRoomContext, mxClient: mockClient, permalinkCreator });
|
||||
await sendMessage(
|
||||
message,
|
||||
true,
|
||||
{ roomContext: defaultRoomContext, mxClient: mockClient, permalinkCreator },
|
||||
);
|
||||
|
||||
// Then
|
||||
const expectedContent = {
|
||||
"body": "<i><b>hello</b> world</i>",
|
||||
"body": "hello world",
|
||||
"format": "org.matrix.custom.html",
|
||||
"formatted_body": "<i><b>hello</b> world</i>",
|
||||
"msgtype": "m.text",
|
||||
|
@ -97,7 +101,7 @@ describe('message', () => {
|
|||
});
|
||||
|
||||
// When
|
||||
await sendMessage(message, {
|
||||
await sendMessage(message, true, {
|
||||
roomContext: defaultRoomContext,
|
||||
mxClient: mockClient,
|
||||
permalinkCreator,
|
||||
|
@ -112,7 +116,7 @@ describe('message', () => {
|
|||
});
|
||||
|
||||
const expectedContent = {
|
||||
"body": "> <myfakeuser2> My reply\n\n<i><b>hello</b> world</i>",
|
||||
"body": "> <myfakeuser2> My reply\n\nhello world",
|
||||
"format": "org.matrix.custom.html",
|
||||
"formatted_body": "<mx-reply><blockquote><a href=\"$$permalink$$\">In reply to</a>" +
|
||||
" <a href=\"https://matrix.to/#/myfakeuser2\">myfakeuser2</a>" +
|
||||
|
@ -130,7 +134,11 @@ describe('message', () => {
|
|||
it('Should scroll to bottom after sending a html message', async () => {
|
||||
// When
|
||||
SettingsStore.setValue("scrollToBottomOnMessageSent", null, SettingLevel.DEVICE, true);
|
||||
await sendMessage(message, { roomContext: defaultRoomContext, mxClient: mockClient, permalinkCreator });
|
||||
await sendMessage(
|
||||
message,
|
||||
true,
|
||||
{ roomContext: defaultRoomContext, mxClient: mockClient, permalinkCreator },
|
||||
);
|
||||
|
||||
// Then
|
||||
expect(spyDispatcher).toBeCalledWith(
|
||||
|
@ -140,7 +148,11 @@ describe('message', () => {
|
|||
|
||||
it('Should handle emojis', async () => {
|
||||
// When
|
||||
await sendMessage('🎉', { roomContext: defaultRoomContext, mxClient: mockClient, permalinkCreator });
|
||||
await sendMessage(
|
||||
'🎉',
|
||||
false,
|
||||
{ roomContext: defaultRoomContext, mxClient: mockClient, permalinkCreator },
|
||||
);
|
||||
|
||||
// Then
|
||||
expect(spyDispatcher).toBeCalledWith(
|
||||
|
@ -203,7 +215,7 @@ describe('message', () => {
|
|||
// Then
|
||||
const { msgtype, format } = mockEvent.getContent();
|
||||
const expectedContent = {
|
||||
"body": newMessage,
|
||||
"body": ` * ${newMessage}`,
|
||||
"formatted_body": ` * ${newMessage}`,
|
||||
"m.new_content": {
|
||||
"body": "Replying to this new content",
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue