Skip to content

Commit

Permalink
Fix CI
Browse files Browse the repository at this point in the history
  • Loading branch information
domdomegg committed Apr 7, 2024
1 parent 8b49d76 commit 70b621b
Show file tree
Hide file tree
Showing 7 changed files with 5,389 additions and 6,316 deletions.
2 changes: 1 addition & 1 deletion frontend/setup.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import { FieldType } from "@airtable/blocks/models";
import React, { useMemo, useState } from "react";
import { Preset } from ".";
import { MS_IN_WEEK, MINUTES_IN_UNIT } from "../lib/constants";
import { renderDuration } from "../lib/format";
import { renderDuration } from "../lib/renderDuration";
import { newUID } from "../lib/util";
import { FixedNumberInput } from "./components/FixedNumberInput";

Expand Down
21 changes: 21 additions & 0 deletions lib/expectInteger.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import { describe, expect, test } from 'vitest';
import { expectInteger } from './expectInteger';

describe('expectInteger', () => {
test('should return the number if it is an integer', () => {
const input = 42;
const result = expectInteger(input, '');
expect(result).toBe(input);
});

test('should throw an error if the number is not an integer', () => {
const input = 3.14;
const errorMessage = 'Input must be an integer';
expect(() => expectInteger(input, errorMessage)).toThrow(errorMessage);
});

test('should use the default error message if no error message is provided', () => {
const input = 2.5;
expect(() => expectInteger(input)).toThrow('Not an integer');
});
});
2 changes: 1 addition & 1 deletion lib/expectInteger.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
export const expectInteger = (n: number, error: string): number => {
export const expectInteger = (n: number, error?: string): number => {
if (n !== Math.round(n)) {
throw new Error(error ?? 'Not an integer')
}
Expand Down
35 changes: 35 additions & 0 deletions lib/renderDuration.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import { describe, expect, test } from 'vitest';
import { renderDuration } from './renderDuration';

describe('renderDuration', () => {
test('should return the duration in milliseconds for values less than 1000', () => {
expect(renderDuration(500)).toBe('500ms');
expect(renderDuration(0)).toBe('0ms');
});

test('should return the duration in seconds for values between 1000 and 60000', () => {
expect(renderDuration(1000)).toBe('1s');
expect(renderDuration(30000)).toBe('30s');
expect(renderDuration(59000)).toBe('59s');
});

test('should return the duration in minutes for values between 60000 and 3600000', () => {
expect(renderDuration(60000)).toBe('1m');
expect(renderDuration(80000)).toBe('1m');
expect(renderDuration(120000)).toBe('2m');
expect(renderDuration(3540000)).toBe('59m');
});

test('should return the duration in hours and minutes for values greater than 3600000', () => {
expect(renderDuration(3600000)).toBe('1h:00m');
expect(renderDuration(7200000)).toBe('2h:00m');
expect(renderDuration(10800000)).toBe('3h:00m');
expect(renderDuration(86400000)).toBe('24h:00m');
});

test('should handle negative values by prefixing with a minus sign', () => {
expect(renderDuration(-500)).toBe('-500ms');
expect(renderDuration(-60000)).toBe('-1m');
expect(renderDuration(-3600000)).toBe('-1h:00m');
});
});
File renamed without changes.
Loading

0 comments on commit 70b621b

Please sign in to comment.