diff --git a/CHANGELOG.md b/CHANGELOG.md index 22c6d110..1dacf924 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -10,6 +10,7 @@ and this project adheres to ## Added +- 🚩(frontend) feature flag analytic on copy as html #649 - ✨(frontend) Custom block divider with export #698 ## Changed diff --git a/src/frontend/apps/impress/jest.config.ts b/src/frontend/apps/impress/jest.config.ts index 804c4fce..52ef120d 100644 --- a/src/frontend/apps/impress/jest.config.ts +++ b/src/frontend/apps/impress/jest.config.ts @@ -23,6 +23,7 @@ const jestConfig = async () => { '\\.svg$': '/jest/mocks/svg.js', '^.+\\.svg\\?url$': `/jest/mocks/fileMock.js`, BlockNoteEditor: `/jest/mocks/ComponentMock.js`, + 'custom-blocks': `/jest/mocks/ComponentMock.js`, ...nextJestConfig.moduleNameMapper, }, }; diff --git a/src/frontend/apps/impress/src/features/docs/doc-header/__tests__/DocToolBox.spec.tsx b/src/frontend/apps/impress/src/features/docs/doc-header/__tests__/DocToolBox.spec.tsx new file mode 100644 index 00000000..99373361 --- /dev/null +++ b/src/frontend/apps/impress/src/features/docs/doc-header/__tests__/DocToolBox.spec.tsx @@ -0,0 +1,79 @@ +import { render, screen } from '@testing-library/react'; +import userEvent from '@testing-library/user-event'; +import React, { Fragment } from 'react'; + +import { AbstractAnalytic, Analytics } from '@/libs'; +import { AppWrapper } from '@/tests/utils'; + +import { DocToolBox } from '../components/DocToolBox'; + +let flag = true; +class TestAnalytic extends AbstractAnalytic { + public constructor() { + super(); + } + + public Provider() { + return ; + } + + public trackEvent() {} + + public isFeatureFlagActivated(flagName: string): boolean { + if (flagName === 'CopyAsHTML') { + return flag; + } + + return true; + } +} + +jest.mock('@/features/docs/doc-export/', () => ({ + ModalExport: () => ModalExport, +})); + +const doc = { + nb_accesses: 1, + abilities: { + versions_list: true, + destroy: true, + }, +}; + +beforeEach(() => { + Analytics.clearAnalytics(); +}); + +describe('DocToolBox "Copy as HTML" option', () => { + test('renders "Copy as HTML" option when feature flag is enabled', async () => { + new TestAnalytic(); + + render(, { + wrapper: AppWrapper, + }); + const optionsButton = screen.getByLabelText('Open the document options'); + await userEvent.click(optionsButton); + expect(await screen.findByText('Copy as HTML')).toBeInTheDocument(); + }); + + test('does not render "Copy as HTML" option when feature flag is disabled', async () => { + flag = false; + new TestAnalytic(); + + render(, { + wrapper: AppWrapper, + }); + const optionsButton = screen.getByLabelText('Open the document options'); + await userEvent.click(optionsButton); + expect(screen.queryByText('Copy as HTML')).not.toBeInTheDocument(); + }); + + test('render "Copy as HTML" option when we did not add analytics', async () => { + render(, { + wrapper: AppWrapper, + }); + const optionsButton = screen.getByLabelText('Open the document options'); + await userEvent.click(optionsButton); + expect(screen.getByText('Copy as HTML')).toBeInTheDocument(); + }); +}); diff --git a/src/frontend/apps/impress/src/features/docs/doc-header/components/DocToolBox.tsx b/src/frontend/apps/impress/src/features/docs/doc-header/components/DocToolBox.tsx index 07c75aca..dd6920fd 100644 --- a/src/frontend/apps/impress/src/features/docs/doc-header/components/DocToolBox.tsx +++ b/src/frontend/apps/impress/src/features/docs/doc-header/components/DocToolBox.tsx @@ -29,6 +29,7 @@ import { KEY_LIST_DOC_VERSIONS, ModalSelectVersion, } from '@/features/docs/doc-versioning'; +import { useAnalytics } from '@/libs'; import { useResponsiveStore } from '@/stores'; interface DocToolBoxProps { @@ -54,6 +55,7 @@ export const DocToolBox = ({ doc }: DocToolBoxProps) => { const { editor } = useEditorStore(); const { toast } = useToastProvider(); const copyDocLink = useCopyDocLink(doc.id); + const { isFeatureFlagActivated } = useAnalytics(); const options: DropdownMenuOption[] = [ ...(isSmallMobile @@ -101,6 +103,7 @@ export const DocToolBox = ({ doc }: DocToolBoxProps) => { callback: () => { void copyCurrentEditorToClipboard('html'); }, + show: isFeatureFlagActivated('CopyAsHTML'), }, { label: t('Delete document'),