diff --git a/src/components/AddOn/core/AddOnEntry/AddOnEntry.test.tsx b/src/components/AddOn/core/AddOnEntry/AddOnEntry.test.tsx index 50e56adf1e..65a2604ff2 100644 --- a/src/components/AddOn/core/AddOnEntry/AddOnEntry.test.tsx +++ b/src/components/AddOn/core/AddOnEntry/AddOnEntry.test.tsx @@ -16,6 +16,14 @@ import { store } from 'state/store'; import { BACKEND_URL } from 'Constant/constant'; import i18nForTest from 'utils/i18nForTest'; import { I18nextProvider } from 'react-i18next'; +import { debug } from 'jest-preview'; +import userEvent from '@testing-library/user-event'; +import { MockedProvider, wait } from '@apollo/react-testing'; +import { StaticMockLink } from 'utils/StaticMockLink'; +import { ADD_ON_ENTRY_MOCK } from './AddOnEntryMocks'; +import { ToastContainer } from 'react-toastify'; + +const link = new StaticMockLink(ADD_ON_ENTRY_MOCK, true); const httpLink = new HttpLink({ uri: BACKEND_URL, @@ -95,4 +103,85 @@ describe('Testing AddOnEntry', () => { expect(getByText('Test addon description')).toBeInTheDocument(); expect(getByText('Test User')).toBeInTheDocument(); }); + it('Uninstall Button works correctly', async () => { + const props = { + id: '1', + title: 'Test Addon', + description: 'Test addon description', + createdBy: 'Test User', + component: 'string', + installed: true, + configurable: true, + modified: true, + isInstalled: true, + uninstalledOrgs: [], + enabled: true, + getInstalledPlugins: (): { sample: string } => { + return { sample: 'sample' }; + }, + }; + + const { findByText, getByTestId } = render( + + + + + + {} + + + + + ); + await wait(100); + const btn = getByTestId('AddOnEntry_btn_install'); + await userEvent.click(btn); + await wait(100); + expect(btn.innerHTML).toMatch(/Install/i); + expect( + await findByText('This feature is now removed from your organization') + ).toBeInTheDocument(); + await userEvent.click(btn); + await wait(100); + + expect(btn.innerHTML).toMatch(/Uninstall/i); + expect( + await findByText('This feature is now enabled in your organization') + ).toBeInTheDocument(); + }); + + it('Check if uninstalled orgs includes current org', async () => { + const props = { + id: '1', + title: 'Test Addon', + description: 'Test addon description', + createdBy: 'Test User', + component: 'string', + installed: true, + configurable: true, + modified: true, + isInstalled: true, + uninstalledOrgs: ['undefined'], + enabled: true, + getInstalledPlugins: (): { sample: string } => { + return { sample: 'sample' }; + }, + }; + + const { getByTestId } = render( + + + + + {} + + + + + ); + await wait(100); + const btn = getByTestId('AddOnEntry_btn_install'); + expect(btn.innerHTML).toMatch(/install/i); + debug(); + }); }); diff --git a/src/components/AddOn/core/AddOnEntry/AddOnEntryMocks.ts b/src/components/AddOn/core/AddOnEntry/AddOnEntryMocks.ts new file mode 100644 index 0000000000..3967a0963a --- /dev/null +++ b/src/components/AddOn/core/AddOnEntry/AddOnEntryMocks.ts @@ -0,0 +1,25 @@ +import { UPDATE_INSTALL_STATUS_PLUGIN_MUTATION } from 'GraphQl/Mutations/mutations'; + +// Mock data representing the response structure of the mutation +const updatePluginStatus = { + _id: '123', + pluginName: 'Sample Plugin', + pluginCreatedBy: 'John Doe', + pluginDesc: 'This is a sample plugin description.', + uninstalledOrgs: [], +}; + +// Creating the mock entry +export const ADD_ON_ENTRY_MOCK = [ + { + request: { + query: UPDATE_INSTALL_STATUS_PLUGIN_MUTATION, + variables: { id: '1', orgId: 'undefined' }, + }, + result: { + data: { + updatePluginStatus: updatePluginStatus, + }, + }, + }, +];