diff --git a/apps/admin-x-settings/src/components/settings/advanced/integrations/UnsplashModal.tsx b/apps/admin-x-settings/src/components/settings/advanced/integrations/UnsplashModal.tsx index 6f9db1d7e3..88b55e651f 100644 --- a/apps/admin-x-settings/src/components/settings/advanced/integrations/UnsplashModal.tsx +++ b/apps/admin-x-settings/src/components/settings/advanced/integrations/UnsplashModal.tsx @@ -3,19 +3,38 @@ import IntegrationHeader from './IntegrationHeader'; import Modal from '../../../../admin-x-ds/global/modal/Modal'; import NiceModal from '@ebay/nice-modal-react'; import Toggle from '../../../../admin-x-ds/global/form/Toggle'; +import useRouting from '../../../../hooks/useRouting'; import {ReactComponent as Icon} from '../../../../assets/icons/unsplash.svg'; +import {Setting, getSettingValues, useEditSettings} from '../../../../api/settings'; +import {useGlobalData} from '../../../providers/GlobalDataProvider'; const UnsplashModal = NiceModal.create(() => { + const {updateRoute} = useRouting(); const modal = NiceModal.useModal(); + const {settings} = useGlobalData(); + const [unsplashEnabled] = getSettingValues(settings, ['unsplash']); + const {mutateAsync: editSettings} = useEditSettings(); + + const handleToggleChange = async (e: React.ChangeEvent) => { + const updates: Setting[] = [ + {key: 'unsplash', value: (e.target.checked)} + ]; + await editSettings(updates); + }; return ( { + updateRoute('integrations'); + }} cancelLabel='' okColor='black' okLabel='Close' + testId='unsplash-modal' title='' onOk={() => { modal.remove(); + updateRoute('integrations'); }} > {
Enable Unsplash image integration for your posts} label='Enable Unsplash' + onChange={handleToggleChange} />
@@ -36,4 +57,4 @@ const UnsplashModal = NiceModal.create(() => { ); }); -export default UnsplashModal; \ No newline at end of file +export default UnsplashModal; diff --git a/apps/admin-x-settings/test/e2e/advanced/integrations/unsplash.test.ts b/apps/admin-x-settings/test/e2e/advanced/integrations/unsplash.test.ts new file mode 100644 index 0000000000..c39713e0f2 --- /dev/null +++ b/apps/admin-x-settings/test/e2e/advanced/integrations/unsplash.test.ts @@ -0,0 +1,29 @@ +import {expect, test} from '@playwright/test'; +import {globalDataRequests, mockApi, updatedSettingsResponse} from '../../../utils/e2e'; + +test.describe('Unsplash integration', async () => { + test('Supports toggling unsplash integration', async ({page}) => { + const {lastApiRequests} = await mockApi({page, requests: { + ...globalDataRequests, + editSettings: {method: 'PUT', path: '/settings/', response: updatedSettingsResponse([ + {key: 'unsplash', value: false} + ])} + }}); + + await page.goto('/'); + const section = page.getByTestId('integrations'); + const unsplashElement = section.getByText('Unsplash').last(); + await unsplashElement.hover(); + await page.getByRole('button', {name: 'Configure'}).click(); + const unsplashModal = page.getByTestId('unsplash-modal'); + + const unsplashToggle = unsplashModal.getByRole('switch'); + await unsplashToggle.click(); + + expect(lastApiRequests.editSettings?.body).toEqual({ + settings: [ + {key: 'unsplash', value: false} + ] + }); + }); +});