Fix unit tests (#2428)

* only create toaster if we're on the browser

* drop/fix references to window

* add back fe unit tests
This commit is contained in:
Severiano Badajoz
2021-09-14 17:43:59 -07:00
committed by GitHub
parent 01013bcf04
commit 0634160c0c
4 changed files with 15 additions and 20 deletions

View File

@@ -1,11 +1,4 @@
export const baseDataURL = "https://a.fake.url/api/v0.2";
window.CELLXGENE = {
API: {
prefix: baseDataURL,
version: "v0.2/",
},
};
export { schema } from "./schema";
export * from "./routes";

View File

@@ -1,31 +1,33 @@
import { Position, Toaster, Intent } from "@blueprintjs/core";
/** Singleton toaster instance. Create separate instances for different options. */
const ToastTopCenter = Toaster.create({
className: "recipe-toaster",
position: Position.TOP,
maxToasts: 4,
});
let ToastTopCenter = null;
if (typeof document !== "undefined") {
ToastTopCenter = Toaster.create({
className: "recipe-toaster",
position: Position.TOP,
maxToasts: 4,
});
}
/*
A "user" error - eg, bad input
*/
export const postUserErrorToast = (message) =>
ToastTopCenter.show({ message, intent: Intent.WARNING });
ToastTopCenter?.show({ message, intent: Intent.WARNING });
/*
A toast the user must dismiss manually, because they need to act on its information,
ie., 8 bulk add genes out of 40 were bad. Manually see which ones and fix.
*/
export const keepAroundErrorToast = (message) =>
ToastTopCenter.show({ message, timeout: 0, intent: Intent.WARNING });
ToastTopCenter?.show({ message, timeout: 0, intent: Intent.WARNING });
/*
a hard network error
*/
export const postNetworkErrorToast = (message, key = undefined) =>
ToastTopCenter.show(
ToastTopCenter?.show(
{
message,
timeout: 30000,
@@ -38,14 +40,14 @@ export const postNetworkErrorToast = (message, key = undefined) =>
Async message to user
*/
export const postAsyncSuccessToast = (message) =>
ToastTopCenter.show({
ToastTopCenter?.show({
message,
timeout: 10000,
intent: Intent.SUCCESS,
});
export const postAsyncFailureToast = (message) =>
ToastTopCenter.show({
ToastTopCenter?.show({
message,
timeout: 10000,
intent: Intent.WARNING,

View File

@@ -102,7 +102,7 @@ const CXG_SERVER_PORT =
let _API;
if (window.CELLXGENE && window.CELLXGENE.API) {
if (typeof window !== "undefined" && window.CELLXGENE && window.CELLXGENE.API) {
_API = window.CELLXGENE.API;
} else {
if (CXG_SERVER_PORT === undefined) {