Merge 345423715f76ac991e6a7176aecb5fbea882633c into f0323731dd3007c65a5cf940837ab41d96ddc940

This commit is contained in:
zockicookie 2024-10-10 08:32:26 -07:00 committed by GitHub
commit cac10f47a6
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 29 additions and 1 deletions

View File

@ -18,8 +18,9 @@ export type StatusbarProps = {
className?: string;
};
function makeDurationString(lastConnectTime: Date): string {
export function makeDurationString(lastConnectTime: Date): string {
const diff = intervalToDuration({ start: lastConnectTime, end: new Date() });
if (diff.days >= 1) {
return formatDuration({
days: diff.days,

View 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;
}