+ )
+}
diff --git a/web/src/i18n/locales/en.json b/web/src/i18n/locales/en.json
index 300707c..a57db21 100644
--- a/web/src/i18n/locales/en.json
+++ b/web/src/i18n/locales/en.json
@@ -58,6 +58,17 @@
"currentPasswordWrong": "The current password is wrong.",
"changePassword": "Change password"
},
+ "discover": {
+ "title": "Discover",
+ "listening": {
+ "label": "Start Discover from my listening",
+ "help": "When this is on, the names of the artists you play most go to Last.fm, if an admin turned Last.fm on, to find similar artists. When it is off, Discover starts only from artists you pick.",
+ "confirmTitle": "Send your top artists to Last.fm?",
+ "confirmBody": "Discover will send the names of the artists you play most to Last.fm, if an admin turned Last.fm on, and ask for similar artists. Nothing else about you is sent. You can turn this off at any time.",
+ "turnOn": "Turn on",
+ "cancel": "Cancel"
+ }
+ },
"home": {
"greeting_morning": "Good morning",
"greeting_afternoon": "Good afternoon",
diff --git a/web/src/i18n/locales/it.json b/web/src/i18n/locales/it.json
index 86c7c62..27281ef 100644
--- a/web/src/i18n/locales/it.json
+++ b/web/src/i18n/locales/it.json
@@ -58,6 +58,17 @@
"currentPasswordWrong": "La password attuale è sbagliata.",
"changePassword": "Cambia password"
},
+ "discover": {
+ "title": "Discover",
+ "listening": {
+ "label": "Avvia Discover dai miei ascolti",
+ "help": "Se è acceso, i nomi degli artisti che ascolti di più vanno a Last.fm, se un admin l'ha acceso, per trovare artisti simili. Se è spento, Discover parte solo dagli artisti che scegli tu.",
+ "confirmTitle": "Mandare i tuoi artisti preferiti a Last.fm?",
+ "confirmBody": "Discover manderà a Last.fm i nomi degli artisti che ascolti di più, se un admin ha acceso Last.fm, e chiederà artisti simili. Non viene mandato nient'altro su di te. Puoi spegnerlo quando vuoi.",
+ "turnOn": "Accendi",
+ "cancel": "Annulla"
+ }
+ },
"home": {
"greeting_morning": "Buongiorno",
"greeting_afternoon": "Buon pomeriggio",
diff --git a/web/src/pages/SettingsPage.test.tsx b/web/src/pages/SettingsPage.test.tsx
index db500ab..75018db 100644
--- a/web/src/pages/SettingsPage.test.tsx
+++ b/web/src/pages/SettingsPage.test.tsx
@@ -1,3 +1,4 @@
+import { QueryClient, QueryClientProvider } from '@tanstack/react-query'
import { render, screen } from '@testing-library/react'
import userEvent from '@testing-library/user-event'
import { MemoryRouter } from 'react-router-dom'
@@ -12,14 +13,18 @@ import SettingsPage from './SettingsPage'
const noContent = () => new Response(null, { status: 204 })
function renderSettings() {
+ const client = new QueryClient({ defaultOptions: { queries: { retry: false }, mutations: { retry: false } } })
return render(
-
-
- ,
+
+
+
+
+ ,
)
}
beforeEach(async () => {
+ mockFetch({ 'GET /api/v1/me/settings': () => ({ discover_from_listening: false }) })
vi.spyOn(navigator, 'language', 'get').mockReturnValue('en-US')
await initI18n()
initTheme()
@@ -93,12 +98,19 @@ test('choosing Italian changes the words on the page', async () => {
expect(localStorage.getItem('sonda.lang')).toBe('it')
})
+test('Discover has its own group with the switch for using your listening, off until you turn it on', async () => {
+ renderSettings()
+ expect(screen.getByRole('region', { name: 'Discover' })).toBeInTheDocument()
+ const sw = await screen.findByRole('switch', { name: 'Start Discover from my listening' })
+ expect(sw).toHaveAttribute('aria-checked', 'false')
+})
+
test('a new password of seven characters is refused here, with no request', async () => {
const { calls } = mockFetch({})
renderSettings()
await changePassword('old-password', '1234567')
expect(await screen.findByRole('alert')).toHaveTextContent('The new password needs 8 to 256 characters.')
- expect(calls).toHaveLength(0)
+ expect(calls.filter((c) => c.url.pathname === '/api/v1/auth/password')).toHaveLength(0)
})
test('a new password longer than 256 bytes is refused here, with no request', async () => {
@@ -109,7 +121,7 @@ test('a new password longer than 256 bytes is refused here, with no request', as
await userEvent.paste('x'.repeat(257))
await userEvent.click(screen.getByRole('button', { name: 'Change password' }))
expect(await screen.findByRole('alert')).toHaveTextContent('8 to 256')
- expect(calls).toHaveLength(0)
+ expect(calls.filter((c) => c.url.pathname === '/api/v1/auth/password')).toHaveLength(0)
})
test('a changed password signs this session out, because the server ends every session', async () => {
diff --git a/web/src/pages/SettingsPage.tsx b/web/src/pages/SettingsPage.tsx
index 00f355e..1b670b3 100644
--- a/web/src/pages/SettingsPage.tsx
+++ b/web/src/pages/SettingsPage.tsx
@@ -3,6 +3,7 @@ import { useTranslation } from 'react-i18next'
import { api, ApiError } from '@/api/client'
import { logout, useSession } from '@/auth/session'
import ChoiceGroup from '@/components/ChoiceGroup'
+import ListeningSwitch from '@/components/ListeningSwitch'
import Section from '@/components/Section'
import { Button } from '@/components/ui/button'
import { Input } from '@/components/ui/input'
@@ -136,6 +137,10 @@ export default function SettingsPage() {
/>
+
+
+
+