2020-09-24 19:23:23 +00:00
|
|
|
import faker from 'faker';
|
2020-09-23 22:49:25 +00:00
|
|
|
|
2020-09-24 19:23:23 +00:00
|
|
|
export const workspaceDropdownExists = async (app, workspaceName = 'Insomnia') => {
|
2020-08-24 22:49:29 +00:00
|
|
|
await app.client.waitUntilTextExists('.workspace-dropdown', workspaceName);
|
|
|
|
};
|
|
|
|
|
2020-09-24 19:23:23 +00:00
|
|
|
export const createNewRequest = async (app, name) => {
|
2020-09-17 18:05:53 +00:00
|
|
|
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');
|
|
|
|
|
2020-09-23 22:49:25 +00:00
|
|
|
const requestName = `${name}-${faker.lorem.slug()}`;
|
|
|
|
await input.waitUntil(() => input.isFocused());
|
|
|
|
await input.keys(requestName);
|
2020-09-17 18:05:53 +00:00
|
|
|
|
|
|
|
await app.client
|
|
|
|
.$('.modal .modal__footer')
|
|
|
|
.then(e => e.$('button=Create'))
|
|
|
|
.then(e => e.click());
|
|
|
|
|
2020-09-23 22:49:25 +00:00
|
|
|
await waitUntilRequestIsActive(app, requestName);
|
2020-09-17 18:05:53 +00:00
|
|
|
};
|
|
|
|
|
2020-09-23 22:49:25 +00:00
|
|
|
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-21 06:17:31 +00:00
|
|
|
|
2020-09-24 19:23:23 +00:00
|
|
|
export const typeInUrlBar = async (app, url) => {
|
2020-09-23 22:49:25 +00:00
|
|
|
const urlEditor = await app.client.react$('RequestUrlBar');
|
|
|
|
await urlEditor.waitForExist();
|
|
|
|
await urlEditor.click();
|
|
|
|
await urlEditor.keys(url);
|
2020-09-17 18:05:53 +00:00
|
|
|
};
|
|
|
|
|
2020-09-24 19:23:23 +00:00
|
|
|
export const clickSendRequest = async app => {
|
2020-09-23 22:49:25 +00:00
|
|
|
await app.client
|
|
|
|
.react$('RequestUrlBar')
|
|
|
|
.then(e => e.$('.urlbar__send-btn'))
|
|
|
|
.then(e => e.click());
|
2020-09-17 18:05:53 +00:00
|
|
|
};
|
|
|
|
|
2020-09-24 19:23:23 +00:00
|
|
|
export const expect200 = async app => {
|
2020-09-17 18:05:53 +00:00
|
|
|
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 => {
|
2020-09-17 18:05:53 +00:00
|
|
|
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 => {
|
2020-09-21 08:45:36 +00:00
|
|
|
const pdfViewer = await app.client.react$('ResponsePDFViewer');
|
|
|
|
await pdfViewer.waitForDisplayed();
|
|
|
|
const canvas = await pdfViewer.$('.S-PDF-ID canvas');
|
|
|
|
await canvas.waitForDisplayed();
|
|
|
|
return canvas;
|
|
|
|
};
|