insomnia/packages/insomnia-smoke-test/modules/home.ts
Opender Singh 5fa8f0069d
Enable ESLint & TS for smoke tests (#3397)
* remove babel and add configs

* add ts-node

* lint scripts

* eslint override

* remove type module

* add expect errors

* update js files to ts

* fix electron import

* remove errors

* update readme

* add build step

* typesync

* add eslintignore
2021-05-19 07:49:48 -04:00

87 lines
2.7 KiB
TypeScript

import * as dropdown from './dropdown';
import * as modal from './modal';
import findAsync from './find-async';
import * as debug from './debug';
import faker from 'faker';
export const documentListingShown = async app => {
const item = await app.client.$('.document-listing');
await item.waitForExist();
};
export const expectDocumentWithTitle = async (app, title) => {
await app.client.waitUntilTextExists('.document-listing__body', title);
};
export const findCardWithTitle = async (app, text) => {
let card;
await app.client.waitUntil(async () => {
const cards = await app.client.react$$('Card');
card = await findAsync(
cards,
async i => (await i.react$('CardBody').then(e => e.$('.title')).then(e => e.getText())) === text,
);
return !!card;
});
return card;
};
export const cardHasBadge = async (card, text) => {
const badge = await card.$('.header-item.card-badge');
expect(await badge.getText()).toBe(text);
};
export const openDocumentWithTitle = async (app, text) => {
const card = await findCardWithTitle(app, text);
await card.waitForDisplayed();
await card.click();
await debug.pageDisplayed(app);
};
export const expectTotalDocuments = async (app, count) => {
const label = count > 1 ? 'Documents' : 'Document';
await app.client.waitUntilTextExists('.document-listing__footer', `${count} ${label}`);
};
export const openDocumentMenuDropdown = async card => {
const dropdown = await card.react$('DocumentCardDropdown');
await dropdown.click();
};
const openCreateDropdown = async app => {
const button = await app.client.$('button*=Create');
await button.waitForClickable();
await button.click();
};
export const createNewCollection = async (app, prefix = 'coll') => {
await openCreateDropdown(app);
await dropdown.clickDropdownItemByText(app.client, 'Request Collection');
const collectionName = `${prefix}-${faker.lorem.slug()}`;
await modal.waitUntilOpened(app, { title: 'Create New Request Collection' });
await modal.typeIntoModalInput(app, collectionName);
await modal.clickModalFooterByText(app, 'Create');
return collectionName;
};
export const createNewDocument = async (app, prefix = 'doc') => {
await openCreateDropdown(app);
await dropdown.clickDropdownItemByText(app.client, 'Design Document');
const documentName = `${prefix}-${faker.lorem.slug()}`;
await modal.waitUntilOpened(app, { title: 'Create New Design Document' });
await modal.typeIntoModalInput(app, documentName);
await modal.clickModalFooterByText(app, 'Create');
return documentName;
};
export const importFromClipboard = async app => {
await openCreateDropdown(app);
await dropdown.clickDropdownItemByText(app.client, 'Clipboard');
};