mirror of https://github.com/buster-so/buster.git
Merge pull request #1188 from buster-so/big-nate-bus-1959-public-share-url-for-a-chat-doesnt-include-chat-id
Big nate bus 1959 public share url for a chat doesnt include chat
This commit is contained in:
commit
5616ea054f
|
@ -1482,3 +1482,152 @@ export const BarChartWithProblemData: Story = {
|
|||
],
|
||||
},
|
||||
};
|
||||
|
||||
export const BarChartWithSortedDayOfWeek: Story = {
|
||||
args: {
|
||||
colors: [
|
||||
'#B399FD',
|
||||
'#FC8497',
|
||||
'#FBBC30',
|
||||
'#279EFF',
|
||||
'#E83562',
|
||||
'#41F8FF',
|
||||
'#F3864F',
|
||||
'#C82184',
|
||||
'#31FCB4',
|
||||
'#E83562',
|
||||
],
|
||||
barLayout: 'vertical',
|
||||
barSortBy: ['desc'],
|
||||
goalLines: [],
|
||||
gridLines: true,
|
||||
trendlines: [],
|
||||
barGroupType: 'group',
|
||||
xAxisDataZoom: false,
|
||||
barAndLineAxis: {
|
||||
x: ['day_of_week'],
|
||||
y: ['message_count'],
|
||||
category: [],
|
||||
tooltip: null,
|
||||
},
|
||||
columnSettings: {
|
||||
day_of_week: {
|
||||
lineType: 'normal',
|
||||
lineStyle: 'line',
|
||||
lineWidth: 2,
|
||||
barRoundness: 8,
|
||||
lineSymbolSize: 0,
|
||||
showDataLabels: false,
|
||||
columnVisualization: 'bar',
|
||||
showDataLabelsAsPercentage: false,
|
||||
},
|
||||
message_count: {
|
||||
lineType: 'normal',
|
||||
lineStyle: 'line',
|
||||
lineWidth: 2,
|
||||
barRoundness: 8,
|
||||
lineSymbolSize: 0,
|
||||
showDataLabels: false,
|
||||
columnVisualization: 'bar',
|
||||
showDataLabelsAsPercentage: false,
|
||||
},
|
||||
},
|
||||
disableTooltip: false,
|
||||
yAxisScaleType: 'linear',
|
||||
y2AxisScaleType: 'linear',
|
||||
barShowTotalAtTop: false,
|
||||
selectedChartType: 'bar',
|
||||
columnLabelFormats: {
|
||||
day_of_week: {
|
||||
style: 'date',
|
||||
prefix: '',
|
||||
suffix: '',
|
||||
currency: 'USD',
|
||||
columnType: 'number',
|
||||
dateFormat: 'auto',
|
||||
multiplier: 1,
|
||||
displayName: 'Day of Week',
|
||||
compactNumbers: false,
|
||||
convertNumberTo: 'day_of_week',
|
||||
useRelativeTime: false,
|
||||
numberSeparatorStyle: null,
|
||||
maximumFractionDigits: 2,
|
||||
minimumFractionDigits: 0,
|
||||
replaceMissingDataWith: null,
|
||||
} as ColumnLabelFormat,
|
||||
message_count: {
|
||||
style: 'number',
|
||||
prefix: '',
|
||||
suffix: '',
|
||||
currency: 'USD',
|
||||
columnType: 'number',
|
||||
dateFormat: 'auto',
|
||||
multiplier: 1,
|
||||
displayName: 'Messages Sent',
|
||||
compactNumbers: false,
|
||||
useRelativeTime: false,
|
||||
numberSeparatorStyle: ',',
|
||||
maximumFractionDigits: 2,
|
||||
minimumFractionDigits: 0,
|
||||
replaceMissingDataWith: 0,
|
||||
} as ColumnLabelFormat,
|
||||
},
|
||||
showLegendHeadline: false,
|
||||
xAxisLabelRotation: 'auto',
|
||||
xAxisShowAxisLabel: true,
|
||||
xAxisShowAxisTitle: true,
|
||||
yAxisShowAxisLabel: true,
|
||||
yAxisShowAxisTitle: true,
|
||||
y2AxisShowAxisLabel: true,
|
||||
y2AxisShowAxisTitle: true,
|
||||
y2AxisStartAxisAtZero: true,
|
||||
columnMetadata: [
|
||||
{
|
||||
name: 'day_of_week',
|
||||
min_value: 0,
|
||||
max_value: 6,
|
||||
unique_values: 7,
|
||||
simple_type: 'number',
|
||||
type: 'numeric',
|
||||
},
|
||||
{
|
||||
name: 'message_count',
|
||||
min_value: 2,
|
||||
max_value: 140,
|
||||
unique_values: 7,
|
||||
simple_type: 'number',
|
||||
type: 'int8',
|
||||
},
|
||||
],
|
||||
data: [
|
||||
{
|
||||
day_of_week: 0,
|
||||
message_count: 2,
|
||||
},
|
||||
{
|
||||
day_of_week: 1,
|
||||
message_count: 127,
|
||||
},
|
||||
{
|
||||
day_of_week: 2,
|
||||
message_count: 119,
|
||||
},
|
||||
{
|
||||
day_of_week: 3,
|
||||
message_count: 140,
|
||||
},
|
||||
{
|
||||
day_of_week: 4,
|
||||
message_count: 122,
|
||||
},
|
||||
{
|
||||
day_of_week: 5,
|
||||
message_count: 106,
|
||||
},
|
||||
{
|
||||
day_of_week: 6,
|
||||
message_count: 5,
|
||||
},
|
||||
],
|
||||
},
|
||||
};
|
||||
|
|
|
@ -1,6 +1,11 @@
|
|||
import dayjs from 'dayjs';
|
||||
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest';
|
||||
import { formatDate, numberDateFallback, valueIsValidMonth } from './date';
|
||||
import {
|
||||
extractDateForFormatting,
|
||||
formatDate,
|
||||
numberDateFallback,
|
||||
valueIsValidMonth,
|
||||
} from './date';
|
||||
|
||||
describe('formatDate', () => {
|
||||
// Test 1: Basic date string formatting
|
||||
|
@ -184,6 +189,23 @@ describe('numberDateFallback', () => {
|
|||
const result = numberDateFallback(1, 'month');
|
||||
expect(dayjs.isDayjs(result) ? result.format('YYYY-MM') : result).toBe('2024-01');
|
||||
});
|
||||
|
||||
it('should handle 13-digit millisecond timestamp', () => {
|
||||
const timestamp = 1710921600000; // 2024-03-20 00:00:00 in milliseconds
|
||||
const result = numberDateFallback(timestamp);
|
||||
|
||||
expect(dayjs.isDayjs(result)).toBe(true);
|
||||
expect((result as dayjs.Dayjs).format('YYYY-MM-DD')).toBe('2024-03-20');
|
||||
});
|
||||
|
||||
it('should return string for quarter convertNumberTo with non-timestamp number', () => {
|
||||
const result = numberDateFallback(15, undefined, 'quarter');
|
||||
|
||||
// Since there's no specific quarter logic in numberDateFallback,
|
||||
// 15 is not a valid month (>12), and not a valid timestamp, it should return as string
|
||||
expect(result).toBe('15');
|
||||
expect(typeof result).toBe('string');
|
||||
});
|
||||
});
|
||||
|
||||
describe('valueIsValidMonth', () => {
|
||||
|
@ -227,3 +249,84 @@ describe('valueIsValidMonth', () => {
|
|||
expect(valueIsValidMonth('12')).toBe(true);
|
||||
});
|
||||
});
|
||||
|
||||
describe('extractDateForFormatting', () => {
|
||||
beforeEach(() => {
|
||||
// Mock the current date to ensure consistent test results
|
||||
vi.useFakeTimers();
|
||||
vi.setSystemTime(new Date('2024-01-15T00:00:00.000Z'));
|
||||
});
|
||||
|
||||
afterEach(() => {
|
||||
vi.useRealTimers();
|
||||
});
|
||||
|
||||
// Test 1: Date object input should return new Date(date)
|
||||
it('should return new Date when input is a Date object', () => {
|
||||
const inputDate = new Date('2024-03-20T10:30:00Z');
|
||||
const result = extractDateForFormatting(inputDate);
|
||||
|
||||
expect(result).toBeInstanceOf(Date);
|
||||
expect(result).toEqual(new Date(inputDate));
|
||||
});
|
||||
|
||||
// Test 2: Number input should call numberDateFallback
|
||||
it('should call numberDateFallback when input is a number', () => {
|
||||
const result = extractDateForFormatting(1710921600); // 10-digit timestamp
|
||||
|
||||
// Should return a dayjs object from numberDateFallback for timestamps
|
||||
expect(dayjs.isDayjs(result)).toBe(true);
|
||||
expect((result as dayjs.Dayjs).format('YYYY-MM-DD')).toBe('2024-03-20');
|
||||
});
|
||||
|
||||
// Test 3: String input with convertNumberTo set (non-'number') should parse and call numberDateFallback
|
||||
it('should parse string to int and call numberDateFallback when convertNumberTo is set', () => {
|
||||
const result = extractDateForFormatting('3', undefined, 'month_of_year');
|
||||
|
||||
expect(dayjs.isDayjs(result)).toBe(true);
|
||||
expect((result as dayjs.Dayjs).format('YYYY-MM')).toBe('2024-03');
|
||||
});
|
||||
|
||||
// Test 4: String input with convertNumberTo set to 'number' should return string as-is
|
||||
it('should return string as-is when convertNumberTo is "number"', () => {
|
||||
const result = extractDateForFormatting('123', undefined, 'number');
|
||||
|
||||
expect(result).toBe('123');
|
||||
expect(typeof result).toBe('string');
|
||||
});
|
||||
|
||||
// Test 5: String input without convertNumberTo should return string as-is
|
||||
it('should return string as-is when convertNumberTo is not set', () => {
|
||||
const testString = '2024-03-20';
|
||||
const result = extractDateForFormatting(testString);
|
||||
|
||||
expect(result).toBe(testString);
|
||||
expect(typeof result).toBe('string');
|
||||
});
|
||||
|
||||
// Test 6: String input that can't be parsed to int with convertNumberTo should return string
|
||||
it('should return string when input cannot be parsed as integer with convertNumberTo', () => {
|
||||
const result = extractDateForFormatting('not-a-number', undefined, 'day_of_week');
|
||||
|
||||
expect(result).toBe('not-a-number');
|
||||
expect(typeof result).toBe('string');
|
||||
});
|
||||
|
||||
// Test 7: Non-string, non-number, non-date input should convert to string
|
||||
it('should convert non-string, non-number, non-date input to string', () => {
|
||||
const objectInput = { test: 'value' };
|
||||
const result = extractDateForFormatting(objectInput as any);
|
||||
|
||||
expect(typeof result).toBe('string');
|
||||
expect(result).toBe('[object Object]');
|
||||
});
|
||||
|
||||
// Test 8: String input with convertNumberTo 'day_of_week' should parse and call numberDateFallback
|
||||
it('should handle day_of_week conversion from string number', () => {
|
||||
const result = extractDateForFormatting('1', undefined, 'day_of_week');
|
||||
|
||||
expect(dayjs.isDayjs(result)).toBe(true);
|
||||
// Day 1 (Monday) starting from current mock date (2024-01-15 which is Monday)
|
||||
expect((result as dayjs.Dayjs).format('YYYY-MM-DD')).toBe('2024-01-15');
|
||||
});
|
||||
});
|
||||
|
|
|
@ -96,14 +96,20 @@ export const numberDateFallback = (
|
|||
return String(date);
|
||||
};
|
||||
|
||||
const extractDateForFormatting = (
|
||||
export const extractDateForFormatting = (
|
||||
date: string | number | Date,
|
||||
dateKey?: string,
|
||||
convertNumberTo?: ColumnLabelFormat['convertNumberTo']
|
||||
) => {
|
||||
if (isString(date)) return date;
|
||||
if (isNumber(date)) return numberDateFallback(date, dateKey, convertNumberTo);
|
||||
if (isDate(date)) return new Date(date);
|
||||
if (isNumber(date)) return numberDateFallback(date, dateKey, convertNumberTo);
|
||||
if (convertNumberTo && convertNumberTo !== 'number') {
|
||||
//this will happen when the date is a string and we need to convert it to a number like '1' -> 1
|
||||
const parsedInt = parseInt(date as string);
|
||||
if (Number.isNaN(parsedInt)) return String(date);
|
||||
return numberDateFallback(parsedInt, dateKey, convertNumberTo);
|
||||
}
|
||||
if (isString(date)) return date;
|
||||
return String(date);
|
||||
};
|
||||
|
||||
|
|
Loading…
Reference in New Issue