1
0
mirror of https://github.com/laurent22/joplin.git synced 2025-12-20 23:30:05 +02:00

Chore: Mobile: Add additional plugin panel integration tests (#13152)

This commit is contained in:
Henry Heino
2025-09-08 16:31:12 -07:00
committed by GitHub
parent 1762f9485f
commit 15c973e885
7 changed files with 285 additions and 211 deletions

View File

@@ -6,11 +6,12 @@ import createMockReduxStore from '../../utils/testing/createMockReduxStore';
import setupGlobalStore from '../../utils/testing/setupGlobalStore';
import PluginRunnerWebView from './PluginRunnerWebView';
import TestProviderStack from '../testing/TestProviderStack';
import { render, waitFor } from '../../utils/testing/testingLibrary';
import { act, render, screen, waitFor } from '../../utils/testing/testingLibrary';
import createTestPlugin from '@joplin/lib/testing/plugins/createTestPlugin';
import getWebViewDomById from '../../utils/testing/getWebViewDomById';
import Setting from '@joplin/lib/models/Setting';
import PluginService from '@joplin/lib/services/plugins/PluginService';
import CommandService from '@joplin/lib/services/CommandService';
let store: Store<AppState>;
@@ -30,6 +31,16 @@ const defaultManifestProperties = {
name: 'Some plugin name',
};
type PluginSlice = { manifest: { id: string } };
const waitForPluginToLoad = (plugin: PluginSlice) => {
return waitFor(async () => {
expect(PluginService.instance().pluginById(plugin.manifest.id)).toBeTruthy();
});
};
const webViewId = 'joplin__PluginDialogWebView';
const getUserWebViewDom = () => getWebViewDomById(webViewId);
describe('PluginRunnerWebView', () => {
beforeEach(async () => {
await setupDatabaseAndSynchronizer(0);
@@ -56,16 +67,68 @@ describe('PluginRunnerWebView', () => {
`,
});
render(<WrappedPluginRunnerWebView/>);
// Should load the plugin
await waitFor(async () => {
expect(PluginService.instance().pluginById(testPlugin.manifest.id)).toBeTruthy();
});
await waitForPluginToLoad(testPlugin);
// Should show the dialog
await waitFor(async () => {
const dom = await getWebViewDomById('joplin__PluginDialogWebView');
const dom = await getUserWebViewDom();
expect(dom.querySelector('h1').textContent).toBe('Test!');
});
});
test('should load a plugin that adds a panel', async () => {
const testPlugin = await createTestPlugin({
...defaultManifestProperties,
id: 'org.joplinapp.panel-test',
}, {
onStart: `
const panels = joplin.views.panels;
const handle = await panels.create('test-panel');
await panels.setHtml(
handle,
'<h1>Panel content</h1><p>Test</p>',
);
const commands = joplin.commands;
await commands.register({
name: 'hideTestPanel',
label: 'Hide the test plugin panel',
execute: async () => {
await panels.hide(handle);
},
});
await commands.register({
name: 'showTestPanel',
execute: async () => {
await panels.show(handle);
},
});
`,
});
render(<WrappedPluginRunnerWebView/>);
await waitForPluginToLoad(testPlugin);
act(() => {
store.dispatch({ type: 'SET_PLUGIN_PANELS_DIALOG_VISIBLE', visible: true });
});
const expectPanelVisible = async () => {
const dom = await getUserWebViewDom();
await waitFor(async () => {
expect(dom.querySelector('h1').textContent).toBe('Panel content');
});
};
await expectPanelVisible();
// Should hide the panel
await act(() => CommandService.instance().execute('hideTestPanel'));
await waitFor(() => {
expect(screen.queryByTestId('webViewId')).toBeNull();
});
// Should show the panel again
await act(() => CommandService.instance().execute('showTestPanel'));
await expectPanelVisible();
});
});