Add test for renderToString

This commit is contained in:
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);
// if the reply format is invalid, then return the body
if (!match) return content.body;
let rplSource: string;

View File

@ -14,13 +14,15 @@ See the License for the specific language governing permissions and
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 { textForFormat, IExportOptions, ExportTypes } from "../../src/utils/exportUtils/exportUtils";
import '../skinned-sdk';
import PlainTextExporter from "../../src/utils/exportUtils/PlainTextExport";
import HTMLExporter from "../../src/utils/exportUtils/HtmlExport";
import * as TestUtilsMatrix from '../test-utils';
import { stubClient } from '../test-utils';
import { renderToString } from "react-dom/server";
let client: MatrixClient;
@ -65,9 +67,8 @@ describe('export', function() {
},
];
const events = mkEvents();
const events: MatrixEvent[] = mkEvents();
const room = createRoom();
console.log(events);
function createRoom() {
const room = new Room(generateRoomId(), null, client.getUserId());
return room;
@ -131,7 +132,7 @@ describe('export', function() {
},
{
"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",
"expectedText": "Invalid reply format",
},
@ -151,5 +152,13 @@ describe('export', function() {
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();
}
});
});