Skip to content

Commit

Permalink
added tests for OrganizationNavbar component
Browse files Browse the repository at this point in the history
  • Loading branch information
lakshz committed Dec 3, 2023
1 parent da35be1 commit 8718486
Showing 1 changed file with 67 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import React from 'react';
import { MockedProvider } from '@apollo/react-testing';
import 'jest-localstorage-mock';
import { act, render, screen } from '@testing-library/react';
import { I18nextProvider } from 'react-i18next';
import { Provider } from 'react-redux';
Expand Down Expand Up @@ -233,4 +234,70 @@ describe('Testing OrganizationNavbar Component [User Portal]', () => {

expect(cookies.get('i18next')).toBe('zh');
});

test('Component should be rendered properly if plugins with view are present in localStorage', async () => {
const testPlugins = [
{
pluginName: 'TestPlugin1',
alias: 'testPlugin1',
link: '/testPlugin1',
translated: 'Test Plugin 1',
view: true,
},
];
localStorage.setItem('talawaPlugins', JSON.stringify(testPlugins));

render(
<MockedProvider addTypename={false} link={link}>
<BrowserRouter>
<Provider store={store}>
<I18nextProvider i18n={i18nForTest}>
<OrganizationNavbar {...navbarProps} />
</I18nextProvider>
</Provider>
</BrowserRouter>
</MockedProvider>
);

await wait();

testPlugins.forEach((plugin) => {
expect(screen.getByText(plugin.translated)).toBeInTheDocument();
});

localStorage.removeItem('talawaPlugins');
});

test('Component should be rendered properly if plugins without view are present in localStorage', async () => {
const testPlugins = [
{
pluginName: 'TestPlugin1',
alias: 'testPlugin1',
link: '/testPlugin1',
translated: 'Test Plugin 1',
view: false,
},
];
localStorage.setItem('talawaPlugins', JSON.stringify(testPlugins));

render(
<MockedProvider addTypename={false} link={link}>
<BrowserRouter>
<Provider store={store}>
<I18nextProvider i18n={i18nForTest}>
<OrganizationNavbar {...navbarProps} />
</I18nextProvider>
</Provider>
</BrowserRouter>
</MockedProvider>
);

await wait();

testPlugins.forEach((plugin) => {
expect(screen.getByText(plugin.translated)).not.toBeInTheDocument();
});

localStorage.removeItem('talawaPlugins');
});
});

0 comments on commit 8718486

Please sign in to comment.