added integration test for the link inside the info modal. #849.

This commit is contained in:
davemfish 2022-04-20 09:32:33 -04:00
parent 3e31086d0c
commit 192fba8bf5
3 changed files with 22 additions and 11 deletions

View File

@ -84,5 +84,6 @@ export const screen = {
};
export const shell = {
showItemInFolder: jest.fn()
showItemInFolder: jest.fn(),
openExternal: jest.fn(),
};

View File

@ -8,7 +8,6 @@ import { ipcMainChannels } from './ipcMainChannels';
export default function setupOpenExternalUrl() {
ipcMain.on(
ipcMainChannels.OPEN_EXTERNAL_URL, (event, url) => {
event.preventDefault();
shell.openExternal(url);
}
);

View File

@ -1,4 +1,4 @@
import { ipcRenderer } from 'electron';
import { ipcRenderer, shell } from 'electron';
import React from 'react';
import {
createEvent, fireEvent, render, waitFor, within
@ -10,6 +10,8 @@ import SetupTab from '../../src/renderer/components/SetupTab';
import {
fetchDatastackFromFile, fetchValidation
} from '../../src/renderer/server_requests';
import setupOpenExternalUrl from '../../src/main/setupOpenExternalUrl';
import { removeIpcMainListeners } from '../../src/main/main';
jest.mock('../../src/renderer/server_requests');
@ -149,14 +151,6 @@ describe('Arguments form input types', () => {
expect(input).toHaveValue('a');
expect(input).not.toHaveValue('b');
});
test('expect the info dialog contains text about input', async () => {
const spec = baseArgsSpec('directory');
const { findByText, findByRole } = renderSetupFromSpec(spec, UI_SPEC);
userEvent.click(await findByRole('button', { name: /info about/ }));
expect(await findByText(spec.args.arg.about)).toBeInTheDocument();
await findByRole('link', { name: /user guide/ });
});
});
describe('Arguments form interactions', () => {
@ -164,6 +158,11 @@ describe('Arguments form interactions', () => {
fetchValidation.mockResolvedValue(
[[Object.keys(BASE_ARGS_SPEC.args), VALIDATION_MESSAGE]]
);
setupOpenExternalUrl();
});
afterEach(() => {
removeIpcMainListeners();
});
test('Browse button populates an input', async () => {
@ -311,6 +310,18 @@ describe('Arguments form interactions', () => {
expect(input).toHaveClass('is-valid');
});
});
test('Open info dialog, expect text & link', async () => {
const spec = baseArgsSpec('directory');
const { findByText, findByRole } = renderSetupFromSpec(spec, UI_SPEC);
userEvent.click(await findByRole('button', { name: /info about/ }));
expect(await findByText(spec.args.arg.about)).toBeInTheDocument();
const link = await findByRole('link', { name: /user guide/ });
userEvent.click(link);
await waitFor(() => {
expect(shell.openExternal).toHaveBeenCalledTimes(1);
});
});
});
describe('UI spec functionality', () => {