diff --git a/client/src/components/Settings/Settings.test.jsx b/client/src/components/Settings/Settings.test.jsx index d019242..39cf527 100644 --- a/client/src/components/Settings/Settings.test.jsx +++ b/client/src/components/Settings/Settings.test.jsx @@ -1,4 +1,3 @@ -import React from 'react'; import { render, fireEvent, waitFor } from '@testing-library/react'; import { Provider } from 'react-redux'; import { describe, it, expect, vi } from 'vitest'; @@ -9,10 +8,6 @@ import Settings from '.'; const store = configureStore(); -const mockTranslations = { - sound: 'soundCheck', -}; - vi.useFakeTimers(); vi.mock('@/components/RoomLink'); @@ -39,11 +34,14 @@ describe('Settings component', () => { {}} + persistenceIsEnabled={true} + togglePersistenceEnabled={() => {}} notificationIsEnabled={true} toggleNotificationEnabled={() => {}} toggleNotificationAllowed={vi.fn()} roomId="roomId" setLanguage={() => {}} + language="en" translations={{}} /> , @@ -56,12 +54,15 @@ describe('Settings component', () => { {}} + persistenceIsEnabled={true} + togglePersistenceEnabled={() => {}} notificationIsEnabled={true} notificationIsAllowed={false} toggleNotificationEnabled={() => {}} toggleNotificationAllowed={vi.fn()} roomId="roomId" setLanguage={() => {}} + language="en" translations={{}} /> , @@ -77,18 +78,20 @@ describe('Settings component', () => { {}} notificationIsEnabled={true} notificationIsAllowed={true} toggleNotificationEnabled={() => {}} toggleNotificationAllowed={vi.fn()} roomId="roomId" setLanguage={() => {}} + language="en" translations={{}} /> , ); - //console.log(getAllByText(mockTranslations.sound)[1]); fireEvent.click(getByText('Sound')); expect(toggleSound).toHaveBeenCalledWith(false); @@ -105,12 +108,15 @@ describe('Settings component', () => { {}} + persistenceIsEnabled={true} + togglePersistenceEnabled={() => {}} notificationIsEnabled={true} notificationIsAllowed={true} toggleNotificationEnabled={toggleNotifications} toggleNotificationAllowed={vi.fn()} roomId="roomId" setLanguage={() => {}} + language="en" translations={{}} /> , @@ -137,12 +143,15 @@ describe('Settings component', () => { {}} + persistenceIsEnabled={true} + togglePersistenceEnabled={() => {}} notificationIsEnabled={true} notificationIsAllowed={true} toggleNotificationEnabled={toggleNotifications} toggleNotificationAllowed={toggleAllowed} roomId="roomId" setLanguage={() => {}} + language="en" translations={{}} /> , @@ -166,11 +175,14 @@ describe('Settings component', () => { {}} + persistenceIsEnabled={true} + togglePersistenceEnabled={() => {}} notificationIsEnabled={true} toggleNotificationEnabled={() => {}} toggleNotificationAllowed={vi.fn()} roomId="roomId" setLanguage={changeLang} + language="en" translations={{}} /> , diff --git a/client/src/components/Settings/__snapshots__/Settings.test.jsx.snap b/client/src/components/Settings/__snapshots__/Settings.test.jsx.snap index 126575a..1dd0cad 100644 --- a/client/src/components/Settings/__snapshots__/Settings.test.jsx.snap +++ b/client/src/components/Settings/__snapshots__/Settings.test.jsx.snap @@ -50,6 +50,7 @@ exports[`Settings component > should display 1`] = ` for="persistence-control" > should display 2`] = ` for="persistence-control" > { + const handleSoundToggle = () => { + toggleSoundEnabled(!soundIsEnabled); + }; - handlePersistenceToggle() { - this.props.togglePersistenceEnabled(!this.props.persistenceIsEnabled); - } + const handlePersistenceToggle = () => { + togglePersistenceEnabled(!persistenceIsEnabled); + }; - handleNotificationToggle() { + const handleNotificationToggle = () => { Notification.requestPermission().then(permission => { if (permission === 'granted') { - this.props.toggleNotificationEnabled(!this.props.notificationIsEnabled); - this.props.toggleNotificationAllowed(true); + toggleNotificationEnabled(!notificationIsEnabled); + toggleNotificationAllowed(true); } if (permission === 'denied') { - this.props.toggleNotificationAllowed(false); + toggleNotificationAllowed(false); } }); - } + }; - handleLanguageChange(evt) { - const language = evt.target.value; - this.props.setLanguage(language); - } + const handleLanguageChange = evt => { + setLanguage(evt.target.value); + }; - render() { - return ( -
-
-

- -

-
-
- -
-
- -
-
- -
-
-
- -
-

- -

- -
- -
-

- -

-

- - - -

-
- + return ( +
+
+

+ +

+
+
+
-
+
+ +
+
+ +
+ +
-
-

- -

-

- -

-
-
-

- -

-

- -

-
-
-

- -

-

- -

-
    -
  • - /nick [username]{' '} - - - -
  • -
  • - /me [action]{' '} - - - -
  • -
  • - /clear{' '} - - - -
  • -
  • - /help{' '} - - - -
  • -
-
-
- ); - } -} +
+

+ +

+ +
+ +
+

+ +

+

+ + + +

+
+ +
+
+ +
+

+ +

+

+ +

+
+
+

+ +

+

+ +

+
+
+

+ +

+

+ +

+
    +
  • + /nick [username]{' '} + + + +
  • +
  • + /me [action]{' '} + + + +
  • +
  • + /clear{' '} + + + +
  • +
  • + /help{' '} + + + +
  • +
+
+ + ); +}; Settings.propTypes = { soundIsEnabled: PropTypes.bool.isRequired, persistenceIsEnabled: PropTypes.bool.isRequired, toggleSoundEnabled: PropTypes.func.isRequired, + togglePersistenceEnabled: PropTypes.func.isRequired, notificationIsEnabled: PropTypes.bool.isRequired, notificationIsAllowed: PropTypes.bool, toggleNotificationEnabled: PropTypes.func.isRequired, toggleNotificationAllowed: PropTypes.func.isRequired, roomId: PropTypes.string.isRequired, setLanguage: PropTypes.func.isRequired, + language: PropTypes.string.isRequired, translations: PropTypes.object.isRequired, };