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

'Codeless' UI test generation #884

Merged
merged 1 commit into from
Oct 1, 2024
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
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import asthmaGraphData from '../test-data/asthmaExampleGraphData.json';
// diagramCase: last copied from test_graph.py test_get_missing_in_between_nodes(): 2024/02/11
// edges only. see https://github.com/jhu-bids/TermHub/blob/develop/docs/graph.md
import _diagramCase from '../test-data/diagramCase.json';
import convertToArrayOfStrings from './utils';
let diagramCase = convertToArrayOfStrings(_diagramCase);


Expand All @@ -25,12 +26,12 @@ testCases = [singleSmallTestData, ];
let timeout = 20000;

for (const envName in selectedConfigs) {
const appUrl =
deploymentConfigs[envName] +
'/cset-comparison?' +
codeset_ids.map(d => `codeset_ids=${d}`).join('&');
for (const testData of testCases) {
const {test_name, codeset_ids, graphData, roots, leaves, firstRow, } = testData;
const appUrl =
deploymentConfigs[envName] +
'/cset-comparison?' +
codeset_ids.map(d => `codeset_ids=${d}`).join('&');

test.describe(`On ${envName} with case ${test_name}`, () => {
test.describe(`GraphOptions and GraphContainer Tests`, async () => {
Expand Down Expand Up @@ -117,10 +118,6 @@ for (const envName in selectedConfigs) {
const url = new URL(page.url());
return url.pathname === 'cset-comparison';
}).toBeTruthy();

/*

*/
});
});

Expand Down Expand Up @@ -197,17 +194,3 @@ for (const envName in selectedConfigs) {
*/
}
}

// UTILS
/* Used to convert input to be same as graphology serialization (all strings). */
function convertToArrayOfStrings(matrix) {
var stringMatrix = [];
for (var i = 0; i < matrix.length; i++) {
var stringRow = [];
for (var j = 0; j < matrix[i].length; j++) {
stringRow.push(matrix[i][j].toString());
}
stringMatrix.push(stringRow);
}
return stringMatrix;
}
42 changes: 42 additions & 0 deletions frontend/tests/playwright/n3c-recommended.todo.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
import {selectedConfigs, deploymentConfigs} from "./setup-test-environments";
// const { test, expect } = require('@playwright/test');
import {test, expect, } from '@playwright/test';

// Tests ---------------------------------------------------------------------------------------------------------------
let timeout = 20000;

// todo temp: toggle comment for development
// for (const envName of ['dev']) {
for (const envName in selectedConfigs) {

const appUrl = deploymentConfigs[envName];

test('N3C Recommended', async ({ page }) => {
await page.goto(appUrl);
await page.goto(appUrl + '/OMOPConceptSets');

await page.getByTestId('Help / About').click();
await page.getByRole('link', { name: 'N3C Recommended', exact: true }).click();
// TODO: make some assertions
});

test('N3C Recommended comparison', async ({ page }) => {
await page.goto(appUrl);
await page.goto(appUrl + '/OMOPConceptSets');

await page.getByTestId('Help / About').click();
await page.getByRole('link', { name: 'N3C Recommended comparison' }).click();
// todo: maybe try to dynamically select whatever row it is that has changes, rather than static case
await page.getByRole('row', { name: 'Expand Row CARDIOMYOPATHIES' }).getByTestId('expander-button-undefined').click();
// TODO: how to select the table dynamically? I want to assert that it shows rows are removed an added
// - but the selector id is really weird: <div class="sc-jXbUNg cyUjzM rdt_ExpanderRow">. has another <div>, then
// another <p>, then a <table id="n3ccompdiff">
// Ahhh! We need unique IDs. It should be something like "n3ccompdiff-removed-CARDIOMYOPATHIES" (or whatever the
// cset ID for that is).
// TODO: After solving the above, assert rows added/removed

// TODO: Next, find some way to dynamically select the hyperink in the rightmost column
// TODO: What do I expect to happen next? it says "downloading..."
await page.getByRole('link', { name: '12 removed , 12 added' }).click();
});
}
13 changes: 13 additions & 0 deletions frontend/tests/utils.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
// UTILS
/* Used to convert input to be same as graphology serialization (all strings). */
function convertToArrayOfStrings(matrix) {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Refactored this func into a tests/utils.js file

var stringMatrix = [];
for (var i = 0; i < matrix.length; i++) {
var stringRow = [];
for (var j = 0; j < matrix[i].length; j++) {
stringRow.push(matrix[i][j].toString());
}
stringMatrix.push(stringRow);
}
return stringMatrix;
}
14 changes: 14 additions & 0 deletions makefile
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,20 @@ test-frontend-e2e-dev:
test-frontend-e2e-prod:
(cd frontend; \
ENVIRONMENTS=prod ${TEST_FRONTEND_CMD})
## - codegen: "codeless" Playwright generation of UI tests by recording browser interaction
## You don't need to use 'local' necessarily if you want to write the tests for local. Any of these commands can work
## to write tests that are theoretically compatible in any environment (as long as the UI is the same). The only
## difference is that when the test code is written, the first line will hard-code the URL to that environment. So
## after recording, the code should be repuprosed in the style of frontend/tests/.
codegen-local:
Copy link
Member Author

@joeflack4 joeflack4 Sep 24, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

New "codeless test generation" commands

I added some documentation on how to use them and what they are in the makefile.

These are basically a wrapper for:
yarn playwright codegen URL

(cd frontend; \
yarn playwright codegen https://localhost:3000)
codegen-dev:
(cd frontend; \
yarn playwright codegen https://icy-ground-0416a040f.2.azurestaticapps.net)
codegen-prod:
(cd frontend; \
yarn playwright codegen https://purple-plant-0f4023d0f.2.azurestaticapps.net)

# QC
fetch-missing-csets:
Expand Down
Loading