From 93af24d7d65121a28fa78ab88e2d6b42a7953277 Mon Sep 17 00:00:00 2001 From: louis Date: Sat, 1 Feb 2025 19:19:43 +0100 Subject: [PATCH 1/2] =?UTF-8?q?=F0=9F=92=84=20Add=20Fields=20for=20Instagr?= =?UTF-8?q?am=20and=20Threads?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/api/Ticker.ts | 2 + src/components/ticker/form/Instagram.tsx | 42 +++++++++++++ src/components/ticker/form/Threads.tsx | 42 +++++++++++++ .../ticker/form/TickerForm.test.tsx | 59 ++++++++++++++++++- src/components/ticker/form/TickerForm.tsx | 14 +++++ 5 files changed, 156 insertions(+), 3 deletions(-) create mode 100644 src/components/ticker/form/Instagram.tsx create mode 100644 src/components/ticker/form/Threads.tsx diff --git a/src/api/Ticker.ts b/src/api/Ticker.ts index 85af292d..47e7df3c 100644 --- a/src/api/Ticker.ts +++ b/src/api/Ticker.ts @@ -48,6 +48,8 @@ export interface TickerInformation { email: string twitter: string facebook: string + threads: string + instagram: string telegram: string mastodon: string bluesky: string diff --git a/src/components/ticker/form/Instagram.tsx b/src/components/ticker/form/Instagram.tsx new file mode 100644 index 00000000..55227375 --- /dev/null +++ b/src/components/ticker/form/Instagram.tsx @@ -0,0 +1,42 @@ +import { faInstagram } from '@fortawesome/free-brands-svg-icons' +import { FontAwesomeIcon } from '@fortawesome/react-fontawesome' +import { InputAdornment, TextField } from '@mui/material' +import { FC } from 'react' +import { Controller, useFormContext } from 'react-hook-form' + +const Instagram: FC = () => { + const { control } = useFormContext() + + return ( + ( + + + instagram.com/ + + ), + }} + error={!!error} + helperText={error?.message ? error.message : null} + label="Instagram" + margin="dense" + /> + )} + /> + ) +} + +export default Instagram diff --git a/src/components/ticker/form/Threads.tsx b/src/components/ticker/form/Threads.tsx new file mode 100644 index 00000000..42fadc37 --- /dev/null +++ b/src/components/ticker/form/Threads.tsx @@ -0,0 +1,42 @@ +import { faThreads } from '@fortawesome/free-brands-svg-icons' +import { FontAwesomeIcon } from '@fortawesome/react-fontawesome' +import { InputAdornment, TextField } from '@mui/material' +import { FC } from 'react' +import { Controller, useFormContext } from 'react-hook-form' + +const Threads: FC = () => { + const { control } = useFormContext() + + return ( + ( + + + threads.net/ + + ), + }} + error={!!error} + helperText={error?.message ? error.message : null} + label="Threads" + margin="dense" + /> + )} + /> + ) +} + +export default Threads diff --git a/src/components/ticker/form/TickerForm.test.tsx b/src/components/ticker/form/TickerForm.test.tsx index 2c409432..434993dd 100644 --- a/src/components/ticker/form/TickerForm.test.tsx +++ b/src/components/ticker/form/TickerForm.test.tsx @@ -1,5 +1,6 @@ import { QueryClient, QueryClientProvider } from '@tanstack/react-query' import { render, screen } from '@testing-library/react' +import userEvent from '@testing-library/user-event' import sign from 'jwt-encode' import { MemoryRouter } from 'react-router' import { Ticker } from '../../../api/Ticker' @@ -19,7 +20,7 @@ describe('TickerForm', () => { return { id: 1, title: 'Ticker', - active: true, + active: false, information: {}, location: {}, } as Ticker @@ -42,8 +43,8 @@ describe('TickerForm', () => {
- - + +
@@ -57,4 +58,56 @@ describe('TickerForm', () => { expect(screen.getByRole('textbox', { name: 'Title' })).toBeInTheDocument() expect(screen.getByRole('checkbox', { name: 'Active' })).toBeInTheDocument() }) + + it('should submit the form', async () => { + setup(ticker()) + + fetchMock.mockResponseOnce(JSON.stringify({ status: 'success' })) + + await userEvent.click(screen.getByRole('checkbox', { name: 'Active' })) + await userEvent.clear(screen.getByRole('textbox', { name: 'Title' })) + await userEvent.type(screen.getByRole('textbox', { name: 'Title' }), 'New Ticker') + await userEvent.type(screen.getByRole('textbox', { name: 'Description' }), 'Description') + await userEvent.type(screen.getByRole('textbox', { name: 'Author' }), 'Author') + await userEvent.type(screen.getByRole('textbox', { name: 'Homepage' }), 'https://example.org') + await userEvent.type(screen.getByRole('textbox', { name: 'E-Mail' }), 'author@example.org') + await userEvent.type(screen.getByRole('textbox', { name: 'Twitter' }), 'account') + await userEvent.type(screen.getByRole('textbox', { name: 'Facebook' }), 'account') + await userEvent.type(screen.getByRole('textbox', { name: 'Threads' }), '@account') + await userEvent.type(screen.getByRole('textbox', { name: 'Instagram' }), 'account') + await userEvent.type(screen.getByRole('textbox', { name: 'Telegram' }), 'account') + await userEvent.type(screen.getByRole('textbox', { name: 'Mastodon' }), 'https://mastodon.social/@account') + await userEvent.type(screen.getByRole('textbox', { name: 'Bluesky' }), 'https://bsky.app/profile/account.bsky.social') + + await userEvent.click(screen.getByRole('button', { name: 'Submit' })) + + expect(callback).toHaveBeenCalledTimes(1) + expect(fetchMock).toHaveBeenCalledTimes(1) + expect(fetchMock).toHaveBeenCalledWith('http://localhost:8080/v1/admin/tickers/1', { + body: JSON.stringify({ + title: 'New Ticker', + active: true, + description: 'Description', + information: { + author: 'Author', + email: 'author@example.org', + url: 'https://example.org', + twitter: 'account', + facebook: 'account', + threads: '@account', + instagram: 'account', + telegram: 'account', + mastodon: 'https://mastodon.social/@account', + bluesky: 'https://bsky.app/profile/account.bsky.social', + }, + location: { lat: 0, lon: 0 }, + }), + headers: { + Accept: 'application/json', + Authorization: `Bearer ${token}`, + 'Content-Type': 'application/json', + }, + method: 'put', + }) + }) }) diff --git a/src/components/ticker/form/TickerForm.tsx b/src/components/ticker/form/TickerForm.tsx index 79d75911..369dcafd 100644 --- a/src/components/ticker/form/TickerForm.tsx +++ b/src/components/ticker/form/TickerForm.tsx @@ -13,8 +13,10 @@ import Bluesky from './Bluesky' import Description from './Description' import Email from './Email' import Facebook from './Facebook' +import Instagram from './Instagram' import Mastodon from './Mastodon' import Telegram from './Telegram' +import Threads from './Threads' import Title from './Title' import Twitter from './Twitter' import Url from './Url' @@ -37,6 +39,8 @@ const TickerForm: FC = ({ callback, id, ticker }) => { url: ticker?.information.url, twitter: ticker?.information.twitter, facebook: ticker?.information.facebook, + threads: ticker?.information.threads, + instagram: ticker?.information.instagram, telegram: ticker?.information.telegram, mastodon: ticker?.information.mastodon, bluesky: ticker?.information.bluesky, @@ -140,6 +144,16 @@ const TickerForm: FC = ({ callback, id, ticker }) => { + + + + + + + + + + From 9a9822e4a13c716753f139ca336e20cf1e27516b Mon Sep 17 00:00:00 2001 From: louis Date: Sat, 1 Feb 2025 19:25:54 +0100 Subject: [PATCH 2/2] =?UTF-8?q?=F0=9F=94=A7=20Adjust=20vitest=20configurat?= =?UTF-8?q?ion?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- vite.config.ts | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/vite.config.ts b/vite.config.ts index 0eaf886c..6152a912 100644 --- a/vite.config.ts +++ b/vite.config.ts @@ -1,7 +1,7 @@ /// -import { defineConfig } from 'vite' import react from '@vitejs/plugin-react' +import { defineConfig } from 'vite' // https://vitejs.dev/config/ export default defineConfig({ @@ -20,5 +20,7 @@ export default defineConfig({ provider: 'v8', reporter: ['lcov'], }, + pool: 'threads', + testTimeout: 10000, }, })