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.
This commit is contained in:
parent
90817f3bc6
commit
6ab235f10c
7 changed files with 40 additions and 0 deletions
|
@ -157,6 +157,7 @@
|
||||||
"jest": "^26.6.3",
|
"jest": "^26.6.3",
|
||||||
"jest-canvas-mock": "^2.3.0",
|
"jest-canvas-mock": "^2.3.0",
|
||||||
"jest-environment-jsdom-sixteen": "^1.0.3",
|
"jest-environment-jsdom-sixteen": "^1.0.3",
|
||||||
|
"jest-fetch-mock": "^3.0.3",
|
||||||
"matrix-mock-request": "^1.2.3",
|
"matrix-mock-request": "^1.2.3",
|
||||||
"matrix-react-test-utils": "^0.2.2",
|
"matrix-react-test-utils": "^0.2.2",
|
||||||
"olm": "https://packages.matrix.org/npm/olm/olm-3.2.1.tgz",
|
"olm": "https://packages.matrix.org/npm/olm/olm-3.2.1.tgz",
|
||||||
|
|
|
@ -116,6 +116,7 @@ describe('MessagePanel', function() {
|
||||||
getAvatarUrl: () => {
|
getAvatarUrl: () => {
|
||||||
return "avatar.jpeg";
|
return "avatar.jpeg";
|
||||||
},
|
},
|
||||||
|
getMxcAvatarUrl: () => 'mxc://avatar.url/image.png',
|
||||||
},
|
},
|
||||||
ts: ts0 + i*1000,
|
ts: ts0 + i*1000,
|
||||||
mship: 'join',
|
mship: 'join',
|
||||||
|
@ -148,6 +149,7 @@ describe('MessagePanel', function() {
|
||||||
getAvatarUrl: () => {
|
getAvatarUrl: () => {
|
||||||
return "avatar.jpeg";
|
return "avatar.jpeg";
|
||||||
},
|
},
|
||||||
|
getMxcAvatarUrl: () => 'mxc://avatar.url/image.png',
|
||||||
},
|
},
|
||||||
ts: ts0 + i*1000,
|
ts: ts0 + i*1000,
|
||||||
mship: 'join',
|
mship: 'join',
|
||||||
|
@ -193,6 +195,7 @@ describe('MessagePanel', function() {
|
||||||
getAvatarUrl: () => {
|
getAvatarUrl: () => {
|
||||||
return "avatar.jpeg";
|
return "avatar.jpeg";
|
||||||
},
|
},
|
||||||
|
getMxcAvatarUrl: () => 'mxc://avatar.url/image.png',
|
||||||
},
|
},
|
||||||
ts: ts0 + 1,
|
ts: ts0 + 1,
|
||||||
mship: 'join',
|
mship: 'join',
|
||||||
|
@ -239,6 +242,7 @@ describe('MessagePanel', function() {
|
||||||
getAvatarUrl: () => {
|
getAvatarUrl: () => {
|
||||||
return "avatar.jpeg";
|
return "avatar.jpeg";
|
||||||
},
|
},
|
||||||
|
getMxcAvatarUrl: () => 'mxc://avatar.url/image.png',
|
||||||
},
|
},
|
||||||
ts: ts0 + 5,
|
ts: ts0 + 5,
|
||||||
mship: 'invite',
|
mship: 'invite',
|
||||||
|
|
|
@ -50,6 +50,7 @@ describe('MemberEventListSummary', function() {
|
||||||
getAvatarUrl: () => {
|
getAvatarUrl: () => {
|
||||||
return "avatar.jpeg";
|
return "avatar.jpeg";
|
||||||
},
|
},
|
||||||
|
getMxcAvatarUrl: () => 'mxc://avatar.url/image.png',
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
// Override random event ID to allow for equality tests against tiles from
|
// Override random event ID to allow for equality tests against tiles from
|
||||||
|
|
|
@ -37,6 +37,7 @@ describe("<TextualBody />", () => {
|
||||||
getRoom: () => mkStubRoom("room_id"),
|
getRoom: () => mkStubRoom("room_id"),
|
||||||
getAccountData: () => undefined,
|
getAccountData: () => undefined,
|
||||||
isGuest: () => false,
|
isGuest: () => false,
|
||||||
|
mxcUrlToHttp: (s) => s,
|
||||||
};
|
};
|
||||||
|
|
||||||
const ev = mkEvent({
|
const ev = mkEvent({
|
||||||
|
@ -61,6 +62,7 @@ describe("<TextualBody />", () => {
|
||||||
getRoom: () => mkStubRoom("room_id"),
|
getRoom: () => mkStubRoom("room_id"),
|
||||||
getAccountData: () => undefined,
|
getAccountData: () => undefined,
|
||||||
isGuest: () => false,
|
isGuest: () => false,
|
||||||
|
mxcUrlToHttp: (s) => s,
|
||||||
};
|
};
|
||||||
|
|
||||||
const ev = mkEvent({
|
const ev = mkEvent({
|
||||||
|
@ -86,6 +88,7 @@ describe("<TextualBody />", () => {
|
||||||
getRoom: () => mkStubRoom("room_id"),
|
getRoom: () => mkStubRoom("room_id"),
|
||||||
getAccountData: () => undefined,
|
getAccountData: () => undefined,
|
||||||
isGuest: () => false,
|
isGuest: () => false,
|
||||||
|
mxcUrlToHttp: (s) => s,
|
||||||
};
|
};
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -139,6 +142,7 @@ describe("<TextualBody />", () => {
|
||||||
on: () => undefined,
|
on: () => undefined,
|
||||||
removeListener: () => undefined,
|
removeListener: () => undefined,
|
||||||
isGuest: () => false,
|
isGuest: () => false,
|
||||||
|
mxcUrlToHttp: (s) => s,
|
||||||
};
|
};
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -284,6 +288,7 @@ describe("<TextualBody />", () => {
|
||||||
getAccountData: () => undefined,
|
getAccountData: () => undefined,
|
||||||
getUrlPreview: (url) => new Promise(() => {}),
|
getUrlPreview: (url) => new Promise(() => {}),
|
||||||
isGuest: () => false,
|
isGuest: () => false,
|
||||||
|
mxcUrlToHttp: (s) => s,
|
||||||
};
|
};
|
||||||
|
|
||||||
const ev = mkEvent({
|
const ev = mkEvent({
|
||||||
|
|
|
@ -2,3 +2,5 @@ import * as languageHandler from "../src/languageHandler";
|
||||||
|
|
||||||
languageHandler.setLanguage('en');
|
languageHandler.setLanguage('en');
|
||||||
languageHandler.setMissingEntryGenerator(key => key.split("|", 2)[1]);
|
languageHandler.setMissingEntryGenerator(key => key.split("|", 2)[1]);
|
||||||
|
|
||||||
|
require('jest-fetch-mock').enableMocks();
|
||||||
|
|
|
@ -213,6 +213,7 @@ export function mkStubRoom(roomId = null) {
|
||||||
rawDisplayName: 'Member',
|
rawDisplayName: 'Member',
|
||||||
roomId: roomId,
|
roomId: roomId,
|
||||||
getAvatarUrl: () => 'mxc://avatar.url/image.png',
|
getAvatarUrl: () => 'mxc://avatar.url/image.png',
|
||||||
|
getMxcAvatarUrl: () => 'mxc://avatar.url/image.png',
|
||||||
}),
|
}),
|
||||||
getMembersWithMembership: jest.fn().mockReturnValue([]),
|
getMembersWithMembership: jest.fn().mockReturnValue([]),
|
||||||
getJoinedMembers: jest.fn().mockReturnValue([]),
|
getJoinedMembers: jest.fn().mockReturnValue([]),
|
||||||
|
@ -242,6 +243,7 @@ export function mkStubRoom(roomId = null) {
|
||||||
removeListener: jest.fn(),
|
removeListener: jest.fn(),
|
||||||
getDMInviter: jest.fn(),
|
getDMInviter: jest.fn(),
|
||||||
getAvatarUrl: () => 'mxc://avatar.url/room.png',
|
getAvatarUrl: () => 'mxc://avatar.url/room.png',
|
||||||
|
getMxcAvatarUrl: () => 'mxc://avatar.url/room.png',
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
25
yarn.lock
25
yarn.lock
|
@ -2589,6 +2589,13 @@ crc-32@^0.3.0:
|
||||||
resolved "https://registry.yarnpkg.com/crc-32/-/crc-32-0.3.0.tgz#6a3d3687f5baec41f7e9b99fe1953a2e5d19775e"
|
resolved "https://registry.yarnpkg.com/crc-32/-/crc-32-0.3.0.tgz#6a3d3687f5baec41f7e9b99fe1953a2e5d19775e"
|
||||||
integrity sha1-aj02h/W67EH36bmf4ZU6Ll0Zd14=
|
integrity sha1-aj02h/W67EH36bmf4ZU6Ll0Zd14=
|
||||||
|
|
||||||
|
cross-fetch@^3.0.4:
|
||||||
|
version "3.0.6"
|
||||||
|
resolved "https://registry.yarnpkg.com/cross-fetch/-/cross-fetch-3.0.6.tgz#3a4040bc8941e653e0e9cf17f29ebcd177d3365c"
|
||||||
|
integrity sha512-KBPUbqgFjzWlVcURG+Svp9TlhA5uliYtiNx/0r8nv0pdypeQCRJ9IaSIc3q/x3q8t3F75cHuwxVql1HFGHCNJQ==
|
||||||
|
dependencies:
|
||||||
|
node-fetch "2.6.1"
|
||||||
|
|
||||||
cross-spawn@^6.0.0, cross-spawn@^6.0.5:
|
cross-spawn@^6.0.0, cross-spawn@^6.0.5:
|
||||||
version "6.0.5"
|
version "6.0.5"
|
||||||
resolved "https://registry.yarnpkg.com/cross-spawn/-/cross-spawn-6.0.5.tgz#4a5ec7c64dfae22c3a14124dbacdee846d80cbc4"
|
resolved "https://registry.yarnpkg.com/cross-spawn/-/cross-spawn-6.0.5.tgz#4a5ec7c64dfae22c3a14124dbacdee846d80cbc4"
|
||||||
|
@ -4918,6 +4925,14 @@ jest-environment-node@^26.6.2:
|
||||||
jest-mock "^26.6.2"
|
jest-mock "^26.6.2"
|
||||||
jest-util "^26.6.2"
|
jest-util "^26.6.2"
|
||||||
|
|
||||||
|
jest-fetch-mock@^3.0.3:
|
||||||
|
version "3.0.3"
|
||||||
|
resolved "https://registry.yarnpkg.com/jest-fetch-mock/-/jest-fetch-mock-3.0.3.tgz#31749c456ae27b8919d69824f1c2bd85fe0a1f3b"
|
||||||
|
integrity sha512-Ux1nWprtLrdrH4XwE7O7InRY6psIi3GOsqNESJgMJ+M5cv4A8Lh7SN9d2V2kKRZ8ebAfcd1LNyZguAOb6JiDqw==
|
||||||
|
dependencies:
|
||||||
|
cross-fetch "^3.0.4"
|
||||||
|
promise-polyfill "^8.1.3"
|
||||||
|
|
||||||
jest-get-type@^26.3.0:
|
jest-get-type@^26.3.0:
|
||||||
version "26.3.0"
|
version "26.3.0"
|
||||||
resolved "https://registry.yarnpkg.com/jest-get-type/-/jest-get-type-26.3.0.tgz#e97dc3c3f53c2b406ca7afaed4493b1d099199e0"
|
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:
|
||||||
resolved "https://registry.yarnpkg.com/nice-try/-/nice-try-1.0.5.tgz#a3378a7696ce7d223e88fc9b764bd7ef1089e366"
|
resolved "https://registry.yarnpkg.com/nice-try/-/nice-try-1.0.5.tgz#a3378a7696ce7d223e88fc9b764bd7ef1089e366"
|
||||||
integrity sha512-1nh45deeb5olNY7eX82BkPO7SSxR5SSYJiPTrTdFUVYwAl8CKMA5N9PjTYkHiRjisVcxcQ1HXdLhx2qxxJzLNQ==
|
integrity sha512-1nh45deeb5olNY7eX82BkPO7SSxR5SSYJiPTrTdFUVYwAl8CKMA5N9PjTYkHiRjisVcxcQ1HXdLhx2qxxJzLNQ==
|
||||||
|
|
||||||
|
node-fetch@2.6.1:
|
||||||
|
version "2.6.1"
|
||||||
|
resolved "https://registry.yarnpkg.com/node-fetch/-/node-fetch-2.6.1.tgz#045bd323631f76ed2e2b55573394416b639a0052"
|
||||||
|
integrity sha512-V4aYg89jEoVRxRb2fJdAg8FHvI7cEyYdVAh94HH0UIK8oJxUfkjlDQN9RbMx+bEjP7+ggMiFRprSti032Oipxw==
|
||||||
|
|
||||||
node-fetch@^1.0.1:
|
node-fetch@^1.0.1:
|
||||||
version "1.7.3"
|
version "1.7.3"
|
||||||
resolved "https://registry.yarnpkg.com/node-fetch/-/node-fetch-1.7.3.tgz#980f6f72d85211a5347c6b2bc18c5b84c3eb47ef"
|
resolved "https://registry.yarnpkg.com/node-fetch/-/node-fetch-1.7.3.tgz#980f6f72d85211a5347c6b2bc18c5b84c3eb47ef"
|
||||||
|
@ -6448,6 +6468,11 @@ progress@^2.0.0:
|
||||||
resolved "https://registry.yarnpkg.com/progress/-/progress-2.0.3.tgz#7e8cf8d8f5b8f239c1bc68beb4eb78567d572ef8"
|
resolved "https://registry.yarnpkg.com/progress/-/progress-2.0.3.tgz#7e8cf8d8f5b8f239c1bc68beb4eb78567d572ef8"
|
||||||
integrity sha512-7PiHtLll5LdnKIMw100I+8xJXR5gW2QwWYkT6iJva0bXitZKa/XMrSbdmg3r2Xnaidz9Qumd0VPaMrZlF9V9sA==
|
integrity sha512-7PiHtLll5LdnKIMw100I+8xJXR5gW2QwWYkT6iJva0bXitZKa/XMrSbdmg3r2Xnaidz9Qumd0VPaMrZlF9V9sA==
|
||||||
|
|
||||||
|
promise-polyfill@^8.1.3:
|
||||||
|
version "8.2.0"
|
||||||
|
resolved "https://registry.yarnpkg.com/promise-polyfill/-/promise-polyfill-8.2.0.tgz#367394726da7561457aba2133c9ceefbd6267da0"
|
||||||
|
integrity sha512-k/TC0mIcPVF6yHhUvwAp7cvL6I2fFV7TzF1DuGPI8mBh4QQazf36xCKEHKTZKRysEoTQoQdKyP25J8MPJp7j5g==
|
||||||
|
|
||||||
promise@^7.0.3, promise@^7.1.1:
|
promise@^7.0.3, promise@^7.1.1:
|
||||||
version "7.3.1"
|
version "7.3.1"
|
||||||
resolved "https://registry.yarnpkg.com/promise/-/promise-7.3.1.tgz#064b72602b18f90f29192b8b1bc418ffd1ebd3bf"
|
resolved "https://registry.yarnpkg.com/promise/-/promise-7.3.1.tgz#064b72602b18f90f29192b8b1bc418ffd1ebd3bf"
|
||||||
|
|
Loading…
Reference in a new issue