Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Events: Display TBD if location is empty or null (#479)
* Display TBD if location is empty or null * move bulk of logic to utils, tests are kinda scuffed * fix logic, still need ternary, update test * Move around logic to be more readable * null check in parse, format in ui, remove unit test * add !location and fix info.location * I forgor * null check and trim everything, change default location * Update src/lib/components/events/event-item.svelte Co-authored-by: Ethan Davidson <31261035+EthanThatOneKid@users.noreply.github.com> * Remove optional chaining, update test data and test * Add unit tests to format location * remove unecessary toast 🍞 * Add good location format tests Co-authored-by: Ethan Davidson <31261035+EthanThatOneKid@users.noreply.github.com> Co-authored-by: jason wong <jayywong92@gmail.com>
- Loading branch information
1 parent
145ad90
commit e571135
Showing
6 changed files
with
68 additions
and
41 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
import { expect, test } from 'vitest'; | ||
import { formatLocation } from './utils'; | ||
|
||
test('can format bad locations', () => { | ||
expect(formatLocation(null)).toBe('TBD'); | ||
expect(formatLocation('')).toBe('TBD'); | ||
expect(formatLocation(undefined)).toBe('TBD'); | ||
expect(formatLocation(" Your mom's house ")).toBe("Your mom's house"); | ||
}); | ||
|
||
test('can format online locations', () => { | ||
expect(formatLocation('Discord')).toBe('Hosted on Discord'); | ||
expect(formatLocation('Zoom')).toBe('Hosted on Zoom'); | ||
}); | ||
|
||
test('can format good locations', () => { | ||
expect(formatLocation('CS-104')).toBe('CS-104'); | ||
expect(formatLocation('TSU Pavilions')).toBe('TSU Pavilions'); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
import { toast, ToastType } from '$lib/stores/toasts'; | ||
|
||
/** @see <https://developer.mozilla.org/en-US/docs/Web/API/Clipboard/writeText> */ | ||
export function copy(link: string, successMessage: string, errorMessage: string, path: string) { | ||
navigator.clipboard | ||
.writeText(link) | ||
.then(() => toast({ content: successMessage, path })) | ||
.catch(() => toast({ path, type: ToastType.Error, content: errorMessage })); | ||
} | ||
|
||
export function formatLocation(location?: string | null, hosted = ['Discord', 'Zoom']): string { | ||
// '', null, and undefined are all TBD | ||
location = location?.trim() ?? ''; | ||
if (location === '') return 'TBD'; | ||
return hosted.includes(location) ? `Hosted on ${location}` : location; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
e571135
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Successfully deployed to the following URLs:
acm-csuf-site – ./
acmcsuf.com
acm-csuf-site-ethanthatonekid.vercel.app
acm-csuf-site.vercel.app
acm-csuf-site-git-main-ethanthatonekid.vercel.app