Implement download_file in widget driver (#12931)

* Implement download_file in widget driver

Signed-off-by: Michael Weimann <michael.weimann@nordeck.net>

* Fix test URIs

Signed-off-by: Michael Weimann <michael.weimann@nordeck.net>

* Use download-file branch as widget-api source

Signed-off-by: Michael Weimann <michael.weimann@nordeck.net>

* bump matrix-widget-api to 1.9.0

Signed-off-by: Kim Brose <kim.brose@nordeck.net>

* prettier

Signed-off-by: Kim Brose <kim.brose@nordeck.net>

---------

Signed-off-by: Michael Weimann <michael.weimann@nordeck.net>
Signed-off-by: Kim Brose <kim.brose@nordeck.net>
Co-authored-by: Kim Brose <kim.brose@nordeck.net>
This commit is contained in:
Michael Weimann 2024-08-30 16:45:25 +02:00 committed by GitHub
parent 2a450c095c
commit 19f8b44745
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 53 additions and 1 deletions

View file

@ -15,6 +15,7 @@ limitations under the License.
*/
import { mocked, MockedObject } from "jest-mock";
import fetchMockJest from "fetch-mock-jest";
import {
MatrixClient,
ClientEvent,
@ -616,4 +617,32 @@ describe("StopGapWidgetDriver", () => {
expect(client.uploadContent).toHaveBeenCalledWith("data");
});
});
describe("downloadFile", () => {
let driver: WidgetDriver;
beforeEach(() => {
driver = mkDefaultDriver();
});
it("should download a file and return the blob", async () => {
// eslint-disable-next-line no-restricted-properties
client.mxcUrlToHttp.mockImplementation((mxcUrl) => {
if (mxcUrl === "mxc://example.com/test_file") {
return "https://example.com/_matrix/media/v3/download/example.com/test_file";
}
return null;
});
fetchMockJest.get("https://example.com/_matrix/media/v3/download/example.com/test_file", "test contents");
const result = await driver.downloadFile("mxc://example.com/test_file");
// A type test is impossible here because of
// https://github.com/jefflau/jest-fetch-mock/issues/209
// Tell TypeScript that file is a blob.
const file = result.file as Blob;
await expect(file.text()).resolves.toEqual("test contents");
});
});
});