Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix: Persist sample body #2550

Merged
merged 9 commits into from
May 15, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 12 additions & 5 deletions src/app/views/query-runner/QueryRunner.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { IDropdownOption, MessageBarType } from '@fluentui/react';
import { useState } from 'react';
import { useEffect, useState } from 'react';
import { injectIntl } from 'react-intl';
import { useDispatch } from 'react-redux';

Expand All @@ -23,6 +23,14 @@ const QueryRunner = (props: any) => {

const [sampleBody, setSampleBody] = useState('');

useEffect(() => {
if(sampleQuery.selectedVerb !== 'GET') {
const query = { ...sampleQuery };
query.sampleBody = sampleBody;
dispatch(setSampleQuery(query));
}
}, [sampleBody])

const handleOnMethodChange = (method?: IDropdownOption) => {
const query = { ...sampleQuery };
if (method !== undefined) {
Expand All @@ -39,7 +47,7 @@ const QueryRunner = (props: any) => {
};

const handleOnRunQuery = (query?: IQuery) => {
if (sampleBody) {
if (sampleBody && sampleQuery.selectedVerb !== 'GET') {
const headers = sampleQuery.sampleHeaders;
const contentType = headers.find(k => k.name.toLowerCase() === 'content-type');
if (!contentType || (contentType.value === ContentType.Json)) {
Expand All @@ -52,14 +60,14 @@ const QueryRunner = (props: any) => {
status: `${translateMessage('Review the request body')} ${error}`,
messageType: MessageBarType.error
}));
setSampleBody('');
return;
}
} else {
sampleQuery.sampleBody = sampleBody;
}
}
if(query) {

if (query) {
sampleQuery.sampleUrl = query.sampleUrl;
sampleQuery.selectedVersion = query.selectedVersion;
sampleQuery.selectedVerb = query.selectedVerb;
Expand All @@ -75,7 +83,6 @@ const QueryRunner = (props: any) => {
QuerySignature: `${sampleQuery.selectedVerb} ${sanitizedUrl}`,
...deviceCharacteristics
});
setSampleBody('');
};

const handleOnVersionChange = (urlVersion?: IDropdownOption) => {
Expand Down
26 changes: 20 additions & 6 deletions src/tests/ui/anonymous-experiences/request.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,7 @@ test.describe('Run query', () => {
})

test('Tests query parameter for beta version that do not require a $ sign', async () => {
await page.reload();
const queryInputField = page.locator('[aria-label="Query sample input"]');
await queryInputField.click();
await page.evaluate(() => document.fonts.ready);
Expand Down Expand Up @@ -242,14 +243,27 @@ test.describe('Run query', () => {
expect(page.getByText('"Microsoft Viva"')).toBeDefined();
})

test('User can add request bodies that persist when switching between tabs', async () => {
await page.locator('[aria-label="my profile"]').click();
await page.getByRole('tab', { name: 'Request body' }).click();
await page.getByRole('tab', { name: 'Request body' }).press('Tab');
await page.getByRole('textbox', { name: 'Editor content;Press Alt+F1 for Accessibility Options.' }).fill('{\n\n "$schema": {}}\n}');
await page.getByRole('tab', { name: 'Request headers' }).click();
await page.getByRole('tab', { name: 'Request body' }).click();
expect(page.getByText('"$schema"')).toBeVisible();

// Make sure that request body is not there when switching between queries
await page.getByRole('gridcell', { name: 'my profile (beta)' }).click();
expect(page.getByText('"$schema"')).not.toBeVisible();
})

test('should show documentation link for queries with links ', async () => {
await page.reload();
await page.locator('[aria-label="my profile"]').click();
await page.locator('[aria-label="More Info"]').click();
const [page3] = await Promise.all([
page.waitForEvent('popup'),
page.locator('button:has-text("Learn more")').click()
]);
expect(page3.url().indexOf('https://learn.microsoft.com/')).toBeGreaterThan(-1);
const page2Promise = page.waitForEvent('popup');
await page.getByRole('button', { name: 'Read documentation' }).click();
const page2 = await page2Promise;
expect(page2.url().indexOf('https://learn.microsoft.com/')).toBeGreaterThan(-1);
})

test('should launch the share query dialog when share query button is clicked', async () => {
Expand Down