Skip to content

Commit

Permalink
Add test cases for static navbar and migrate links spec (#2481)
Browse files Browse the repository at this point in the history
* add test cases for static navbar + migrate links spec
  • Loading branch information
RFSH authored Jun 13, 2024
1 parent 245cb00 commit 1a0b20e
Show file tree
Hide file tree
Showing 41 changed files with 503 additions and 378 deletions.
6 changes: 3 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ E2EDrecord=test/e2e/specs/all-features-confirmation/record/presentation-btn.conf
E2EDrecordCopy=test/e2e/specs/all-features/record/copy-btn.config.ts
E2ErecordNoDeleteBtn=test/e2e/specs/delete-prohibited/record/no-delete-btn.config.ts
E2EDrecordRelatedTable=test/e2e/specs/all-features/record/related-table.config.ts
E2EDrecordLinks=test/e2e/specs/default-config/record/links.conf.js
E2EDrecordLinks=test/e2e/specs/default-config/record/links.config.ts
# Recordset tests
E2EDrecordset=test/e2e/specs/all-features-confirmation/recordset/presentation.conf.js
E2EDrecordsetEdit=test/e2e/specs/default-config/recordset/edit.conf.js
Expand Down Expand Up @@ -93,7 +93,7 @@ DefaultConfigParallel=test/e2e/specs/default-config/playwright.config.ts
Manualrecordset=test/manual/specs/recordset.conf.js

# protractor tests
RECORD_TESTS_PROTRACTOR=$(E2EDrecord) $(E2EDrecordLinks)
RECORD_TESTS_PROTRACTOR=$(E2EDrecord)
RECORDSET_TESTS_PROTRACTOR=$(E2EDrecordset) $(E2ErecordsetAdd) $(E2EDrecordsetEdit) $(E2EDrecordsetIndFacetProt)
RECORDADD_TESTS_PROTRACTOR=$(E2EDIrecordAdd) $(E2EDIrecordMultiFormInput) $(E2EDIrecordImmutable)
RECORDEDIT_TESTS_PROTRACTOR=$(E2EDIrecordEdit) $(E2EDIrecordMultiEdit) $(E2EDrecordEditSubmissionDisabled) $(E2EDIrecordEditMultiColTypes)
Expand All @@ -105,7 +105,7 @@ ALL_TESTS_PROTRACTOR=$(RECORD_TESTS_PROTRACTOR) $(RECORDSET_TESTS_PROTRACTOR) $(

# playwright tests
NAVBAR_TESTS=$(E2Enavbar) $(E2EnavbarHeadTitle) $(E2EnavbarCatalogConfig)
RECORD_TESTS=$(E2ErecordNoDeleteBtn) $(E2EDrecordRelatedTable) $(E2EDrecordCopy)
RECORD_TESTS=$(E2ErecordNoDeleteBtn) $(E2EDrecordRelatedTable) $(E2EDrecordCopy) $(E2EDrecordLinks)
RECORDSET_TESTS=$(E2ErecordsetSavedQuery) $(E2EDrecordsetIndFacet) $(E2EDrecordsetHistFacet)
RECORDADD_TESTS=$(E2EDIrecordMultiFormInput) $(E2ErecordEditForeignKeyDropdown) $(E2EDrecordEditCompositeKey)
RECORDEDIT_TESTS=$(E2ErecordEditInputIframe) $(E2EDrecordEditDomainFilter)
Expand Down
5 changes: 5 additions & 0 deletions docs/dev-docs/e2e-test-writing.md
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,11 @@ This section summarizes the best practices for writing test cases in Chaise.
});
});
```
- If your file has multiple independent `test`s that can run in parallel, you can ask playwright to run them in parallel by adding the following:
```ts
test.describe.configure({ mode: 'parallel' });
```
- Don't use this configuration if you have a `beforeAll` or `afterAll` that you want to run only once. Because in this case each worker will run their own `beforeAll` and `afterAll` instead of running it once (https://github.com/microsoft/playwright/issues/28201).
- If your tests must run in order and on the same browser, use the `test.step` method.
- Don't forget to include `await` before each `test.step`.
- Playwright will not run the remaining steps if any of the steps fail. To get around this, you should use `expect.soft`.
Expand Down
8 changes: 5 additions & 3 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
"ui"
],
"devDependencies": {
"@isrd-isi-edu/ermrest-data-utils": "0.0.5",
"@isrd-isi-edu/ermrest-data-utils": "^0.0.6",
"@playwright/test": "latest",
"@typescript-eslint/eslint-plugin": "~7.1.0",
"@typescript-eslint/parser": "~7.1.0",
Expand Down
2 changes: 1 addition & 1 deletion test/e2e/data_setup/schema/record/links.json
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@
"annotations": {
"tag:isrd.isi.edu,2016:visible-columns" : {
"detailed": [
"id", "text", "int", ["links", "fk_assoc_links"]
"id", "text", "int", ["links", "fk_inline_assoc_inline"]
]
}
}
Expand Down
11 changes: 10 additions & 1 deletion test/e2e/setup/playwright.model.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,11 @@
export type TestOptions = {
/**
* the name of the main spec folder.
* usages:
* - the catalog alias
* - finding the folder (for default chaise-config.js)
*/
mainSpecName: string,
/**
* the name of the spec (will be used for the report file)
*/
Expand All @@ -11,8 +18,10 @@ export type TestOptions = {
configFileName: string,
/**
* location of the chaise config file
* (if misisng, we're using mainSpecName to find the chaise-config file).
* /test/e2e/specs/<mainSpecName>/chaise-config.js
*/
chaiseConfigFilePath: string,
chaiseConfigFilePath?: string,

manualTestConfig?: boolean,

Expand Down
16 changes: 12 additions & 4 deletions test/e2e/setup/playwright.setup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,13 +68,19 @@ export default async function globalSetup(config: FullConfig) {

// create the catalog
try {
await createCatalog(testConfiguration, projectNames, options.manualTestConfig);
await createCatalog(testConfiguration, projectNames, options.mainSpecName, options.manualTestConfig);
} catch (exp) {
throw exp;
}

// take care of chaise-config
copyChaiseConfig(options.chaiseConfigFilePath);
let chaiseConfigFilePath = options.chaiseConfigFilePath;
// use the default
if (typeof chaiseConfigFilePath !== 'string') {
chaiseConfigFilePath = `test/e2e/specs/${options.mainSpecName}/chaise-config.js`;
}

copyChaiseConfig(chaiseConfigFilePath);

registerCallbacks(testConfiguration);
}
Expand Down Expand Up @@ -119,7 +125,7 @@ async function checkUserSessions(): Promise<{ session: any, authCookie: string }
/**
* create the catalog and data
*/
async function createCatalog(testConfiguration: any, projectNames: string[], isManual?: boolean) {
async function createCatalog(testConfiguration: any, projectNames: string[], mainSpecName: string, isManual?: boolean) {

return new Promise(async (resolve, reject) => {
testConfiguration.setup.url = process.env.ERMREST_URL;
Expand Down Expand Up @@ -174,7 +180,9 @@ async function createCatalog(testConfiguration: any, projectNames: string[], isM

for (const p of projectNames) {
try {
const res = await setupCatalog({ catalog, schemas });
// add alias to the catalog based on the config and project name
const alias = `${mainSpecName}-${p}`;
const res = await setupCatalog({ catalog: { ...catalog, alias }, schemas });
console.log(`catalog with id ${res.catalogId} created for project ${p}`);
setCatalogID(p, res.catalogId);

Expand Down
4 changes: 0 additions & 4 deletions test/e2e/specs/all-features-confirmation/chaise-config.js
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,3 @@ var chaiseConfig = {
]
}
};

if (typeof module === 'object' && module.exports && typeof require === 'function') {
exports.config = chaiseConfig;
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import getConfig from '@isrd-isi-edu/chaise/test/e2e/setup/playwright.configurat
export default getConfig({
testName: 'all-features-confirmation/errors',
configFileName: 'errors/dev.json',
chaiseConfigFilePath: 'test/e2e/specs/all-features-confirmation/chaise-config.js',
mainSpecName: 'all-features-confirmation',
testMatch: [
'errors.spec.ts'
]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@ import getConfig from '@isrd-isi-edu/chaise/test/e2e/setup/playwright.configurat
export default getConfig({
testName: 'all-features-confirmation/footer',
configFileName: 'footer/dev.json',
chaiseConfigFilePath: 'test/e2e/specs/all-features-confirmation/chaise-config.js',
mainSpecName: 'all-features-confirmation',
});
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@ import getConfig from '@isrd-isi-edu/chaise/test/e2e/setup/playwright.configurat
export default getConfig({
testName: 'all-features-confirmation/navbar',
configFileName: 'navbar/dev.json',
chaiseConfigFilePath: 'test/e2e/specs/all-features-confirmation/chaise-config.js',
mainSpecName: 'all-features-confirmation',
});
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@ import getConfig from '@isrd-isi-edu/chaise/test/e2e/setup/playwright.configurat
export default getConfig({
testName: 'all-features-confirmation',
configFileName: 'parallel-configs/all-features-confirmation.dev.json',
chaiseConfigFilePath: 'test/e2e/specs/all-features-confirmation/chaise-config.js',
mainSpecName: 'all-features-confirmation',
});
2 changes: 1 addition & 1 deletion test/e2e/specs/all-features/navbar/playwright.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@ import getConfig from '@isrd-isi-edu/chaise/test/e2e/setup/playwright.configurat
export default getConfig({
testName: 'all-features/navbar',
configFileName: 'navbar/dev.json',
chaiseConfigFilePath: 'test/e2e/specs/all-features/chaise-config.js',
mainSpecName: 'all-features',
});
2 changes: 1 addition & 1 deletion test/e2e/specs/all-features/permissions.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import getConfig from '@isrd-isi-edu/chaise/test/e2e/setup/playwright.configurat
export default getConfig({
testName: 'all-features/permissions',
configFileName: 'multi-permissions/dev.json',
chaiseConfigFilePath: 'test/e2e/specs/all-features/chaise-config.js',
mainSpecName: 'all-features',
testMatch: [
'acls/main.spec.ts',
'*/permissions-annotation.spec.ts'
Expand Down
2 changes: 1 addition & 1 deletion test/e2e/specs/all-features/playwright.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@ import getConfig from '@isrd-isi-edu/chaise/test/e2e/setup/playwright.configurat
export default getConfig({
testName: 'all-features',
configFileName: 'parallel-configs/all-features.dev.json',
chaiseConfigFilePath: 'test/e2e/specs/all-features/chaise-config.js',
mainSpecName: 'all-features',
runSequentially: true
});
2 changes: 1 addition & 1 deletion test/e2e/specs/all-features/record/copy-btn.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import getConfig from '@isrd-isi-edu/chaise/test/e2e/setup/playwright.configurat
export default getConfig({
testName: 'all-features/record/copy-btn',
configFileName: 'record/copy-btn.dev.json',
chaiseConfigFilePath: 'test/e2e/specs/all-features/chaise-config.js',
mainSpecName: 'all-features',
testMatch: [
'copy-btn.spec.ts'
]
Expand Down
2 changes: 1 addition & 1 deletion test/e2e/specs/all-features/record/related-table.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,5 @@ export default getConfig({
testName: 'all-features/record/related-table',
testMatch: 'related-table.spec.ts',
configFileName: 'record/related-table/dev.json',
chaiseConfigFilePath: 'test/e2e/specs/all-features/chaise-config.js',
mainSpecName: 'all-features',
});
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import getConfig from '@isrd-isi-edu/chaise/test/e2e/setup/playwright.configurat
export default getConfig({
testName: 'all-features/recordedit/input-iframe',
configFileName: 'recordedit/input-iframe.dev.json',
chaiseConfigFilePath: 'test/e2e/specs/all-features/chaise-config.js',
mainSpecName: 'all-features',
testMatch: [
'input-iframe.spec.ts'
]
Expand Down
22 changes: 2 additions & 20 deletions test/e2e/specs/all-features/recordedit/input-iframe.spec.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
import { test, expect, TestInfo } from '@playwright/test';
import { execSync } from 'child_process';
import { resolve } from 'path';

import RecordeditLocators, { RecordeditInputType } from '@isrd-isi-edu/chaise/test/e2e/locators/recordedit';
import ModalLocators from '@isrd-isi-edu/chaise/test/e2e/locators/modal';
import AlertLocators from '@isrd-isi-edu/chaise/test/e2e/locators/alert';

import { getCatalogID } from '@isrd-isi-edu/chaise/test/e2e/utils/catalog-utils';
import { copyFileToChaiseDir, getCatalogID } from '@isrd-isi-edu/chaise/test/e2e/utils/catalog-utils';
import { setInputValue, testRecordeditColumnNames, testSubmission } from '@isrd-isi-edu/chaise/test/e2e/utils/recordedit-utils';

const testParams = {
Expand Down Expand Up @@ -230,24 +229,7 @@ const getRecordeditURL = (baseURL: string | undefined, testInfo: TestInfo, filte
*/
const copyIframeToLocation = () => {
const iframeLocation = resolve(__dirname, './../../../utils/input-iframe-test.html');

const remoteChaiseDirPath = process.env.REMOTE_CHAISE_DIR_PATH;
// The tests will take this path when it is not running on CI and remoteChaseDirPath is not null
let cmd;
if (typeof remoteChaiseDirPath === 'string') {
cmd = `scp ${iframeLocation} ${remoteChaiseDirPath}/input-iframe-test.html`;
} else {
cmd = `sudo cp ${iframeLocation} /var/www/html/chaise/input-iframe-test.html`;
}

try {
execSync(cmd);
console.log('copied the iframe into proper location');
} catch (exp) {
console.log(exp);
console.log('Unable to copy the iframe into proper location');
process.exit(1);
}
copyFileToChaiseDir(iframeLocation, 'input-iframe-test.html');
}

const setIframeInputValues = async (iframeElementProps: any, values: any) => {
Expand Down
4 changes: 2 additions & 2 deletions test/e2e/specs/all-features/recordset/saved-query.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@ import getConfig from '@isrd-isi-edu/chaise/test/e2e/setup/playwright.configurat
export default getConfig({
testName: 'all-features/recordset/saved-query',
configFileName: 'recordset/saved-query.dev.json',
chaiseConfigFilePath: 'test/e2e/specs/all-features/chaise-config.js',
mainSpecName: 'all-features',
testMatch: [ 'saved-query.spec.ts' ]
});
});
4 changes: 0 additions & 4 deletions test/e2e/specs/default-config/chaise-config.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,3 @@ var chaiseConfig = {
logClientActions: false,
hideRecordeditLeaveAlert: true,
};

if (typeof module === 'object' && module.exports && typeof require === 'function') {
exports.config = chaiseConfig;
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,5 @@ export default getConfig({
'multi-form-input-edit.spec.ts'
],
configFileName: 'recordedit/multi-form-input.dev.json',
chaiseConfigFilePath: 'test/e2e/specs/default-config/chaise-config.js',
mainSpecName: 'default-config',
});
2 changes: 1 addition & 1 deletion test/e2e/specs/default-config/playwright.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@ import getConfig from '@isrd-isi-edu/chaise/test/e2e/setup/playwright.configurat
export default getConfig({
testName: 'default-config',
configFileName: 'parallel-configs/default-config.dev.json',
chaiseConfigFilePath: 'test/e2e/specs/default-config/chaise-config.js',
mainSpecName: 'default-config',
});
15 changes: 0 additions & 15 deletions test/e2e/specs/default-config/record/links.conf.js

This file was deleted.

10 changes: 10 additions & 0 deletions test/e2e/specs/default-config/record/links.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import getConfig from '@isrd-isi-edu/chaise/test/e2e/setup/playwright.configuration';

export default getConfig({
testName: 'default-config/record/links',
configFileName: 'record/links.dev.json',
mainSpecName: 'default-config',
testMatch: [
'links.spec.ts'
]
});
Loading

0 comments on commit 1a0b20e

Please sign in to comment.