insomnia/packages/insomnia-smoke-test/core/app.test.js

94 lines
3.0 KiB
JavaScript
Raw Normal View History

2020-09-24 19:23:23 +00:00
import * as debug from '../modules/debug';
import * as client from '../modules/client';
import { launchCore, stop } from '../modules/application';
import * as dropdown from '../modules/dropdown';
import * as settings from '../modules/settings';
import fs from 'fs';
2020-08-20 20:08:47 +00:00
describe('Application launch', function() {
jest.setTimeout(50000);
let app = null;
beforeEach(async () => {
app = await launchCore();
2020-08-20 20:08:47 +00:00
});
afterEach(async () => {
await stop(app);
2020-08-20 20:08:47 +00:00
});
it('shows an initial window', async () => {
await client.correctlyLaunched(app);
await debug.workspaceDropdownExists(app);
2020-08-20 20:08:47 +00:00
});
it('sends JSON request', async () => {
const url = 'http://127.0.0.1:4010/pets/1';
await debug.workspaceDropdownExists(app);
await debug.createNewRequest(app, 'json');
await debug.typeInUrlBar(app, url);
await debug.clickSendRequest(app);
await debug.expect200(app);
});
it.each([true, false])(
'imports swagger 2 and sends request: new workspace=%s ',
async newWorkspace => {
await debug.workspaceDropdownExists(app);
// Copy text to clipboard
const buffer = await fs.promises.readFile(`${__dirname}/../fixtures/swagger2.yaml`);
const swagger2Text = buffer.toString();
await app.electron.clipboard.writeText(swagger2Text);
// Click dropdown and open import modal
const workspaceDropdown = await debug.clickWorkspaceDropdown(app);
await dropdown.clickDropdownItemByText(workspaceDropdown, 'Import/Export');
// Import from clipboard into new/current workspace
await settings.importFromClipboard(app, newWorkspace);
// Click imported folder and request
await debug.clickFolderByName(app, 'custom-tag');
await debug.clickRequestByName(app, 'get pet by id');
// Click send
await debug.clickSendRequest(app);
// Ensure 200
await debug.expect200(app);
},
);
it('sends CSV request and shows rich response', async () => {
const url = 'http://127.0.0.1:4010/csv';
await debug.workspaceDropdownExists(app);
await debug.createNewRequest(app, 'csv');
await debug.typeInUrlBar(app, url);
await debug.clickSendRequest(app);
await debug.expect200(app);
const csvViewer = await debug.getCsvViewer(app);
await expect(csvViewer.getText()).resolves.toBe('a b c\n1 2 3');
});
it('sends PDF request and shows rich response', async () => {
// Cannot mock the pdf response using Prism because it is not yet supported
// https://github.com/stoplightio/prism/issues/1248#issuecomment-646056440
const url = 'https://www.w3.org/WAI/ER/tests/xhtml/testfiles/resources/pdf/dummy.pdf';
await debug.workspaceDropdownExists(app);
await debug.createNewRequest(app, 'pdf');
await debug.typeInUrlBar(app, url);
await debug.clickSendRequest(app);
await debug.expect200(app);
const pdfCanvas = await debug.getPdfCanvas(app);
// Investigate how we can extract text from the canvas, or compare images
await expect(pdfCanvas.isExisting()).resolves.toBe(true);
});
2020-08-20 20:08:47 +00:00
});