This commit is contained in:
114
node_modules/react-topbar-progress-indicator/src/__tests__/index.js
generated
vendored
Normal file
114
node_modules/react-topbar-progress-indicator/src/__tests__/index.js
generated
vendored
Normal file
@@ -0,0 +1,114 @@
|
||||
const React = require("react");
|
||||
const renderer = require("react-test-renderer");
|
||||
|
||||
const ReactTopBar = require("../index");
|
||||
|
||||
test("ReactTopBar can show topbar", () => {
|
||||
let count = 0;
|
||||
|
||||
const topbar = {
|
||||
show() {
|
||||
count++;
|
||||
},
|
||||
hide() {}
|
||||
};
|
||||
|
||||
let root;
|
||||
renderer.act(() => {
|
||||
root = renderer.create(
|
||||
React.createElement(ReactTopBar, { topbar: topbar })
|
||||
);
|
||||
});
|
||||
renderer.act(() => {
|
||||
root.unmount();
|
||||
});
|
||||
|
||||
expect(count).toBe(1);
|
||||
});
|
||||
|
||||
test("ReactTopBar can hide topbar", () => {
|
||||
let count = 0;
|
||||
|
||||
const topbar = {
|
||||
show() {},
|
||||
hide() {
|
||||
count++;
|
||||
}
|
||||
};
|
||||
|
||||
let root;
|
||||
renderer.act(() => {
|
||||
root = renderer.create(
|
||||
React.createElement(ReactTopBar, { topbar: topbar })
|
||||
);
|
||||
});
|
||||
renderer.act(() => {
|
||||
root.unmount();
|
||||
});
|
||||
|
||||
expect(count).toBe(1);
|
||||
});
|
||||
|
||||
test("ReactTopBar can show/hide topbar", () => {
|
||||
let count = 0;
|
||||
|
||||
const topbar = {
|
||||
show() {
|
||||
count++;
|
||||
},
|
||||
hide() {
|
||||
count++;
|
||||
}
|
||||
};
|
||||
|
||||
let root;
|
||||
renderer.act(() => {
|
||||
root = renderer.create(
|
||||
React.createElement(ReactTopBar, { topbar: topbar })
|
||||
);
|
||||
});
|
||||
renderer.act(() => {
|
||||
root.unmount();
|
||||
});
|
||||
|
||||
expect(count).toBe(2);
|
||||
});
|
||||
|
||||
test("ReactTopBar can show/hide topbar even with multiples call, but once", () => {
|
||||
let count = 0;
|
||||
|
||||
const topbar = {
|
||||
show() {
|
||||
count++;
|
||||
},
|
||||
hide() {
|
||||
count++;
|
||||
}
|
||||
};
|
||||
|
||||
let root;
|
||||
renderer.act(() => {
|
||||
root = renderer.create(
|
||||
React.createElement(ReactTopBar, { topbar: topbar })
|
||||
);
|
||||
});
|
||||
let root2;
|
||||
renderer.act(() => {
|
||||
root2 = renderer.create(
|
||||
React.createElement(ReactTopBar, { topbar: topbar })
|
||||
);
|
||||
});
|
||||
|
||||
renderer.act(() => {
|
||||
root.unmount();
|
||||
});
|
||||
renderer.act(() => {
|
||||
root2.unmount();
|
||||
});
|
||||
|
||||
expect(count).toBe(2);
|
||||
});
|
||||
|
||||
test("ReactTopBar exposes topbar config function", () => {
|
||||
expect(typeof ReactTopBar.config).toBe("function");
|
||||
});
|
||||
14
node_modules/react-topbar-progress-indicator/src/index.d.ts
generated
vendored
Normal file
14
node_modules/react-topbar-progress-indicator/src/index.d.ts
generated
vendored
Normal file
@@ -0,0 +1,14 @@
|
||||
/// <reference types="react" />
|
||||
|
||||
import * as React from "react";
|
||||
|
||||
export interface TopBarConfig {
|
||||
barThickness?: number;
|
||||
barColors?: any;
|
||||
shadowBlur?: number;
|
||||
shadowColor?: string;
|
||||
}
|
||||
|
||||
export default class TopBarProgress extends React.Component {
|
||||
static config(config: TopBarConfig): void;
|
||||
}
|
||||
47
node_modules/react-topbar-progress-indicator/src/index.js
generated
vendored
Normal file
47
node_modules/react-topbar-progress-indicator/src/index.js
generated
vendored
Normal file
@@ -0,0 +1,47 @@
|
||||
// @flow
|
||||
|
||||
var React = require("react");
|
||||
|
||||
// topbar require window, so here is an universal workaround
|
||||
var topbar =
|
||||
typeof window === "undefined"
|
||||
? {
|
||||
show: function() {},
|
||||
hide: function() {},
|
||||
config: function() {}
|
||||
}
|
||||
: require("topbar");
|
||||
|
||||
var semaphore /*: number*/ = 0;
|
||||
|
||||
/*::
|
||||
type Props = {
|
||||
topbar?: typeof topbar
|
||||
};
|
||||
*/
|
||||
|
||||
var getTopBar = function(props /*: Props*/) /*: typeof topbar*/ {
|
||||
return props.topbar || topbar;
|
||||
};
|
||||
|
||||
function TopBar(props /*: Props */) {
|
||||
React.useEffect(function() {
|
||||
if (semaphore === 0) {
|
||||
getTopBar(props).show();
|
||||
}
|
||||
semaphore++;
|
||||
|
||||
return function() {
|
||||
semaphore--;
|
||||
if (semaphore === 0) {
|
||||
getTopBar(props).hide();
|
||||
}
|
||||
};
|
||||
}, []);
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
TopBar.config = topbar.config;
|
||||
|
||||
module.exports = TopBar;
|
||||
Reference in New Issue
Block a user