Skip to content

Commit

Permalink
improve mxc in tests
Browse files Browse the repository at this point in the history
Signed-off-by: Ahmad Kadri <ahmad.kadri@nordeck.net>
  • Loading branch information
ahmadkadri committed Oct 8, 2024
1 parent e10672b commit 239f8f8
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 12 deletions.
2 changes: 1 addition & 1 deletion example-widget-mui/src/ImagePage/ImagePage.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ describe('<ImagePage>', () => {
widgetApi.sendRoomEvent(ROOM_EVENT_UPLOADED_IMAGE, {
name: 'image.png',
size: 123,
url: 'mxc://...',
url: 'mxc://example.com/imageACSshaw',
});

render(<ImagePage />, { wrapper });
Expand Down
12 changes: 8 additions & 4 deletions packages/api/src/api/WidgetApiImpl.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2173,7 +2173,7 @@ describe('WidgetApiImpl', () => {
{
user_id: '@user-id',
display_name: 'User',
avatar_url: 'mxc://...',
avatar_url: 'mxc://example.com/imageACSshaw',
},
],
});
Expand All @@ -2182,7 +2182,11 @@ describe('WidgetApiImpl', () => {
widgetApi.searchUserDirectory('user', { limit: 5 }),
).resolves.toEqual({
results: [
{ userId: '@user-id', displayName: 'User', avatarUrl: 'mxc://...' },
{
userId: '@user-id',
displayName: 'User',
avatarUrl: 'mxc://example.com/imageACSshaw',
},
],
});
expect(matrixWidgetApi.searchUserDirectory).toHaveBeenCalledWith(
Expand Down Expand Up @@ -2222,15 +2226,15 @@ describe('WidgetApiImpl', () => {
describe('uploadFile', () => {
it('should upload a file', async () => {
matrixWidgetApi.uploadFile.mockResolvedValue({
content_uri: 'msx//:example',
content_uri: 'mxc://example.com/imageACSshaw',
});

const file = new File(['file content'], 'test-image.png', {
type: 'image/png',
});

await expect(widgetApi.uploadFile(file)).resolves.toEqual({
content_uri: 'msx//:example',
content_uri: 'mxc://example.com/imageACSshaw',
});
expect(matrixWidgetApi.uploadFile).toHaveBeenCalled();
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ describe('<ElementAvatar>', () => {
<ElementAvatar
userId="@user-alice"
displayName="Alice"
avatarUrl={'mxc://alice'}
avatarUrl={'mxc://example.com/imageAlice'}
/>,
);

Expand All @@ -41,7 +41,7 @@ describe('<ElementAvatar>', () => {
<ElementAvatar
userId="@user-alice"
displayName="Alice"
avatarUrl={'mxc://alice'}
avatarUrl={'mxc://example.com/imageAlice'}
/>,
);

Expand All @@ -57,15 +57,15 @@ describe('<ElementAvatar>', () => {
<ElementAvatar
userId="@user-alice"
displayName="Alice"
avatarUrl={'mxc://alice'}
avatarUrl={'mxc://example.com/imageAlice'}
/>,
);

await expect(
screen.findByRole('presentation', { hidden: true }),
).resolves.toHaveAttribute(
'src',
expect.stringMatching(/\/_matrix\/media\/r0\/thumbnail\/alice/i),
expect.stringMatching(/\/_matrix\/media\/r0\/thumbnail\/.*\/imageAlice/i),
);
});

Expand Down
6 changes: 4 additions & 2 deletions packages/testing/src/api/mockWidgetApi.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -968,13 +968,15 @@ describe('getMediaConfig', () => {
describe('uploadFile', () => {
it('should return empty response', async () => {
await expect(widgetApi.uploadFile('data')).resolves.toEqual({
content_uri: 'mxc://...',
content_uri: 'mxc://example.com/imageACSshaw',
});
});

describe('downloadFile', () => {
it('should return empty response', async () => {
await expect(widgetApi.downloadFile('mxc://...')).resolves.toEqual({
await expect(
widgetApi.downloadFile('mxc://example.com/imageACSshaw'),
).resolves.toEqual({
file: new Blob(['image content'], { type: 'image/png' }),
});
});
Expand Down
2 changes: 1 addition & 1 deletion packages/testing/src/api/mockWidgetApi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -243,7 +243,7 @@ export function mockWidgetApi(opts?: {
searchUserDirectory: vi.fn().mockResolvedValue({ results: [] }),
getMediaConfig: vi.fn().mockResolvedValue({}),
uploadFile: vi.fn().mockResolvedValue({
content_uri: 'mxc://...',
content_uri: 'mxc://example.com/imageACSshaw',
}),
downloadFile: vi.fn().mockResolvedValue({
file: new Blob(['image content'], { type: 'image/png' }),
Expand Down

0 comments on commit 239f8f8

Please sign in to comment.