Skip to content

Commit

Permalink
feat: added jest test case for the same
Browse files Browse the repository at this point in the history
  • Loading branch information
vikrantgupta25 committed May 23, 2024
1 parent 7eac588 commit a1de063
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 2 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import { act, renderHook, waitFor } from '@testing-library/react';
import { createMemoryHistory } from 'history';
import { Router } from 'react-router-dom';

import ResourceProvider from '../ResourceProvider';
import useResourceAttribute from '../useResourceAttribute';

describe('useResourceAttribute component hook', () => {
it('should not change other query params except for resourceAttribute', async () => {
const history = createMemoryHistory({
initialEntries: ['/inital-url?tab=overview'],
});
const wrapper = ({ children }: { children: any }): JSX.Element => (
<Router history={history}>
<ResourceProvider>{children}</ResourceProvider>
</Router>
);
const { result } = renderHook(() => useResourceAttribute(), { wrapper });

act(() => {
result.current.handleEnvironmentChange(['production']);
});

await waitFor(() =>
expect(history.location.search).toContain('tab=overview'),
);
});
});
3 changes: 1 addition & 2 deletions frontend/src/hooks/useResourceAttribute/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -176,8 +176,6 @@ export const GetTagValues = async (tagKey: string): Promise<IOption[]> => {
export const createQuery = (
selectedItems: Array<string | string[]> = [],
): IResourceAttribute | null => {
console.log('selectedItems', selectedItems);

if (selectedItems.length === 3) {
return {
id: uuid().slice(0, 8),
Expand All @@ -192,6 +190,7 @@ export const createQuery = (
export const updateQuery = (
queryKey: string,
selectedItems: Array<string | string[]> = [],
// eslint-disable-next-line sonarjs/no-identical-functions
): IResourceAttribute | null => {
if (selectedItems.length === 3) {
return {
Expand Down

0 comments on commit a1de063

Please sign in to comment.