insomnia/packages/insomnia-smoke-test/modules/debug.js

77 lines
2.3 KiB
JavaScript
Raw Normal View History

2020-09-24 19:23:23 +00:00
import faker from 'faker';
2020-09-24 19:23:23 +00:00
export const workspaceDropdownExists = async (app, workspaceName = 'Insomnia') => {
await app.client.waitUntilTextExists('.workspace-dropdown', workspaceName);
};
2020-09-24 19:23:23 +00:00
export const createNewRequest = async (app, name) => {
await app.client.$('.sidebar .dropdown .fa-plus-circle').then(e => e.click());
await app.client
.$('[aria-hidden=false]')
.then(e => e.$('button*=New Request'))
.then(e => e.click());
// Wait for modal to open
await app.client.waitUntilTextExists('.modal__header', 'New Request');
// Set name and create request
const input = await app.client.$('.modal input');
const requestName = `${name}-${faker.lorem.slug()}`;
await input.waitUntil(() => input.isFocused());
await input.keys(requestName);
await app.client
.$('.modal .modal__footer')
.then(e => e.$('button=Create'))
.then(e => e.click());
await waitUntilRequestIsActive(app, requestName);
};
const waitUntilRequestIsActive = async (app, name) => {
const requestIsActive = async () => {
const requests = await app.client.react$$('SidebarRequestRow', { props: { isActive: true } });
const firstRequest = requests[0];
const activeRequestName = await firstRequest.react$('Editable').then(e => e.getText());
return activeRequestName === name;
};
await app.client.waitUntil(requestIsActive);
};
2020-09-24 19:23:23 +00:00
export const typeInUrlBar = async (app, url) => {
const urlEditor = await app.client.react$('RequestUrlBar');
await urlEditor.waitForExist();
await urlEditor.click();
await urlEditor.keys(url);
};
2020-09-24 19:23:23 +00:00
export const clickSendRequest = async app => {
await app.client
.react$('RequestUrlBar')
.then(e => e.$('.urlbar__send-btn'))
.then(e => e.click());
};
2020-09-24 19:23:23 +00:00
export const expect200 = async app => {
const tag = await app.client.$('.response-pane .pane__header .tag.bg-success');
await tag.waitForDisplayed();
await expect(tag.getText()).resolves.toBe('200 OK');
};
2020-09-24 19:23:23 +00:00
export const getCsvViewer = async app => {
const csvViewer = await app.client.react$('ResponseCSVViewer');
await csvViewer.waitForDisplayed();
return csvViewer;
};
2020-09-24 19:23:23 +00:00
export const getPdfCanvas = async app => {
const pdfViewer = await app.client.react$('ResponsePDFViewer');
await pdfViewer.waitForDisplayed();
const canvas = await pdfViewer.$('.S-PDF-ID canvas');
await canvas.waitForDisplayed();
return canvas;
};