-
Notifications
You must be signed in to change notification settings - Fork 135
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
ROX-113658: Add first basic e2e tests for PF Network Graph (#5264)
- Loading branch information
Showing
6 changed files
with
188 additions
and
3 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,108 @@ | ||
import * as api from '../constants/apiEndpoints'; | ||
import { selectors as networkGraphSelectors } from '../constants/NetworkPage'; | ||
import { interactAndWaitForResponses } from './request'; | ||
import { visit } from './visit'; | ||
import selectSelectors from '../selectors/select'; | ||
import navSelectors from '../selectors/navigation'; | ||
import { visitMainDashboard } from './main'; | ||
|
||
const networkGraphClusterAlias = 'networkgraph/cluster/id'; | ||
const networkPoliciesClusterAlias = 'networkpolicies/cluster/id'; | ||
|
||
const routeMatcherMapForClusterInNetworkGraph = { | ||
[networkGraphClusterAlias]: { | ||
method: 'GET', | ||
url: api.network.networkGraph, | ||
}, | ||
[networkPoliciesClusterAlias]: { | ||
method: 'GET', | ||
url: api.network.networkPoliciesGraph, | ||
}, | ||
}; | ||
|
||
export function selectCluster() { | ||
// TODO: update this test to use the new low-permission Clusters-Namespace endpoint after that is merged | ||
// https://github.com/stackrox/stackrox/pull/4951 | ||
cy.intercept('POST', api.graphql('getClusterNamespaces')).as('getClusterNamespaces'); | ||
|
||
interactAndWaitForResponses( | ||
() => { | ||
cy.get(networkGraphSelectors.selector.clusterSelect).click(); | ||
cy.get(`${selectSelectors.patternFlySelect.openMenu} span:first`).click(); | ||
}, | ||
{ | ||
getClusterNamespaces: { | ||
method: 'POST', | ||
url: api.graphql('getClusterNamespaces'), | ||
}, | ||
} | ||
); | ||
} | ||
|
||
// Additional calls in a test can select additional namespaces. | ||
|
||
export function selectNamespace(namespace) { | ||
interactAndWaitForResponses(() => { | ||
cy.get(networkGraphSelectors.selector.namespaceSelect).click(); | ||
// Exact match to distinguish stackrox from stackrox-operator namespaces. | ||
cy.get( | ||
`${selectSelectors.patternFlySelect.openMenu} .pf-c-select__menu-item [data-testid="namespace-name"]` | ||
) | ||
.contains(new RegExp(`^${namespace}$`)) | ||
.click(); | ||
cy.get(networkGraphSelectors.selector.namespaceSelect).click(); | ||
}, routeMatcherMapForClusterInNetworkGraph); | ||
} | ||
|
||
// visit helpers | ||
|
||
export const notifiersAlias = 'notifiers'; | ||
export const clustersAlias = 'clusters'; | ||
export const networkPoliciesGraphEpochAlias = 'networkpolicies/graph/epoch'; | ||
export const searchMetadataOptionsAlias = 'search/metadata/options'; | ||
|
||
const routeMatcherMapToVisitNetworkGraph = { | ||
// TODO: update this test to use the new low-permission Clusters endpoint after that is merged | ||
// https://github.com/stackrox/stackrox/pull/4951 | ||
[clustersAlias]: { | ||
method: 'GET', | ||
url: '/v1/clusters', | ||
}, | ||
[networkPoliciesGraphEpochAlias]: { | ||
method: 'GET', | ||
url: `${api.network.epoch}?clusterId=*`, // either id or null if no cluster selected | ||
}, | ||
}; | ||
|
||
export const basePath = '/main/network-graph'; | ||
|
||
// TODO: replace this custom implementation with the version from | ||
// import { visitFromLeftNav } from './nav'; | ||
// after the old network graph goes away in the left nav | ||
function visitFromLeftNav(itemText, routeMatcherMap, staticResponseMap) { | ||
visitMainDashboard(); | ||
|
||
interactAndWaitForResponses( | ||
() => { | ||
cy.get(`${navSelectors.navLinks}:contains("${itemText}")`).first().click(); | ||
}, | ||
routeMatcherMap, | ||
staticResponseMap | ||
); | ||
} | ||
|
||
export function visitNetworkGraphFromLeftNav() { | ||
visitFromLeftNav('Network Graph', routeMatcherMapToVisitNetworkGraph); | ||
|
||
cy.location('pathname').should('eq', basePath); | ||
} | ||
|
||
export function visitNetworkGraph(staticResponseMap) { | ||
visit(basePath, routeMatcherMapToVisitNetworkGraph, staticResponseMap); | ||
} | ||
|
||
export function checkNetworkGraphEmptyState() { | ||
cy.get( | ||
'.pf-c-empty-state__content:contains("Select a cluster and at least one namespace to render active deployment traffic on the graph")' | ||
); | ||
} |
59 changes: 59 additions & 0 deletions
59
ui/apps/platform/cypress/integration/networkGraphPF/networkGraphPF.test.js
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,59 @@ | ||
import navigationSelectors from '../../selectors/navigation'; | ||
|
||
import withAuth from '../../helpers/basicAuth'; | ||
import { | ||
visitNetworkGraph, | ||
visitNetworkGraphFromLeftNav, | ||
checkNetworkGraphEmptyState, | ||
selectCluster, | ||
selectNamespace, | ||
} from '../../helpers/networkGraphPF'; | ||
import { getRegExpForTitleWithBranding } from '../../helpers/title'; | ||
import { hasFeatureFlag } from '../../helpers/features'; | ||
|
||
describe('Network page', () => { | ||
before(function beforeHook() { | ||
if (!hasFeatureFlag('ROX_NETWORK_GRAPH_PATTERNFLY')) { | ||
this.skip(); | ||
} | ||
}); | ||
|
||
withAuth(); | ||
|
||
it('should visit using the left nav', () => { | ||
visitNetworkGraphFromLeftNav(); | ||
|
||
cy.get(`${navigationSelectors.navLinks}:contains('Network Graph')`) | ||
.first() | ||
.should('have.class', 'pf-m-current'); | ||
|
||
checkNetworkGraphEmptyState(); | ||
}); | ||
|
||
it('should visit from direct navigation', () => { | ||
visitNetworkGraph(); | ||
|
||
cy.title().should('match', getRegExpForTitleWithBranding('Network Graph')); | ||
|
||
checkNetworkGraphEmptyState(); | ||
}); | ||
|
||
it('should render a graph when cluster and namespace are selected', () => { | ||
visitNetworkGraph(); | ||
|
||
checkNetworkGraphEmptyState(); | ||
|
||
selectCluster(); | ||
selectNamespace('stackrox'); | ||
|
||
// check that group of nodes for NS is present | ||
cy.get( | ||
'.pf-ri__topology-demo .pf-topology-content [data-id="stackrox-active-graph"] [data-layer-id="groups"] [data-id="stackrox"]' | ||
); | ||
|
||
// check that label for NS is present | ||
cy.get( | ||
'.pf-ri__topology-demo .pf-topology-content [data-id="stackrox-active-graph"] [data-layer-id="default"] [data-id="stackrox"] text' | ||
).contains('stackro'); | ||
}); | ||
}); |
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