mirror of
				https://github.com/scm-manager/scm-manager.git
				synced 2025-10-31 10:35:56 +01:00 
			
		
		
		
	added unit tests for ChangesetDiff url decision
This commit is contained in:
		| @@ -1,5 +1,5 @@ | ||||
| import React from "react"; | ||||
| import { Changeset, Link } from "@scm-manager/ui-types"; | ||||
| import { Changeset, Link, Collection } from "@scm-manager/ui-types"; | ||||
| import LoadingDiff from "../LoadingDiff"; | ||||
| import Notification from "../../Notification"; | ||||
| import { WithTranslation, withTranslation } from "react-i18next"; | ||||
| @@ -9,27 +9,27 @@ type Props = WithTranslation & { | ||||
|   defaultCollapse?: boolean; | ||||
| }; | ||||
|  | ||||
| export const isDiffSupported = (changeset: Collection) => { | ||||
|   return !!changeset._links.diff || !!changeset._links.diffParsed; | ||||
| }; | ||||
|  | ||||
| export const createUrl = (changeset: Collection) => { | ||||
|   if (changeset._links.diffParsed) { | ||||
|     return (changeset._links.diffParsed as Link).href; | ||||
|   } else if (changeset._links.diff) { | ||||
|     return (changeset._links.diff as Link).href + "?format=GIT"; | ||||
|   } | ||||
|   throw new Error("diff link is missing"); | ||||
| }; | ||||
|  | ||||
| class ChangesetDiff extends React.Component<Props> { | ||||
|   isDiffSupported(changeset: Changeset) { | ||||
|     return changeset._links.diff || !!changeset._links.diffParsed; | ||||
|   } | ||||
|  | ||||
|   createUrl(changeset: Changeset) { | ||||
|     if (changeset._links.diffParsed) { | ||||
|       return (changeset._links.diffParsed as Link).href; | ||||
|     } else if (changeset._links.diff) { | ||||
|       return (changeset._links.diff as Link).href + "?format=GIT"; | ||||
|     } | ||||
|     throw new Error("diff link is missing"); | ||||
|   } | ||||
|  | ||||
|   render() { | ||||
|     const { changeset, defaultCollapse, t } = this.props; | ||||
|     if (!this.isDiffSupported(changeset)) { | ||||
|     if (!isDiffSupported(changeset)) { | ||||
|       return <Notification type="danger">{t("changeset.diffNotSupported")}</Notification>; | ||||
|     } else { | ||||
|       const url = this.createUrl(changeset); | ||||
|       return <LoadingDiff url={url} defaultCollapse={defaultCollapse} sideBySide={false}/>; | ||||
|       const url = createUrl(changeset); | ||||
|       return <LoadingDiff url={url} defaultCollapse={defaultCollapse} sideBySide={false} />; | ||||
|     } | ||||
|   } | ||||
| } | ||||
|   | ||||
		Reference in New Issue
	
	Block a user