Skip to content

Commit

Permalink
fix(cypress) Fix flakiness of cypress test for glossary navigation (#…
Browse files Browse the repository at this point in the history
…9410)

Co-authored-by: david-leifker <[email protected]>
  • Loading branch information
chriscollins3456 and david-leifker authored Dec 8, 2023
1 parent 3e79a13 commit 159a013
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import analytics, { EventType } from '../../../analytics';
import { useGlossaryEntityData } from '../GlossaryEntityContext';
import { getParentNodeToUpdate, updateGlossarySidebar } from '../../../glossary/utils';
import { useHandleDeleteDomain } from './useHandleDeleteDomain';
import { removeTermFromGlossaryNode } from '../../../glossary/cacheUtils';

/**
* Performs the flow for deleting an entity of a given type.
Expand All @@ -30,6 +31,7 @@ function useDeleteEntity(

const maybeDeleteEntity = getDeleteEntityMutation(type)();
const deleteEntity = (maybeDeleteEntity && maybeDeleteEntity[0]) || undefined;
const client = maybeDeleteEntity?.[1].client;

function handleDeleteEntity() {
deleteEntity?.({
Expand All @@ -54,6 +56,10 @@ function useDeleteEntity(
handleDeleteDomain();
}

if (client && entityData.type === EntityType.GlossaryTerm && entityData?.parentNodes?.nodes) {
removeTermFromGlossaryNode(client, entityData.parentNodes.nodes[0].urn, urn);
}

setTimeout(
() => {
setHasBeenDeleted(true);
Expand Down
36 changes: 36 additions & 0 deletions datahub-web-react/src/app/glossary/cacheUtils.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import { ApolloClient } from '@apollo/client';
import { GetGlossaryNodeDocument, GetGlossaryNodeQuery } from '../../graphql/glossaryNode.generated';

export function removeTermFromGlossaryNode(
client: ApolloClient<object>,
glossaryNodeUrn: string,
glossaryTermUrn: string,
) {
// Read the data from our cache for this query.
const currData: GetGlossaryNodeQuery | null = client.readQuery({
query: GetGlossaryNodeDocument,
variables: { urn: glossaryNodeUrn },
});

// Remove the term from the existing children set.
const newTermChildren = {
relationships: [
...(currData?.glossaryNode?.children?.relationships || []).filter(
(relationship) => relationship.entity?.urn !== glossaryTermUrn,
),
],
total: (currData?.glossaryNode?.children?.total || 1) - 1,
};

// Write our data back to the cache.
client.writeQuery({
query: GetGlossaryNodeDocument,
variables: { urn: glossaryNodeUrn },
data: {
glossaryNode: {
...currData?.glossaryNode,
children: newTermChildren,
},
},
});
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
const glossaryTerm = "CypressGlosssaryNavigationTerm";
const glossaryTermGroup = "CypressGlosssaryNavigationGroup";
const glossaryParentGroup = "Cypress";
const glossaryParentGroup = "CypressNode";

describe("glossary sidebar navigation test", () => {
it("create term and term parent group, move and delete term group", () => {
Expand Down Expand Up @@ -33,6 +33,7 @@ describe("glossary sidebar navigation test", () => {
// Move a term group from the root level to be under a parent term group
cy.goToGlossaryList();
cy.clickOptionWithText(glossaryTermGroup);
cy.wait(3000)
cy.openThreeDotDropdown();
cy.clickOptionWithText("Move");
cy.get('[data-testid="move-glossary-entity-modal"]').contains(glossaryParentGroup).click({force: true});
Expand Down

0 comments on commit 159a013

Please sign in to comment.