1- import { act , screen } from '@testing-library/react' ;
1+ import { screen } from '@testing-library/react' ;
22import userEvent from '@testing-library/user-event' ;
33
44import { renderWithProviders } from '../../__helpers__/test-utils' ;
@@ -20,79 +20,75 @@ describe('renderer/components/settings/AlertSettings.tsx', () => {
2020 } ) ;
2121
2222 it . each ( [
23- [ 'checkbox-showNotifications' , 'showNotifications' ] ,
24- [ 'checkbox-playSound' , 'playSound' ] ,
25- [ 'checkbox-showUpdateNotifications' , 'showUpdateNotifications' ] ,
26- ] as const ) ( 'should toggle %s checkbox' , async ( testId , setting ) => {
27- await act ( async ( ) => {
28- renderWithProviders ( < AlertSettings /> ) ;
29- } ) ;
23+ [ 'Show desktop notifications' , 'showNotifications' ] ,
24+ [ 'Play notification sound' , 'playSound' ] ,
25+ [ 'Show app update notifications' , 'showUpdateNotifications' ] ,
26+ ] as const ) ( 'should toggle %s switch' , async ( label , setting ) => {
27+ renderWithProviders ( < AlertSettings /> ) ;
3028
31- await userEvent . click ( screen . getByTestId ( testId ) ) ;
29+ await userEvent . click ( screen . getByRole ( 'button' , { name : label } ) ) ;
3230
3331 expect ( toggleSettingSpy ) . toHaveBeenCalledTimes ( 1 ) ;
3432 expect ( toggleSettingSpy ) . toHaveBeenCalledWith ( setting ) ;
3533 } ) ;
3634
37- describe ( 'playSound' , ( ) => {
38- it ( 'should explain when the sound plays and what the volume controls do' , async ( ) => {
39- renderWithProviders ( < AlertSettings /> ) ;
35+ it ( 'shows detailed help in tooltips' , async ( ) => {
36+ renderWithProviders ( < AlertSettings /> ) ;
4037
41- const soundHelp =
42- 'Play a sound when new unread notifications arrive after filtering. Use the adjacent volume controls to adjust the sound level.' ;
38+ await userEvent . click ( screen . getByTestId ( 'tooltip-icon-tooltip-playSound' ) ) ;
4339
44- const tooltipTrigger = screen . getByRole ( 'button' , { name : 'tooltip-playSound' } ) ;
40+ expect (
41+ screen . getByText (
42+ 'Play a sound when new unread notifications arrive after filtering. Use the notification volume controls to adjust the sound level.' ,
43+ ) ,
44+ ) . toBeInTheDocument ( ) ;
45+ } ) ;
4546
46- expect ( screen . queryByText ( soundHelp ) ) . not . toBeInTheDocument ( ) ;
47+ it ( 'shows notification volume and its tooltip when sound is enabled' , async ( ) => {
48+ renderWithProviders ( < AlertSettings /> ) ;
4749
48- await userEvent . click ( tooltipTrigger ) ;
50+ expect ( screen . getByText ( 'Notification volume' ) ) . toBeInTheDocument ( ) ;
51+ expect ( screen . getByTestId ( 'reveal-volume' ) ) . toHaveAttribute ( 'data-state' , 'open' ) ;
4952
50- expect ( screen . getByText ( soundHelp ) ) . toBeInTheDocument ( ) ;
51- } ) ;
53+ await userEvent . click ( screen . getByTestId ( 'tooltip-icon-tooltip-notificationVolume' ) ) ;
5254
53- it ( 'volume controls should not be shown if playSound checkbox is false' , async ( ) => {
54- renderWithProviders ( < AlertSettings /> , {
55- settings : { ...mockSettings , playSound : false } ,
56- } ) ;
55+ expect ( screen . getByText ( 'Adjust the volume of the notification sound.' ) ) . toBeInTheDocument ( ) ;
56+ } ) ;
5757
58- expect ( screen . queryByTestId ( 'settings-volume-group' ) ) . not . toBeInTheDocument ( ) ;
58+ it ( 'hides volume controls when playSound is false' , ( ) => {
59+ renderWithProviders ( < AlertSettings /> , {
60+ settings : { ...mockSettings , playSound : false } ,
5961 } ) ;
6062
61- it ( 'volume controls should be shown if playSound checkbox is true' , async ( ) => {
62- renderWithProviders ( < AlertSettings /> , {
63- settings : { ...mockSettings , playSound : true } ,
64- } ) ;
63+ expect ( screen . getByTestId ( 'reveal-volume' ) ) . toHaveAttribute ( 'data-state' , 'closed' ) ;
64+ } ) ;
6565
66- expect ( screen . getByTestId ( 'settings- volume-group' ) ) . toBeInTheDocument ( ) ;
67- } ) ;
66+ it ( 'should increase notification volume' , async ( ) => {
67+ renderWithProviders ( < AlertSettings /> ) ;
6868
69- it ( 'should increase notification volume' , async ( ) => {
70- renderWithProviders ( < AlertSettings /> ) ;
69+ await userEvent . click ( screen . getByTestId ( 'settings-volume-up' ) ) ;
7170
72- await userEvent . click ( screen . getByTestId ( 'settings-volume-up' ) ) ;
71+ expect ( updateSettingSpy ) . toHaveBeenCalledTimes ( 1 ) ;
72+ expect ( updateSettingSpy ) . toHaveBeenCalledWith ( 'notificationVolume' , 30 ) ;
73+ } ) ;
7374
74- expect ( updateSettingSpy ) . toHaveBeenCalledTimes ( 1 ) ;
75- expect ( updateSettingSpy ) . toHaveBeenCalledWith ( 'notificationVolume' , 30 ) ;
76- } ) ;
75+ it ( 'should decrease notification volume' , async ( ) => {
76+ renderWithProviders ( < AlertSettings /> ) ;
7777
78- it ( 'should decrease notification volume' , async ( ) => {
79- renderWithProviders ( < AlertSettings /> ) ;
78+ await userEvent . click ( screen . getByTestId ( 'settings-volume-down' ) ) ;
8079
81- await userEvent . click ( screen . getByTestId ( 'settings-volume-down' ) ) ;
80+ expect ( updateSettingSpy ) . toHaveBeenCalledTimes ( 1 ) ;
81+ expect ( updateSettingSpy ) . toHaveBeenCalledWith ( 'notificationVolume' , 10 ) ;
82+ } ) ;
8283
83- expect ( updateSettingSpy ) . toHaveBeenCalledTimes ( 1 ) ;
84- expect ( updateSettingSpy ) . toHaveBeenCalledWith ( 'notificationVolume' , 10 ) ;
84+ it ( 'should reset notification volume' , async ( ) => {
85+ renderWithProviders ( < AlertSettings /> , {
86+ settings : { ...mockSettings , notificationVolume : 30 as Percentage } ,
8587 } ) ;
8688
87- it ( 'should reset notification volume' , async ( ) => {
88- renderWithProviders ( < AlertSettings /> , {
89- settings : { ...mockSettings , notificationVolume : 30 as Percentage } ,
90- } ) ;
89+ await userEvent . click ( screen . getByTestId ( 'settings-volume-reset' ) ) ;
9190
92- await userEvent . click ( screen . getByTestId ( 'settings-volume-reset' ) ) ;
93-
94- expect ( updateSettingSpy ) . toHaveBeenCalledTimes ( 1 ) ;
95- expect ( updateSettingSpy ) . toHaveBeenCalledWith ( 'notificationVolume' , 20 ) ;
96- } ) ;
91+ expect ( updateSettingSpy ) . toHaveBeenCalledTimes ( 1 ) ;
92+ expect ( updateSettingSpy ) . toHaveBeenCalledWith ( 'notificationVolume' , 20 ) ;
9793 } ) ;
9894} ) ;
0 commit comments