-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: discard changes of timezone, locale and dark mode reset initial …
…values refs: SHELL-161 (#346)
- Loading branch information
1 parent
bb1a575
commit 0b1abed
Showing
5 changed files
with
203 additions
and
70 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,102 @@ | ||
/* | ||
* SPDX-FileCopyrightText: 2023 Zextras <https://www.zextras.com> | ||
* | ||
* SPDX-License-Identifier: AGPL-3.0-only | ||
*/ | ||
import React from 'react'; | ||
|
||
import 'jest-styled-components'; | ||
import { screen, within } from '@testing-library/react'; | ||
import { find } from 'lodash'; | ||
|
||
import { | ||
LocaleDescriptorWithLabels, | ||
localeList, | ||
TimeZoneDescriptor, | ||
timeZoneList | ||
} from './components/utils'; | ||
import GeneralSettings from './general-settings'; | ||
import { useAccountStore } from '../store/account'; | ||
import { useI18nStore } from '../store/i18n'; | ||
import { TESTID_SELECTORS } from '../test/constants'; | ||
import { setup } from '../test/utils'; | ||
|
||
describe('General setting', () => { | ||
const { defaultI18n } = useI18nStore.getState(); | ||
const timeZoneArray = timeZoneList(defaultI18n.t); | ||
const localeArray = localeList(defaultI18n.t); | ||
test('When timezone is changed, discard button become enabled and when clicked the initial value is restored', async () => { | ||
const zimbraPrefTimeZoneIdValue = 'UTC'; | ||
|
||
useAccountStore.setState((previousState) => ({ | ||
...previousState, | ||
settings: { | ||
...previousState.settings, | ||
prefs: { zimbraPrefTimeZoneId: zimbraPrefTimeZoneIdValue } | ||
} | ||
})); | ||
const { user } = setup(<GeneralSettings />); | ||
const match = find( | ||
timeZoneArray, | ||
(item) => item.value === zimbraPrefTimeZoneIdValue | ||
) as TimeZoneDescriptor; | ||
expect(match).toBeDefined(); | ||
expect(screen.getByText(match.label)).toBeVisible(); | ||
expect(screen.getByRole('button', { name: /discard changes/i })).toBeDisabled(); | ||
await user.click(screen.getByText(match.label)); | ||
await user.click( | ||
within(screen.getByTestId(TESTID_SELECTORS.dropdown)).getByText(timeZoneArray[0].label) | ||
); | ||
expect(screen.getByRole('button', { name: /discard changes/i })).toBeEnabled(); | ||
await user.click(screen.getByRole('button', { name: /discard changes/i })); | ||
expect(screen.getByText(match.label)).toBeVisible(); | ||
expect(screen.getByRole('button', { name: /discard changes/i })).toBeDisabled(); | ||
}); | ||
|
||
test('When locale is changed, discard button become enabled and when clicked the initial value is restored', async () => { | ||
const zimbraPrefLocaleValue = 'en'; | ||
|
||
useAccountStore.setState((previousState) => ({ | ||
...previousState, | ||
settings: { | ||
...previousState.settings, | ||
prefs: { zimbraPrefLocale: zimbraPrefLocaleValue } | ||
} | ||
})); | ||
const { user } = setup(<GeneralSettings />); | ||
const match = find( | ||
localeArray, | ||
(item) => item.value === zimbraPrefLocaleValue | ||
) as LocaleDescriptorWithLabels; | ||
expect(match).toBeDefined(); | ||
expect(screen.getByText(match.label)).toBeVisible(); | ||
expect(screen.getByRole('button', { name: /discard changes/i })).toBeDisabled(); | ||
await user.click(screen.getByText(match.label)); | ||
await user.click( | ||
within(screen.getByTestId(TESTID_SELECTORS.dropdown)).getByText(localeArray[0].label) | ||
); | ||
expect(screen.getByRole('button', { name: /discard changes/i })).toBeEnabled(); | ||
await user.click(screen.getByRole('button', { name: /discard changes/i })); | ||
expect(screen.getByText(match.label)).toBeVisible(); | ||
expect(screen.getByRole('button', { name: /discard changes/i })).toBeDisabled(); | ||
}); | ||
|
||
test('When dark mode is changed, discard button become enabled and when clicked the initial value is restored', async () => { | ||
useAccountStore.setState((previousState) => ({ | ||
...previousState, | ||
settings: { | ||
...previousState.settings, | ||
props: [{ name: 'zappDarkreaderMode', zimlet: 'carbonio-shell-ui', _content: 'auto' }] | ||
} | ||
})); | ||
const { user } = setup(<GeneralSettings />); | ||
expect(screen.getByText('Auto')).toBeVisible(); | ||
expect(screen.getByRole('button', { name: /discard changes/i })).toBeDisabled(); | ||
await user.click(screen.getByText('Auto')); | ||
await user.click(within(screen.getByTestId(TESTID_SELECTORS.dropdown)).getByText(/disabled/i)); | ||
expect(screen.getByRole('button', { name: /discard changes/i })).toBeEnabled(); | ||
await user.click(screen.getByRole('button', { name: /discard changes/i })); | ||
expect(screen.getByText('Auto')).toBeVisible(); | ||
expect(screen.getByRole('button', { name: /discard changes/i })).toBeDisabled(); | ||
}); | ||
}); |
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
Oops, something went wrong.