Add test for renderToString

pull/21833/head
Jaiwanth 2021-08-09 13:24:54 +05:30
parent b3c03c9b68
commit 900accd823
2 changed files with 14 additions and 4 deletions

View File

@ -48,6 +48,7 @@ export default class PlainTextExporter extends Exporter {
const match = REPLY_REGEX.exec(content.body); const match = REPLY_REGEX.exec(content.body);
// if the reply format is invalid, then return the body
if (!match) return content.body; if (!match) return content.body;
let rplSource: string; let rplSource: string;

View File

@ -14,13 +14,15 @@ See the License for the specific language governing permissions and
limitations under the License. limitations under the License.
*/ */
import { IContent, MatrixClient, Room } from "matrix-js-sdk"; import { IContent, MatrixClient, MatrixEvent, Room } from "matrix-js-sdk";
import { MatrixClientPeg } from "../../src/MatrixClientPeg"; import { MatrixClientPeg } from "../../src/MatrixClientPeg";
import { textForFormat, IExportOptions, ExportTypes } from "../../src/utils/exportUtils/exportUtils"; import { textForFormat, IExportOptions, ExportTypes } from "../../src/utils/exportUtils/exportUtils";
import '../skinned-sdk'; import '../skinned-sdk';
import PlainTextExporter from "../../src/utils/exportUtils/PlainTextExport"; import PlainTextExporter from "../../src/utils/exportUtils/PlainTextExport";
import HTMLExporter from "../../src/utils/exportUtils/HtmlExport";
import * as TestUtilsMatrix from '../test-utils'; import * as TestUtilsMatrix from '../test-utils';
import { stubClient } from '../test-utils'; import { stubClient } from '../test-utils';
import { renderToString } from "react-dom/server";
let client: MatrixClient; let client: MatrixClient;
@ -65,9 +67,8 @@ describe('export', function() {
}, },
]; ];
const events = mkEvents(); const events: MatrixEvent[] = mkEvents();
const room = createRoom(); const room = createRoom();
console.log(events);
function createRoom() { function createRoom() {
const room = new Room(generateRoomId(), null, client.getUserId()); const room = new Room(generateRoomId(), null, client.getUserId());
return room; return room;
@ -131,7 +132,7 @@ describe('export', function() {
}, },
{ {
"msgtype": "m.text", "msgtype": "m.text",
// if the reply format is invalid, then return the original string as it is // if the reply format is invalid, then return the body
"body": "Invalid reply format", "body": "Invalid reply format",
"expectedText": "Invalid reply format", "expectedText": "Invalid reply format",
}, },
@ -151,5 +152,13 @@ describe('export', function() {
expect(exporter.textForReplyEvent(content)).toBe(content.expectedText); expect(exporter.textForReplyEvent(content)).toBe(content.expectedText);
} }
}); });
it('checks if the render to string works for eventTile', function() {
// Todo: Generate different event types
const exporter = new HTMLExporter(room, ExportTypes.BEGINNING, mockExportOptions, null);
for (const event of events) {
expect(renderToString(exporter.getEventTile(event, false))).toBeTruthy();
}
});
}); });