Skip to content

Commit

Permalink
add smoke tests around environment modal persistance
Browse files Browse the repository at this point in the history
  • Loading branch information
oahmed-OS authored and filfreire committed Apr 29, 2024
1 parent 9d8f50d commit b03d873
Show file tree
Hide file tree
Showing 2 changed files with 235 additions and 0 deletions.
107 changes: 107 additions & 0 deletions packages/insomnia-smoke-test/fixtures/environment-overrides.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
_type: export
__export_format: 4
__export_date: 2024-04-28T02:01:29.930Z
__export_source: insomnia.desktop.app:v9.0.0
resources:
- _id: req_445302d6a15b4486aa703938ca682129
parentId: fld_73ddc00d7ffe4424a7682e74fd1687a5
modified: 1714268969518
created: 1714268969518
url: ""
name: New Request
description: ""
method: GET
body: {}
preRequestScript: ""
parameters: []
headers:
- name: User-Agent
value: insomnia/9.0.0
authentication: {}
metaSortKey: -1714268969518
isPrivate: false
pathParameters: []
settingStoreCookies: true
settingSendCookies: true
settingDisableRenderRequestBody: false
settingEncodeUrl: true
settingRebuildPath: true
settingFollowRedirects: global
_type: request
- _id: fld_73ddc00d7ffe4424a7682e74fd1687a5
parentId: wrk_7042f1d23c6045c0af7c931331246be7
modified: 1714268838706
created: 1714268820327
name: Test Folder
description: ""
environment:
insomnia: kong
environmentPropertyOrder:
"&":
- insomnia
metaSortKey: -1714268820327
_type: request_group
- _id: wrk_7042f1d23c6045c0af7c931331246be7
parentId: null
modified: 1714269681090
created: 1714081773122
name: Test Environment Modal
description: ""
scope: collection
_type: workspace
- _id: req_52e6e293c3b248bd91b236db14bf7b75
parentId: fld_ed4dfe1b7c334841974104529db2540f
modified: 1714268978925
created: 1714268978925
url: ""
name: New Request
description: ""
method: GET
body: {}
preRequestScript: ""
parameters: []
headers:
- name: User-Agent
value: insomnia/9.0.0
authentication: {}
metaSortKey: -1714268978925
isPrivate: false
pathParameters: []
settingStoreCookies: true
settingSendCookies: true
settingDisableRenderRequestBody: false
settingEncodeUrl: true
settingRebuildPath: true
settingFollowRedirects: global
_type: request
- _id: fld_ed4dfe1b7c334841974104529db2540f
parentId: wrk_7042f1d23c6045c0af7c931331246be7
modified: 1714268988093
created: 1714081789377
name: Test Nunjucks Folder
description: ""
environment:
sample_config: "{% base64 'encode', 'normal', 'hey' %}"
environmentPropertyOrder:
"&":
- sample_config
metaSortKey: -1714081789377
_type: request_group
- _id: env_e31d6d6c83da85667dbb29f3ff5ff2f4d46a762c
parentId: wrk_7042f1d23c6045c0af7c931331246be7
modified: 1714269066831
created: 1714081773123
name: Base Environment
data: {}
dataPropertyOrder: {}
color: null
isPrivate: false
metaSortKey: 1714081773123
_type: environment
- _id: jar_e31d6d6c83da85667dbb29f3ff5ff2f4d46a762c
parentId: wrk_7042f1d23c6045c0af7c931331246be7
modified: 1714081773124
created: 1714081773124
name: Default Jar
cookies: []
_type: cookie_jar
Original file line number Diff line number Diff line change
@@ -0,0 +1,128 @@
import { expect } from '@playwright/test';

import { loadFixture } from '../../playwright/paths';
import { test } from '../../playwright/test';

test.describe('Environment Edit Modal', async () => {

test.beforeEach(async ({ app, page }) => {
await page.getByRole('button', { name: 'Create in project' }).click();
const text = await loadFixture('environment-overrides.yaml');
await app.evaluate(async ({ clipboard }, text) => clipboard.writeText(text), text);
await page.getByRole('menuitemradio', { name: 'Import' }).click();
await page.locator('[data-test-id="import-from-clipboard"]').click();
await page.getByRole('button', { name: 'Scan' }).click();
await page.getByRole('dialog').getByRole('button', { name: 'Import' }).click();
await page.getByText('Test Environment Modal').click();
});

// rename an existing environment
test('Add new string variable to new environment overrides folder', async ({ page }) => {
// Create new Folder
await page.getByLabel('Create in collection').click();
await page.getByLabel('New Folder').click();
await page.locator('#prompt-input').fill('New Folder');
await page.getByText('New Folder').press('Enter');

// Open 'New folder' folder
await page.getByTestId('Dropdown-New-Folder').click();
await page.getByRole('menuitemradio', { name: 'Environment' }).click();

// Add a new string environment variable
const expected = '{ "foo":"bar" }';
const editor = await page.getByTestId('CodeEditor').getByRole('textbox');
const selectAllShortcut = process.platform === 'darwin' ? 'Meta+A' : 'Control+A';
await editor.press(selectAllShortcut);
await editor.fill(expected);

// Close and re-open modal
await page.getByText('Close').click();
await page.getByTestId('Dropdown-New-Folder').click();
await page.getByRole('menuitemradio', { name: 'Environment' }).click();

// Validate expected values persisted
const rawOverrides = page.getByTestId('CodeEditor').locator('.CodeMirror-line');
const actualRows = await rawOverrides.allInnerTexts();
expect(actualRows.length).toBeGreaterThan(0);

const actualJSON = JSON.parse(actualRows.join(' '));
expect(actualJSON).toEqual(JSON.parse(expected));
});

test('Add new string variable to an existing environment overrides folder', async ({ page }) => {
// Open 'Test Folder' folder
await page.getByTestId('Dropdown-Test-Folder').click();
await page.getByRole('menuitemradio', { name: 'Environment' }).click();

// Add a new string environment variable to existing overrides

// 1. Retrieve current editor rows
let rawOverrides = page.getByTestId('CodeEditor').locator('.CodeMirror-line');
const rows = await rawOverrides.allInnerTexts();

// 2. Merge rows and convert to JSON
const editorJSON = JSON.parse(rows.join(' '));

// 3. Modify JSON with new string environment variable
editorJSON.REQUEST = 'HTTP';
const expected = editorJSON;

// 4. Apply new JSON to editor
const editor = await page.getByTestId('CodeEditor').getByRole('textbox');
const selectAllShortcut = process.platform === 'darwin' ? 'Meta+A' : 'Control+A';
await editor.press(selectAllShortcut);
await editor.fill(JSON.stringify(expected));

// Close and re-open Modal
await page.getByText('Close').click();
await page.getByTestId('Dropdown-Test-Folder').click();
await page.getByRole('menuitemradio', { name: 'Environment' }).click();

// Validate expected values persisted
rawOverrides = page.getByTestId('CodeEditor').locator('.CodeMirror-line');
const actualRows = await rawOverrides.allInnerTexts();
expect(actualRows.length).toBeGreaterThan(0);

const actualJSON = JSON.parse(actualRows.join(' '));
expect(actualJSON).toEqual(expected);

});

test('Update existing variable in environment override', async ({ page }) => {
// Open 'Test Folder' folder
await page.getByTestId('Dropdown-Test-Folder').click();
await page.getByRole('menuitemradio', { name: 'Environment' }).click();

// Update 'insomnia' string environment variable

// 1. Retrieve current editor rows
let rawOverrides = page.getByTestId('CodeEditor').locator('.CodeMirror-line');
const rows = await rawOverrides.allInnerTexts();

// 2. Merge rows and convert to JSON
const editorJSON = JSON.parse(rows.join(' '));

// 3. Modify JSON with updated string environment variable
editorJSON.insomnia = 'RestClient';
const expected = editorJSON;

// 4. Apply new JSON to editor
const editor = await page.getByTestId('CodeEditor').getByRole('textbox');
const selectAllShortcut = process.platform === 'darwin' ? 'Meta+A' : 'Control+A';
await editor.press(selectAllShortcut);
await editor.fill(JSON.stringify(expected));

// Close and re-open Modal
await page.getByText('Close').click();
await page.getByTestId('Dropdown-Test-Folder').click();
await page.getByRole('menuitemradio', { name: 'Environment' }).click();

// Validate expected values persisted
rawOverrides = page.getByTestId('CodeEditor').locator('.CodeMirror-line');
const actualRows = await rawOverrides.allInnerTexts();
expect(actualRows.length).toBeGreaterThan(0);

const actualJSON = JSON.parse(actualRows.join(' '));
expect(actualJSON).toEqual(expected);
});
});

0 comments on commit b03d873

Please sign in to comment.