Skip to content
Snippets Groups Projects
Commit 1a6cc978 authored by mateusz-winiarczyk's avatar mateusz-winiarczyk
Browse files

fix(plugin): set plugin active tab in drawer as loaded plugin from url (MIN-295)

parent d37c18a5
No related branches found
No related tags found
2 merge requests!223reset the pin numbers before search results are fetch (so the results will be...,!145fix(plugin): set plugin active tab in drawer as loaded plugin from url (MIN-295)
......@@ -9,7 +9,7 @@ import { StoreType } from '@/redux/store';
import { mockNetworkResponse } from '@/utils/mockNetworkResponse';
import { InitialStoreState } from '@/utils/testing/getReduxStoreActionsListener';
import { getReduxWrapperWithStore } from '@/utils/testing/getReduxWrapperWithStore';
import { fireEvent, render, screen } from '@testing-library/react';
import { fireEvent, render, screen, waitFor } from '@testing-library/react';
import axios, { HttpStatusCode } from 'axios';
import MockAdapter from 'axios-mock-adapter';
import { act } from 'react-dom/test-utils';
......@@ -163,5 +163,36 @@ describe('LoadPluginFromUrl - component', () => {
const button = screen.getByTestId('load-plugin-button');
expect(button).toBeDisabled();
});
it('should set plugin active tab in drawer as loaded plugin', async () => {
const pluginUrl = 'http://example.com/plugin.js';
const pluginScript = `function init() {} init()`;
mockedAxiosClient.onGet(pluginUrl).reply(HttpStatusCode.Ok, pluginScript);
global.URL.canParse = jest.fn().mockReturnValue(true);
const { store } = renderComponent();
const dispatchSpy = jest.spyOn(store, 'dispatch');
const input = screen.getByTestId('load-plugin-input-url');
expect(input).toBeVisible();
act(() => {
fireEvent.change(input, { target: { value: pluginUrl } });
});
const button = screen.getByTestId('load-plugin-button');
act(() => {
button.click();
});
await waitFor(() => {
expect(dispatchSpy).toHaveBeenCalledWith({
payload: 'e008fb2ceb97e3d6139ffe38a1b39d5d',
type: 'plugins/setCurrentDrawerPluginHash',
});
});
});
});
});
import { useAppDispatch } from '@/redux/hooks/useAppDispatch';
import { useAppSelector } from '@/redux/hooks/useAppSelector';
import { activePluginsDataSelector } from '@/redux/plugins/plugins.selectors';
import { setCurrentDrawerPluginHash } from '@/redux/plugins/plugins.slice';
import { PluginsManager } from '@/services/pluginsManager';
import axios from 'axios';
import { ChangeEvent, useMemo, useState } from 'react';
......@@ -15,12 +17,17 @@ export const useLoadPluginFromUrl = (): UseLoadPluginReturnType => {
const [pluginUrl, setPluginUrl] = useState('');
const [isLoading, setIsLoading] = useState(false);
const activePlugins = useAppSelector(activePluginsDataSelector);
const dispatch = useAppDispatch();
const isPending = useMemo(
() => !pluginUrl || isLoading || !URL.canParse(pluginUrl),
[pluginUrl, isLoading],
);
const handleSetCurrentDrawerPluginHash = (hash: string): void => {
dispatch(setCurrentDrawerPluginHash(hash));
};
const handleLoadPlugin = async (): Promise<void> => {
try {
setIsLoading(true);
......@@ -40,6 +47,8 @@ export const useLoadPluginFromUrl = (): UseLoadPluginReturnType => {
}
setPluginUrl('');
handleSetCurrentDrawerPluginHash(hash);
} finally {
setIsLoading(false);
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment