mirror of
https://github.com/owncast/owncast.git
synced 2024-10-10 19:16:02 +00:00
Merge 345423715f76ac991e6a7176aecb5fbea882633c into f0323731dd3007c65a5cf940837ab41d96ddc940
This commit is contained in:
commit
cac10f47a6
@ -18,8 +18,9 @@ export type StatusbarProps = {
|
|||||||
className?: string;
|
className?: string;
|
||||||
};
|
};
|
||||||
|
|
||||||
function makeDurationString(lastConnectTime: Date): string {
|
export function makeDurationString(lastConnectTime: Date): string {
|
||||||
const diff = intervalToDuration({ start: lastConnectTime, end: new Date() });
|
const diff = intervalToDuration({ start: lastConnectTime, end: new Date() });
|
||||||
|
|
||||||
if (diff.days >= 1) {
|
if (diff.days >= 1) {
|
||||||
return formatDuration({
|
return formatDuration({
|
||||||
days: diff.days,
|
days: diff.days,
|
||||||
|
|||||||
27
web/tests/statusbar.test.ts
Normal file
27
web/tests/statusbar.test.ts
Normal file
@ -0,0 +1,27 @@
|
|||||||
|
import { makeDurationString } from "../components/ui/Statusbar/Statusbar";
|
||||||
|
|
||||||
|
// Testing the string displayed on the statusbar
|
||||||
|
describe('testStatusbar', () => {
|
||||||
|
test('function should return a string', () => {
|
||||||
|
const typeResult = makeDurationString(new Date(2005, 0, 24));
|
||||||
|
expect(typeof typeResult).toBe('string');
|
||||||
|
});
|
||||||
|
|
||||||
|
test('function should not return a string that contains undefined', () => {
|
||||||
|
let count = 0;
|
||||||
|
while (count < 100) {
|
||||||
|
const result = makeDurationString(randomDate);
|
||||||
|
expect(result).not.toContain("undefined");
|
||||||
|
count++;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
const randomDate = getRandomDate(Date.now()-30, Date.now(), 0, 24);
|
||||||
|
|
||||||
|
function getRandomDate(start, end, startHour, endHour): Date {
|
||||||
|
var date = new Date(+start + Math.random() * (end - start));
|
||||||
|
var hour = startHour + Math.random() * (endHour - startHour) | 0;
|
||||||
|
date.setHours(hour);
|
||||||
|
return date;
|
||||||
|
}
|
||||||
Loading…
x
Reference in New Issue
Block a user