-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: [TERR-313][TERR-325] Integration test harness (#26)
* feat/MAP-160 - initial commit for integration testing and auth for Grafana - plugin testing code TBD * feat/MAP-160 - updated Makefile with e2e targets - updated package.json with e2e targets - added setup and plugin dependencies for auto user sign in for e2e testing in playwright.config file - notes on test configuration and Yarn setup added to README - removed commented code - added e2e.config.json file - data-testids attributes added to initial set of e2e tests for targets of Grafana show/hide sliding switches for View Options - added plugin.spec.ts for e2e testing * feat/MAP-160 - refactored testid into constants module - updated references to import of testids in EditingInterface and MapCanvas components away from e2e.config to constants module - fixed use of controls vs control group click events in plugin.spec - updated dist modules * feat/MAP-160 - added makefile autogenerated e2e/grafana-docker JSON file to .gitignore - added docker-compose to Makefile test:e2e recipe and inpsection of instance info for tests - added CI=1 on the fly environment variables to e2e and e2e:ui scripts in package.json - added node-fetch depedency to package.json for fetching from Grafana API endpoints - refactored playwright config to use auth rather than setup as a dependency - updated yarn.lock file - updated auth.setup to by pass reset of default password step during testing - refactored getHostInfo function into its own script/module - additional parmeters as specified in e2e.config, to be removed - added getFolderDashboardTargets to support test fixture property setting to folderDashboardInit script - added getDashboard, getCurrentUser, createDashboard, and createFolder functions to Grafana API service module - added networkMapPanel.json as a base esnet-networkmap-panel - added in plugin-def module for defining PluginTest types and fixture default values - added getEditNetowrkMapPanelUrl function to plugin.spec script - removed commented code - added interfaces for Panel and Targets * feat/MAP-160 - removed unneeded console.log lines * feat/MAP-160 - removed unused variable - removed homepage and protocolHostPort props from e2e.config - refactored targetPanel to target first of type "esnet-networkmap-panel" in e2e.config - added orgId to fixtures initializations for test params and ITargets interface in getFolderDashboardTargets fn in folderDashboardInit module - set default value of orgId to -1 - added getHomepageUrl fn in plugin.spec * MAP-160 - removed cap on number of workers to 1 for e2e testing - removed jest.config - removed dependencies on jest in package.json - updated yarn.lock * MAP-160 - updated yarn.lock - removed jest.config from .npmignore - remove jest and ts-jest from dependencies in package.json - moved targetDashboardUid setting of 'pending' to before if statement - updated module.js and plugin.json * MAP-160 - removed .yarnrc and .yarnrc.yml (reverting back to 1.22.21) - removed unneded package-lock.json (seems to have come from .npm) - pinned ver of @swc/core to 1.3.75 for compatibility with Node >= 20 - bumped engines requirement for node >=20 and yarn >= 1.22.21 and added preinstall script hook for enforcing use - updated yarn.lock - removed yarn setup section in README.md (caused too many issues and belongs more in docs/development.md) - updated yarn.lock * MAP-160 - added dependencies for eslint-plugin-react and eslint-plugin-jsdoc to meet minimum requirement for dev mode - updated yarn.lock file - readded most generated dist files - converted functions in module.ts to use arrow notation - fixed imports using local files with dot slash prefix in MapPanel.tsx * MAP-160 - updates related to resolving _this is not defined * MAP-160 - rolled back version of @playwright/test to 1.34.3 (and included in dev dependencies) - updated node dependency to work with node 18 - updated lock file - added missing step WRT to install playwright browsers - updated config.info module in ./e2e to build basicAuthHeader using Buffer.from and Buffer.toString instead of old btoa method - added binding of EsMap.update method via this.update.bind(this). - aligned and pinned packages from @grafana to agree with versions as specified in Grafana 8.3.0 * MAP-160 - updated lock file - updated @grafana/eslint-config version to pinned 7.0.0 in package.json - removed node-fetch related packages from package.json (relying on node v18, aka lts/hydrogen built ins) * MAP-160 - changed required yarn version to 1.22.0 or greater * MAP-160 - removed skipped tests relating to dashboard navigation (not directly within scope of plugin testing) * MAP-160 - removed commented code - updated config.info.ts in e2e testing to use port in first available entry under portKeys in generated docker JSON output * MAP-160 - fixed bad version references to Node 18 and Yarn in development.md * MAP-160 - moved documentation on testing out of README.md into development.md * MAP-160 - updated dist copy of the README.md file to reflect that in the project root All notes here correspond to the original ticket [MAP-160] as well as consequent tickets [TERR-313] and [TERR-325]
- Loading branch information
1 parent
bf9406e
commit 5d7c0b5
Showing
33 changed files
with
2,347 additions
and
2,007 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
export default testIds; | ||
declare namespace testIds { | ||
const sidebar: string; | ||
const map: string; | ||
const zoomInBtn: string; | ||
const zoomOutBtn: string; | ||
const addEdgeBtn: string; | ||
const addNodeBtn: string; | ||
const editEdgeToggleBtn: string; | ||
const editNodeToggleBtn: string; | ||
} | ||
//# sourceMappingURL=constants.d.ts.map |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
import { expect, Page } from '@playwright/test'; | ||
import { pluginTest as setup } from './plugin-def'; | ||
import credentials from '../playwright/.auth/credentials.json'; | ||
import { getHostInfo } from './config.info'; | ||
|
||
const authFile = 'playwright/.auth/user.json'; | ||
|
||
setup('authenticate', async ({ page }: { page: Page }) => { | ||
const { protocolHostPort } = getHostInfo(credentials); | ||
// Perform authentication steps. Replace these actions with your own. | ||
await page.goto(`${protocolHostPort}/login`); | ||
await page.getByLabel('Username input field').fill(credentials.username); | ||
await page.getByLabel('Password input field').fill(credentials.password); | ||
await page.getByLabel('Login button').click(); | ||
|
||
const skipBtn = await page.getByLabel('Skip'); | ||
if (!!skipBtn) { | ||
await skipBtn.click(); | ||
} | ||
|
||
// Wait until the page receives the cookies. | ||
// | ||
// Sometimes login flow sets cookies in the process of several redirects. | ||
// Wait for the final URL to ensure that the cookies are actually set. | ||
// Alternatively, you can wait until the page reaches a state where all cookies are set. | ||
await page.waitForURL("**/?orgId=1"); | ||
await expect(page.getByTestId('sidemenu')).toBeVisible(); | ||
// End of authentication steps. | ||
|
||
await page.context().storageState({ path: authFile }); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
import dockerInfo from '../e2e/grafana-docker.json'; | ||
import e2eConfig from '../e2e/e2e.config.json'; | ||
|
||
const moduleName = 'config.info'; | ||
const targetGrafanaInstanceName = e2eConfig.grafanaInstanceName || "grafana"; | ||
const grafanaInfo = (dockerInfo as Array<any>).find(nfo => nfo.Name == `/${targetGrafanaInstanceName}`); | ||
if (!grafanaInfo) { | ||
const configInstr = 'Configure one in e2e.config.json under the key "grafanaInstanceName" or use "grafana" as the name'; | ||
const err = `${moduleName}: No Docker instance named "${targetGrafanaInstanceName}" could be found. ${configInstr}`; | ||
throw new Error(err); | ||
} | ||
const { IPAddress, Ports } = grafanaInfo?.NetworkSettings; | ||
|
||
/** | ||
* Fetches the basic auth header and URL to the configured Grafana server. | ||
* | ||
* @param {{username: string, password: string}} credentials | ||
* @returns {{ protocolHostPort: string, basicAuthHeader: {[headerName: string]: string}}} | ||
*/ | ||
export const getHostInfo = (credentials: {username: string, password: string}) => { | ||
const fnName = 'auth.setup.getHostInfo'; | ||
let protocolHostPort; | ||
const portKeys = Object.keys(Ports); | ||
|
||
if (portKeys.length > 0) { | ||
const portInfo = Ports[portKeys[0]] as { | ||
HostIp: string; | ||
HostPort: string; | ||
}[]; | ||
if (portInfo.length > 0) { | ||
protocolHostPort = `http://${IPAddress || 'localhost'}:${portInfo[0].HostPort}`; | ||
const credentialsBuf = Buffer.from(`${credentials.username}:${credentials.password}`, 'base64'); | ||
const basicAuthHeader = { | ||
"Authorization": `Basic ${credentialsBuf.toString('base64')}` | ||
}; | ||
const result = { protocolHostPort, basicAuthHeader}; | ||
return result; | ||
} else { | ||
throw new Error(`${fnName}: cannot derive port number from Docker NetworkSettings.Ports inspection:\n${JSON.stringify(Ports)}`) | ||
} | ||
} else { | ||
throw new Error(`${fnName}: cannot derive port number from Docker NetworkSettings.Ports inspection:\n${JSON.stringify(Ports)}`) | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
{ | ||
"targetPanelType": "esnet-networkmap-panel", | ||
"targetDashboard": "network-map-test-dashboard", | ||
"targetFolder": "network-map-test-folder", | ||
"grafanaInstanceName": "esnet-networkmap-panel" | ||
} |
Oops, something went wrong.