Skip to content
This repository was archived by the owner on Dec 7, 2024. It is now read-only.

Commit 6ab235f

Browse files
committed
Fix tests for new call path
We have to mock `fetch` for the caching of the download icon, and then mock out all the function calls used by components to feed a Media object.
1 parent 90817f3 commit 6ab235f

File tree

7 files changed

+40
-0
lines changed

7 files changed

+40
-0
lines changed

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,7 @@
157157
"jest": "^26.6.3",
158158
"jest-canvas-mock": "^2.3.0",
159159
"jest-environment-jsdom-sixteen": "^1.0.3",
160+
"jest-fetch-mock": "^3.0.3",
160161
"matrix-mock-request": "^1.2.3",
161162
"matrix-react-test-utils": "^0.2.2",
162163
"olm": "https://packages.matrix.org/npm/olm/olm-3.2.1.tgz",

test/components/structures/MessagePanel-test.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,7 @@ describe('MessagePanel', function() {
116116
getAvatarUrl: () => {
117117
return "avatar.jpeg";
118118
},
119+
getMxcAvatarUrl: () => 'mxc://avatar.url/image.png',
119120
},
120121
ts: ts0 + i*1000,
121122
mship: 'join',
@@ -148,6 +149,7 @@ describe('MessagePanel', function() {
148149
getAvatarUrl: () => {
149150
return "avatar.jpeg";
150151
},
152+
getMxcAvatarUrl: () => 'mxc://avatar.url/image.png',
151153
},
152154
ts: ts0 + i*1000,
153155
mship: 'join',
@@ -193,6 +195,7 @@ describe('MessagePanel', function() {
193195
getAvatarUrl: () => {
194196
return "avatar.jpeg";
195197
},
198+
getMxcAvatarUrl: () => 'mxc://avatar.url/image.png',
196199
},
197200
ts: ts0 + 1,
198201
mship: 'join',
@@ -239,6 +242,7 @@ describe('MessagePanel', function() {
239242
getAvatarUrl: () => {
240243
return "avatar.jpeg";
241244
},
245+
getMxcAvatarUrl: () => 'mxc://avatar.url/image.png',
242246
},
243247
ts: ts0 + 5,
244248
mship: 'invite',

test/components/views/elements/MemberEventListSummary-test.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ describe('MemberEventListSummary', function() {
5050
getAvatarUrl: () => {
5151
return "avatar.jpeg";
5252
},
53+
getMxcAvatarUrl: () => 'mxc://avatar.url/image.png',
5354
},
5455
});
5556
// Override random event ID to allow for equality tests against tiles from

test/components/views/messages/TextualBody-test.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ describe("<TextualBody />", () => {
3737
getRoom: () => mkStubRoom("room_id"),
3838
getAccountData: () => undefined,
3939
isGuest: () => false,
40+
mxcUrlToHttp: (s) => s,
4041
};
4142

4243
const ev = mkEvent({
@@ -61,6 +62,7 @@ describe("<TextualBody />", () => {
6162
getRoom: () => mkStubRoom("room_id"),
6263
getAccountData: () => undefined,
6364
isGuest: () => false,
65+
mxcUrlToHttp: (s) => s,
6466
};
6567

6668
const ev = mkEvent({
@@ -86,6 +88,7 @@ describe("<TextualBody />", () => {
8688
getRoom: () => mkStubRoom("room_id"),
8789
getAccountData: () => undefined,
8890
isGuest: () => false,
91+
mxcUrlToHttp: (s) => s,
8992
};
9093
});
9194

@@ -139,6 +142,7 @@ describe("<TextualBody />", () => {
139142
on: () => undefined,
140143
removeListener: () => undefined,
141144
isGuest: () => false,
145+
mxcUrlToHttp: (s) => s,
142146
};
143147
});
144148

@@ -284,6 +288,7 @@ describe("<TextualBody />", () => {
284288
getAccountData: () => undefined,
285289
getUrlPreview: (url) => new Promise(() => {}),
286290
isGuest: () => false,
291+
mxcUrlToHttp: (s) => s,
287292
};
288293

289294
const ev = mkEvent({

test/setupTests.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,5 @@ import * as languageHandler from "../src/languageHandler";
22

33
languageHandler.setLanguage('en');
44
languageHandler.setMissingEntryGenerator(key => key.split("|", 2)[1]);
5+
6+
require('jest-fetch-mock').enableMocks();

test/test-utils.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -213,6 +213,7 @@ export function mkStubRoom(roomId = null) {
213213
rawDisplayName: 'Member',
214214
roomId: roomId,
215215
getAvatarUrl: () => 'mxc://avatar.url/image.png',
216+
getMxcAvatarUrl: () => 'mxc://avatar.url/image.png',
216217
}),
217218
getMembersWithMembership: jest.fn().mockReturnValue([]),
218219
getJoinedMembers: jest.fn().mockReturnValue([]),
@@ -242,6 +243,7 @@ export function mkStubRoom(roomId = null) {
242243
removeListener: jest.fn(),
243244
getDMInviter: jest.fn(),
244245
getAvatarUrl: () => 'mxc://avatar.url/room.png',
246+
getMxcAvatarUrl: () => 'mxc://avatar.url/room.png',
245247
};
246248
}
247249

yarn.lock

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2589,6 +2589,13 @@ crc-32@^0.3.0:
25892589
resolved "https://registry.yarnpkg.com/crc-32/-/crc-32-0.3.0.tgz#6a3d3687f5baec41f7e9b99fe1953a2e5d19775e"
25902590
integrity sha1-aj02h/W67EH36bmf4ZU6Ll0Zd14=
25912591

2592+
cross-fetch@^3.0.4:
2593+
version "3.0.6"
2594+
resolved "https://registry.yarnpkg.com/cross-fetch/-/cross-fetch-3.0.6.tgz#3a4040bc8941e653e0e9cf17f29ebcd177d3365c"
2595+
integrity sha512-KBPUbqgFjzWlVcURG+Svp9TlhA5uliYtiNx/0r8nv0pdypeQCRJ9IaSIc3q/x3q8t3F75cHuwxVql1HFGHCNJQ==
2596+
dependencies:
2597+
node-fetch "2.6.1"
2598+
25922599
cross-spawn@^6.0.0, cross-spawn@^6.0.5:
25932600
version "6.0.5"
25942601
resolved "https://registry.yarnpkg.com/cross-spawn/-/cross-spawn-6.0.5.tgz#4a5ec7c64dfae22c3a14124dbacdee846d80cbc4"
@@ -4918,6 +4925,14 @@ jest-environment-node@^26.6.2:
49184925
jest-mock "^26.6.2"
49194926
jest-util "^26.6.2"
49204927

4928+
jest-fetch-mock@^3.0.3:
4929+
version "3.0.3"
4930+
resolved "https://registry.yarnpkg.com/jest-fetch-mock/-/jest-fetch-mock-3.0.3.tgz#31749c456ae27b8919d69824f1c2bd85fe0a1f3b"
4931+
integrity sha512-Ux1nWprtLrdrH4XwE7O7InRY6psIi3GOsqNESJgMJ+M5cv4A8Lh7SN9d2V2kKRZ8ebAfcd1LNyZguAOb6JiDqw==
4932+
dependencies:
4933+
cross-fetch "^3.0.4"
4934+
promise-polyfill "^8.1.3"
4935+
49214936
jest-get-type@^26.3.0:
49224937
version "26.3.0"
49234938
resolved "https://registry.yarnpkg.com/jest-get-type/-/jest-get-type-26.3.0.tgz#e97dc3c3f53c2b406ca7afaed4493b1d099199e0"
@@ -5835,6 +5850,11 @@ nice-try@^1.0.4:
58355850
resolved "https://registry.yarnpkg.com/nice-try/-/nice-try-1.0.5.tgz#a3378a7696ce7d223e88fc9b764bd7ef1089e366"
58365851
integrity sha512-1nh45deeb5olNY7eX82BkPO7SSxR5SSYJiPTrTdFUVYwAl8CKMA5N9PjTYkHiRjisVcxcQ1HXdLhx2qxxJzLNQ==
58375852

5853+
node-fetch@2.6.1:
5854+
version "2.6.1"
5855+
resolved "https://registry.yarnpkg.com/node-fetch/-/node-fetch-2.6.1.tgz#045bd323631f76ed2e2b55573394416b639a0052"
5856+
integrity sha512-V4aYg89jEoVRxRb2fJdAg8FHvI7cEyYdVAh94HH0UIK8oJxUfkjlDQN9RbMx+bEjP7+ggMiFRprSti032Oipxw==
5857+
58385858
node-fetch@^1.0.1:
58395859
version "1.7.3"
58405860
resolved "https://registry.yarnpkg.com/node-fetch/-/node-fetch-1.7.3.tgz#980f6f72d85211a5347c6b2bc18c5b84c3eb47ef"
@@ -6448,6 +6468,11 @@ progress@^2.0.0:
64486468
resolved "https://registry.yarnpkg.com/progress/-/progress-2.0.3.tgz#7e8cf8d8f5b8f239c1bc68beb4eb78567d572ef8"
64496469
integrity sha512-7PiHtLll5LdnKIMw100I+8xJXR5gW2QwWYkT6iJva0bXitZKa/XMrSbdmg3r2Xnaidz9Qumd0VPaMrZlF9V9sA==
64506470

6471+
promise-polyfill@^8.1.3:
6472+
version "8.2.0"
6473+
resolved "https://registry.yarnpkg.com/promise-polyfill/-/promise-polyfill-8.2.0.tgz#367394726da7561457aba2133c9ceefbd6267da0"
6474+
integrity sha512-k/TC0mIcPVF6yHhUvwAp7cvL6I2fFV7TzF1DuGPI8mBh4QQazf36xCKEHKTZKRysEoTQoQdKyP25J8MPJp7j5g==
6475+
64516476
promise@^7.0.3, promise@^7.1.1:
64526477
version "7.3.1"
64536478
resolved "https://registry.yarnpkg.com/promise/-/promise-7.3.1.tgz#064b72602b18f90f29192b8b1bc418ffd1ebd3bf"

0 commit comments

Comments
 (0)