Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ jobs:
node-version: '16'
cache: 'yarn'
- run: yarn install --immutable --immutable-cache --check-cache
- run: yarn prod
- run: yarn test-coverage
- run: yarn prod
- name: Coveralls
uses: coverallsapp/github-action@master
with:
Expand Down
2 changes: 1 addition & 1 deletion index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ interface TSMLReactConfig {
};
distance_unit: 'mi' | 'km';
/** Email addresses for update meeting info button */
feedback_emails: [];
feedback_emails: string[];
filters: Array<'region' | 'distance' | 'weekday' | 'time' | 'type'>;
flags: Array<'M' | 'W'> | undefined | null;
in_person_types: MeetingType[];
Expand Down
3 changes: 3 additions & 0 deletions jest.setup.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
import '@testing-library/jest-dom/extend-expect';
import React from 'react';
import * as momentTZ from 'moment-timezone';

momentTZ.tz.setDefault('America/New_York');

global.React = React;

Expand Down
242 changes: 0 additions & 242 deletions src/helpers/format.ts

This file was deleted.

11 changes: 11 additions & 0 deletions src/helpers/format/format-address.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import { formatAddress } from './format-address';

describe('formatAddress', () => {
it('returns first part of address if length > 3', () => {
expect(formatAddress('foo, bar, baz, qux')).toStrictEqual('foo');
});

it.each([undefined, 'foo, bar, baz'])('yields null with %s', input => {
expect(formatAddress(input)).toStrictEqual(null);
});
});
5 changes: 5 additions & 0 deletions src/helpers/format/format-address.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
//get address from formatted_address
export function formatAddress(formatted_address = '') {
const address = formatted_address.split(', ');
return address.length > 3 ? address[0] : null;
}
13 changes: 13 additions & 0 deletions src/helpers/format/format-array.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import { formatArray } from './format-array';

describe('formatArray', () => {
it.each`
input | expected
${[]} | ${[]}
${'foo'} | ${['foo']}
${{ foo: 'bar' }} | ${['bar']}
${undefined} | ${[]}
`('yields $expected with $input', ({ input, expected }) => {
expect(formatArray(input)).toStrictEqual(expected);
});
});
9 changes: 9 additions & 0 deletions src/helpers/format/format-array.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
//ensure array-ness for formatFeedbackEmail()
export function formatArray(unknown: unknown) {
if (Array.isArray(unknown)) return unknown;
const type = typeof unknown;
if (type === 'string') return [unknown];
//@ts-expect-error TODO
if (type === 'object') return Object.values(unknown);
return [];
}
14 changes: 14 additions & 0 deletions src/helpers/format/format-classes.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import { formatClasses } from './format-classes';

describe('formatClasses', () => {
it.each`
input | expected
${'foo'} | ${'foo'}
${{ foo: true }} | ${'foo'}
${{ foo: false }} | ${''}
${undefined} | ${''}
${['foo']} | ${'foo'}
`('yields $expected with $input', ({ input, expected }) => {
expect(formatClasses(input)).toStrictEqual(expected);
});
});
19 changes: 19 additions & 0 deletions src/helpers/format/format-classes.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
//inspired by the functionality of jedwatson/classnames
export function formatClasses(
_args: Array<string | undefined | Record<string, boolean>>
) {
return Object.values(arguments)
.map(arg =>
typeof arg === 'string'
? arg
: Array.isArray(arg)
? arg.join(' ')
: typeof arg === 'object'
? Object.keys(arg)
.filter(key => !!arg[key])
.join(' ')
: null
)
.filter(e => e)
.join(' ');
}
14 changes: 14 additions & 0 deletions src/helpers/format/format-conference-provider.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import { settings } from '../settings';
import { formatConferenceProvider } from './format-conference-provider';

describe('formatConferenceProvider', () => {
it.each(['foo', 'https://', 'https://foo.com'])(
'yields null with %s',
input => expect(formatConferenceProvider(input)).toStrictEqual(null)
);

it('returns title when a valid provider is found', () => {
const [[url, name]] = Object.entries(settings.conference_providers);
expect(formatConferenceProvider(`https://${url}`)).toStrictEqual(name);
});
});
11 changes: 11 additions & 0 deletions src/helpers/format/format-conference-provider.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import { settings } from '../settings';

//get name of provider from url
export function formatConferenceProvider(url: string) {
const urlParts = url.split('/');
if (urlParts.length < 2) return null;
const provider = Object.keys(settings.conference_providers).filter(domain =>
urlParts[2].endsWith(domain)
);
return provider.length ? settings.conference_providers[provider[0]] : null;
}
Loading