Skip to content

Commit

Permalink
Fix flaky test for multi profiles and alerts for props (#3847)
Browse files Browse the repository at this point in the history
* add test id for close button

* close alert before moving on

* fix all alerts to use taost props

* update test to wait after each profile creation

* remove alert in console

* wait for interface to be ready

* correctly wait before query creation

* fix check after comment creation

* update verifiactions tests + increase timeout for proposed changes

* increase timeout for proposed change

* update objects in test to avoid concurrent testing on the same objects

* update locators for hover
  • Loading branch information
pa-lem authored Jul 17, 2024
1 parent 5f5e402 commit 7dd1773
Show file tree
Hide file tree
Showing 41 changed files with 94 additions and 107 deletions.
8 changes: 4 additions & 4 deletions frontend/app/src/Root.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,9 @@ export const Root = ({ children }: { children?: ReactNode }) => {
try {
return fetchUrl(CONFIG.CONFIG_URL);
} catch (err) {
toast(() => (
toast(
<Alert type={ALERT_TYPES.ERROR} message="Something went wrong when fetching the config" />
));
);
console.error("Error while fetching the config: ", err);
return undefined;
}
Expand All @@ -42,9 +42,9 @@ export const Root = ({ children }: { children?: ReactNode }) => {
return;
}

toast(() => (
toast(
<Alert type={ALERT_TYPES.ERROR} message="Something went wrong when fetching the config" />
));
);
console.error("Error while fetching the config: ", error);
}
};
Expand Down
2 changes: 1 addition & 1 deletion frontend/app/src/components/account-menu.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ export const AccountMenu = () => {
const profile = data?.AccountProfile;

if (error) {
toast(() => <Alert type={ALERT_TYPES.ERROR} message="Error while loading profile data" />, {
toast(<Alert type={ALERT_TYPES.ERROR} message="Error while loading profile data" />, {
toastId: customId,
});

Expand Down
2 changes: 1 addition & 1 deletion frontend/app/src/components/buttons/clipboard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ export const Clipboard = (props: tClipboard) => {

await navigator.clipboard.writeText(value);

toast(() => <Alert message={alert} type={ALERT_TYPES.INFO} />);
toast(<Alert message={alert} type={ALERT_TYPES.INFO} />);

setTimeout(() => {
setIsCopied(false);
Expand Down
2 changes: 1 addition & 1 deletion frontend/app/src/components/conversations/thread.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ export const Thread = (props: tThread) => {
setDisplayAddComment(false);
}

toast(() => <Alert type={ALERT_TYPES.SUCCESS} message={"Thread resolved"} />);
toast(<Alert type={ALERT_TYPES.SUCCESS} message={"Thread resolved"} />);
};

const comments = thread?.comments?.edges?.map((comment: any) => comment.node) ?? [];
Expand Down
2 changes: 1 addition & 1 deletion frontend/app/src/components/editor/code-editor.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ export const CodeEditor = (props: any) => {

await navigator.clipboard.writeText(value);

toast(() => <Alert message="Content copied" type={ALERT_TYPES.INFO} />);
toast(<Alert message="Content copied" type={ALERT_TYPES.INFO} />);

setTimeout(() => {
setIsCopied(false);
Expand Down
2 changes: 1 addition & 1 deletion frontend/app/src/components/file.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ export const File = (props: tFile) => {
setFileContent(fileResult);
} catch (err) {
console.error("err: ", err);
toast(() => <Alert type={ALERT_TYPES.ERROR} message="Error while loading file content" />);
toast(<Alert type={ALERT_TYPES.ERROR} message="Error while loading file content" />);
}

setIsLoading(false);
Expand Down
2 changes: 1 addition & 1 deletion frontend/app/src/components/form/object-form.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,7 @@ const NodeForm = ({
},
});

toast(() => <Alert type={ALERT_TYPES.SUCCESS} message={`${schema?.name} created`} />, {
toast(<Alert type={ALERT_TYPES.SUCCESS} message={`${schema?.name} created`} />, {
toastId: `alert-success-${schema?.name}-created`,
});

Expand Down
2 changes: 1 addition & 1 deletion frontend/app/src/components/list.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ const List = forwardRef<HTMLInputElement, OpsListProps>((props, ref) => {
sertInputValue("");

if (newArray.length === value.length) {
toast(() => <Alert message="Item already in the list" type={ALERT_TYPES.INFO} />);
toast(<Alert message="Item already in the list" type={ALERT_TYPES.INFO} />);
}
}
};
Expand Down
7 changes: 4 additions & 3 deletions frontend/app/src/components/ui/alert.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ type AlertProps = {
};

export const Alert = (props: AlertProps) => {
const { closeToast, message, details, onDismiss, type, ...otherProps } = props;
const { closeToast, message, details, onDismiss, type } = props;

const getIcon = () => {
switch (type) {
Expand Down Expand Up @@ -113,7 +113,7 @@ export const Alert = (props: AlertProps) => {
const alertDetails = <p className={classNames("text-sm", alertClasses.text)}>{details}</p>;

return (
<div className={classNames("rounded-m p-4", alertClasses.container)} {...otherProps}>
<div className={classNames("rounded-m p-4", alertClasses.container)}>
<div className="flex items-center">
<div className="flex-shrink-0 flex items-start">{getIcon()}</div>
<div className="ml-3">
Expand All @@ -127,7 +127,8 @@ export const Alert = (props: AlertProps) => {
"inline-flex rounded-md focus:outline-none focus:ring-2 focus:ring-offset-2",
alertClasses?.button
)}
onClick={handleDismiss}>
onClick={handleDismiss}
data-testid="close-alert">
<XMarkIcon className="w-4 h-4" aria-hidden="true" />
</button>
</div>
Expand Down
4 changes: 2 additions & 2 deletions frontend/app/src/decorators/withSchemaContext.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -98,9 +98,9 @@ export const withSchemaContext = (AppComponent: any) => (props: any) => {
setProfiles(profiles);
setState({ isReady: true });
} catch (error) {
toast(() => (
toast(
<Alert type={ALERT_TYPES.ERROR} message="Something went wrong when fetching the schema" />
));
);

console.error("Error while fetching the schema: ", error);
}
Expand Down
2 changes: 1 addition & 1 deletion frontend/app/src/graphql/graphqlClientApollo.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ export const errorLink = onError(({ graphQLErrors, operation, forward }) => {
}
default:
if (graphQLError.message) {
toast(() => <Alert type={ALERT_TYPES.ERROR} message={graphQLError.message} />, {
toast(<Alert type={ALERT_TYPES.ERROR} message={graphQLError.message} />, {
toastId: "alert-error",
});
}
Expand Down
2 changes: 1 addition & 1 deletion frontend/app/src/hooks/useAuth.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ export function AuthProvider({ children }: { children: ReactNode }) {
setIsLoading(false);

if (!result?.access_token) {
toast(() => <Alert type={ALERT_TYPES.ERROR} message="Invalid username and password" />, {
toast(<Alert type={ALERT_TYPES.ERROR} message="Invalid username and password" />, {
toastId: "alert-error-sign-in",
});

Expand Down
4 changes: 2 additions & 2 deletions frontend/app/src/screens/artifacts/generate.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,9 @@ export const Generate = (props: tGenerateProps) => {
});

if (artifactid) {
toast(() => <Alert message="Artifact re-generated" type={ALERT_TYPES.SUCCESS} />);
toast(<Alert message="Artifact re-generated" type={ALERT_TYPES.SUCCESS} />);
} else {
toast(() => <Alert message="Artifacts generated" type={ALERT_TYPES.SUCCESS} />);
toast(<Alert message="Artifacts generated" type={ALERT_TYPES.SUCCESS} />);
}

setIsLoading(false);
Expand Down
2 changes: 1 addition & 1 deletion frontend/app/src/screens/branches/branch-details.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ export const BranchDetails = () => {
console.log("error: ", error);
setDetailsContent(error);

toast(() => <Alert type={ALERT_TYPES.SUCCESS} message={errorMessage} />);
toast(<Alert type={ALERT_TYPES.SUCCESS} message={errorMessage} />);
}

setIsLoadingRequest(false);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ export const ArtifactContentDiff = (props: any) => {
setState(fileResult || "");
} catch (err) {
console.error("Error while loading files diff: ", err);
toast(() => <Alert type={ALERT_TYPES.ERROR} message="Error while loading files diff" />);
toast(<Alert type={ALERT_TYPES.ERROR} message="Error while loading files diff" />);
}

setIsLoading(false);
Expand Down Expand Up @@ -244,7 +244,7 @@ export const ArtifactContentDiff = (props: any) => {
},
});

toast(() => <Alert type={ALERT_TYPES.SUCCESS} message={"Comment added"} />);
toast(<Alert type={ALERT_TYPES.SUCCESS} message={"Comment added"} />);

if (refetch) {
refetch();
Expand Down Expand Up @@ -275,13 +275,13 @@ export const ArtifactContentDiff = (props: any) => {

console.error("An error occurred while creating the comment: ", error);

toast(() => (
toast(
<Alert
type={ALERT_TYPES.ERROR}
message={"An error occurred while creating the comment"}
details={error.message}
/>
));
);

setIsLoading(false);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ export const ArtifactsDiff = forwardRef((props, ref) => {
setArtifactsDiff(filesResult);
} catch (err) {
console.error("Error while loading artifacts diff: ", err);
toast(() => <Alert type={ALERT_TYPES.ERROR} message="Error while loading artifacts diff" />);
toast(<Alert type={ALERT_TYPES.ERROR} message="Error while loading artifacts diff" />);
}

setIsLoading(false);
Expand Down
2 changes: 1 addition & 1 deletion frontend/app/src/screens/diff/checks/checks-summary.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ export const ChecksSummary = (props: tChecksSummaryProps) => {
refetch();

if (result?.data?.CoreProposedChangeRunCheck?.ok) {
toast(() => <Alert type={ALERT_TYPES.SUCCESS} message="Checks are running" />);
toast(<Alert type={ALERT_TYPES.SUCCESS} message="Checks are running" />);
}
};

Expand Down
2 changes: 1 addition & 1 deletion frontend/app/src/screens/diff/checks/conflict.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ export const Conflict = (props: any) => {
},
});

toast(() => <Alert type={ALERT_TYPES.SUCCESS} message="Conflict marked as resovled" />);
toast(<Alert type={ALERT_TYPES.SUCCESS} message="Conflict marked as resovled" />);

setIsLoading(false);

Expand Down
2 changes: 1 addition & 1 deletion frontend/app/src/screens/diff/data-diff.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ export const DataDiff = forwardRef((props, ref) => {
} catch (err) {
console.error("Error when fethcing branches: ", err);

toast(() => <Alert type={ALERT_TYPES.ERROR} message="Error while loading branch diff" />);
toast(<Alert type={ALERT_TYPES.ERROR} message="Error while loading branch diff" />);
}

setIsLoading(false);
Expand Down
2 changes: 1 addition & 1 deletion frontend/app/src/screens/diff/diff-comments.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ export const DataDiffComments = (props: tDataDiffComments) => {
},
});

toast(() => <Alert type={ALERT_TYPES.SUCCESS} message={"Comment added"} />);
toast(<Alert type={ALERT_TYPES.SUCCESS} message={"Comment added"} />);

handleRefetch();
} catch (error: any) {
Expand Down
8 changes: 4 additions & 4 deletions frontend/app/src/screens/diff/file-diff/file-content-diff.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ export const FileContentDiff = (props: any) => {
setState(fileResult);
} catch (err) {
console.error("Error while loading files diff: ", err);
toast(() => <Alert type={ALERT_TYPES.ERROR} message="Error while loading files diff" />);
toast(<Alert type={ALERT_TYPES.ERROR} message="Error while loading files diff" />);
}

setIsLoading(false);
Expand Down Expand Up @@ -274,7 +274,7 @@ export const FileContentDiff = (props: any) => {
},
});

toast(() => <Alert type={ALERT_TYPES.SUCCESS} message={"Comment added"} />);
toast(<Alert type={ALERT_TYPES.SUCCESS} message={"Comment added"} />);

if (refetch) {
refetch();
Expand Down Expand Up @@ -305,13 +305,13 @@ export const FileContentDiff = (props: any) => {

console.error("An error occurred while creating the comment: ", error);

toast(() => (
toast(
<Alert
type={ALERT_TYPES.ERROR}
message={"An error occurred while creating the comment"}
details={error.message}
/>
));
);

setIsLoading(false);
}
Expand Down
2 changes: 1 addition & 1 deletion frontend/app/src/screens/diff/schema-diff.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ export const SchemaDiff = forwardRef((props, ref) => {
setDiff(diffDetails?.diffs ?? []);
} catch (err) {
console.error("Error when loading branch diff: ", err);
toast(() => <Alert type={ALERT_TYPES.ERROR} message="Error while loading branch diff" />);
toast(<Alert type={ALERT_TYPES.ERROR} message="Error while loading branch diff" />);
}

setIsLoading(false);
Expand Down
4 changes: 2 additions & 2 deletions frontend/app/src/screens/groups/add-group-form.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -35,12 +35,12 @@ export default function AddGroupForm({
try {
await addObjectToGroups({ variables: { objectId, relationshipIds: groupIds } });

toast(() => (
toast(
<Alert
type={ALERT_TYPES.SUCCESS}
message={`${pluralize(groupIds.length, "group")} added`}
/>
));
);

if (onUpdateCompleted) onUpdateCompleted();
} catch (e) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -127,12 +127,12 @@ const IpamIPAddressesList = forwardRef((props, ref) => {

setRelatedRowToDelete(undefined);

toast(() => (
toast(
<Alert
type={ALERT_TYPES.SUCCESS}
message={`Address ${relatedRowToDelete?.values?.address} deleted`}
/>
));
);
} catch (error) {
console.error("Error while deleting address: ", error);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -136,13 +136,13 @@ const IpamIPPrefixDetails = forwardRef((props, ref) => {

setRelatedRowToDelete(undefined);

toast(() => (
toast(
<Alert
type={ALERT_TYPES.SUCCESS}
data-testid="alert-prefix-deleted"
message={`Prefix ${relatedRowToDelete?.values?.prefix} deleted`}
/>
));
);
} catch (error) {
console.error("Error while deleting address: ", error);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -123,12 +123,12 @@ const IpamIPPrefixesSummaryList = forwardRef((props, ref) => {

setRelatedRowToDelete(undefined);

toast(() => (
toast(
<Alert
type={ALERT_TYPES.SUCCESS}
message={`Prefix ${relatedRowToDelete?.values?.prefix} deleted`}
/>
));
);
} catch (error) {
console.error("Error while deleting address: ", error);
}
Expand Down
2 changes: 1 addition & 1 deletion frontend/app/src/screens/layout/sidebar/desktop-menu.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ export function DesktopMenu({ className = "" }: MenuProps) {
setIsLoading(false);
} catch (error) {
console.error("error: ", error);
toast(() => <Alert type={ALERT_TYPES.ERROR} message="Error while fetching the menu" />);
toast(<Alert type={ALERT_TYPES.ERROR} message="Error while fetching the menu" />);
setIsLoading(false);
}
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -156,12 +156,12 @@ export default function RelationshipDetails(props: iRelationDetailsProps) {
refetch();
}

toast(() => (
toast(
<Alert
type={ALERT_TYPES.SUCCESS}
message={`Association with ${relationshipSchema.peer} removed`}
/>
));
);
};

const handleSubmit = async (data: any) => {
Expand All @@ -180,12 +180,12 @@ export default function RelationshipDetails(props: iRelationDetailsProps) {
refetch();
}

toast(() => (
toast(
<Alert
type={ALERT_TYPES.SUCCESS}
message={`Association with ${relationshipSchema.peer} added`}
/>
));
);

setShowAddDrawer(false);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ export const RelationshipsDetails = forwardRef((props: RelationshipsDetailsProps

updatePageData();

toast(() => <Alert type={ALERT_TYPES.SUCCESS} message={"Item removed from the group"} />);
toast(<Alert type={ALERT_TYPES.SUCCESS} message={"Item removed from the group"} />);
};

// const count = data[schemaData?.kind].count;
Expand Down
Loading

0 comments on commit 7dd1773

Please sign in to comment.