Skip to content

Commit

Permalink
Added tests for src/components/AddOn/core/AddOnEntry/AddOnEntry.tsx (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
sahadat-sk authored Dec 1, 2023
1 parent 4737b34 commit e713ab6
Show file tree
Hide file tree
Showing 2 changed files with 114 additions and 0 deletions.
89 changes: 89 additions & 0 deletions src/components/AddOn/core/AddOnEntry/AddOnEntry.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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(
<MockedProvider addTypename={false} link={link}>
<Provider store={store}>
<BrowserRouter>
<I18nextProvider i18n={i18nForTest}>
<ToastContainer />
{<AddOnEntry {...props} />}
</I18nextProvider>
</BrowserRouter>
</Provider>
</MockedProvider>
);
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(
<MockedProvider addTypename={false} link={link}>
<Provider store={store}>
<BrowserRouter>
<I18nextProvider i18n={i18nForTest}>
{<AddOnEntry {...props} />}
</I18nextProvider>
</BrowserRouter>
</Provider>
</MockedProvider>
);
await wait(100);
const btn = getByTestId('AddOnEntry_btn_install');
expect(btn.innerHTML).toMatch(/install/i);
debug();
});
});
25 changes: 25 additions & 0 deletions src/components/AddOn/core/AddOnEntry/AddOnEntryMocks.ts
Original file line number Diff line number Diff line change
@@ -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,
},
},
},
];

0 comments on commit e713ab6

Please sign in to comment.