Add unit tests

This commit is contained in:
Florian Duros 2022-09-28 12:42:40 +02:00
parent 55450bc0a6
commit ad9cbe9399
No known key found for this signature in database
GPG key ID: 9700AA5870258A0B
2 changed files with 118 additions and 5 deletions

View file

@ -261,7 +261,7 @@ export async function setTheme(theme?: string): Promise<void> {
const styleSheet = styleElements.get(stylesheetName);
styleSheet.disabled = false;
return new Promise((resolve) => {
return new Promise(((resolve, reject) => {
const switchTheme = function() {
// we re-enable our theme here just in case we raced with another
// theme set request as per https://github.com/vector-im/element-web/issues/5601.
@ -307,21 +307,23 @@ export async function setTheme(theme?: string): Promise<void> {
// Avoid to be stuck in an endless loop if there is an issue in the stylesheet loading
counter++;
if (counter === 5) {
if (counter === 10) {
clearInterval(intervalId);
reject();
}
}, 100);
}, 200);
styleSheet.onload = () => {
clearInterval(intervalId);
switchTheme();
};
styleSheet.onerror = () => {
styleSheet.onerror = (e) => {
clearInterval(intervalId);
reject(e);
};
}
waitForStyleSheetLoading();
});
}));
}