insomnia/packages/insomnia-smoke-test/tests/smoke/graphql.test.ts
Filipe Freire b7028eb62a
Reproduce GraphQL unknown operation named issue (#5681)
* Add smoke check to reproduce #5665

* add debug code

* clean up

Co-authored-by: Mark Kim <mark.kim@konghq.com>
2023-01-17 10:55:39 -05:00

72 lines
3.2 KiB
TypeScript

import { expect } from '@playwright/test';
import { loadFixture } from '../../playwright/paths';
import { test } from '../../playwright/test';
test('can render schema and send GraphQL requests', async ({ app, page }) => {
test.slow(process.platform === 'darwin' || process.platform === 'win32', 'Slow app start on these platforms');
// Create a new the project
await page.click('[data-testid="project"]');
await page.click('text=Create');
// Copy the collection with the graphql query to clipboard
const text = await loadFixture('graphql.yaml');
await app.evaluate(async ({ clipboard }, text) => clipboard.writeText(text), text);
// Import from clipboard
await page.click('button:has-text("Clipboard")');
// Open the new collection workspace
await page.click('text=CollectionSmoke GraphQLjust now');
// Open the graphql request
await page.click('button:has-text("POSTGQLGraphQL request")');
// Assert the schema is fetched after switching to GraphQL request
await expect(page.locator('.app')).toContainText('schema fetched just now');
// Assert schema documentation stuff
await page.click('[data-testid="request-pane"] button:has-text("schema")');
await page.click('button:has-text("Show Documentation")');
await page.click('a:has-text("Query")');
await page.locator('a:has-text("RingBearer")').click();
const graphqlExplorer = page.locator('.graphql-explorer');
await expect(graphqlExplorer).toContainText('Characters who at any time bore a Ring of Power.');
await page.click('text=QueryRingBearer >> button');
// Send and assert GraphQL request
await page.click('[data-testid="request-pane"] >> text=Send');
const statusTag = page.locator('[data-testid="response-status-tag"]:visible');
await expect(statusTag).toContainText('200 OK');
const responseBody = page.locator('[data-testid="response-pane"] >> [data-testid="CodeEditor"]:visible', {
has: page.locator('.CodeMirror-activeline'),
});
await expect(responseBody).toContainText('"bearer": "Gandalf"');
});
test('can send GraphQL requests after editing and prettifying query', async ({ app, page }) => {
test.slow(process.platform === 'darwin' || process.platform === 'win32', 'Slow app start on these platforms');
// Create a new the project
await page.click('[data-testid="project"]');
await page.click('text=Create');
const text = await loadFixture('graphql.yaml');
await app.evaluate(async ({ clipboard }, text) => clipboard.writeText(text), text);
await page.click('button:has-text("Clipboard")');
await page.click('text=CollectionSmoke GraphQLjust now');
await page.click('button:has-text("POSTGQLGraphQL request")');
// Edit and prettify query
await page.locator('pre[role="presentation"]:has-text("hello,")').click();
await page.locator('.app').press('Enter');
await page.locator('text=Prettify GraphQL').click();
await page.click('[data-testid="request-pane"] >> text=Send');
const statusTag = page.locator('[data-testid="response-status-tag"]:visible');
await expect(statusTag).toContainText('200 OK');
const responseBody = page.locator('[data-testid="response-pane"] >> [data-testid="CodeEditor"]:visible', {
has: page.locator('.CodeMirror-activeline'),
});
await expect(responseBody).toContainText('"bearer": "Gandalf"');
});