Fix rendering of method names
This fixes the rendering of method names when either the type or method name is empty. This can happen when the method is a not in a class or when the method is a synthetic method and the properties actually apply to the type.
This commit is contained in:
@@ -7,11 +7,27 @@ const Name = styled.span`
|
||||
word-break: break-all;
|
||||
`;
|
||||
|
||||
const TypeMethodName = (method: Method) => {
|
||||
if (!method.typeName) {
|
||||
return <>{method.methodName}</>;
|
||||
}
|
||||
|
||||
if (!method.methodName) {
|
||||
return <>{method.typeName}</>;
|
||||
}
|
||||
|
||||
return (
|
||||
<>
|
||||
{method.typeName}.{method.methodName}
|
||||
</>
|
||||
);
|
||||
};
|
||||
|
||||
export const MethodName = (method: Method): JSX.Element => {
|
||||
return (
|
||||
<Name>
|
||||
{method.packageName && <>{method.packageName}.</>}
|
||||
{method.typeName}.{method.methodName}
|
||||
<TypeMethodName {...method} />
|
||||
{method.methodParameters}
|
||||
</Name>
|
||||
);
|
||||
|
||||
@@ -24,4 +24,48 @@ describe(MethodName.name, () => {
|
||||
const name = `${method.typeName}.${method.methodName}${method.methodParameters}`;
|
||||
expect(screen.getByText(name)).toBeInTheDocument();
|
||||
});
|
||||
|
||||
it("renders method name without method name but with parameters", () => {
|
||||
const method = createMethod({
|
||||
packageName: "",
|
||||
methodName: "",
|
||||
});
|
||||
render(method);
|
||||
|
||||
const name = `${method.typeName}${method.methodParameters}`;
|
||||
expect(screen.getByText(name)).toBeInTheDocument();
|
||||
});
|
||||
|
||||
it("renders method name without method name and parameters", () => {
|
||||
const method = createMethod({
|
||||
packageName: "",
|
||||
methodName: "",
|
||||
methodParameters: "",
|
||||
});
|
||||
render(method);
|
||||
|
||||
const name = `${method.typeName}`;
|
||||
expect(screen.getByText(name)).toBeInTheDocument();
|
||||
});
|
||||
|
||||
it("renders method name without package and type name", () => {
|
||||
const method = createMethod({
|
||||
packageName: "",
|
||||
typeName: "",
|
||||
});
|
||||
render(method);
|
||||
|
||||
const name = `${method.methodName}${method.methodParameters}`;
|
||||
expect(screen.getByText(name)).toBeInTheDocument();
|
||||
});
|
||||
|
||||
it("renders method name without type name", () => {
|
||||
const method = createMethod({
|
||||
typeName: "",
|
||||
});
|
||||
render(method);
|
||||
|
||||
const name = `${method.packageName}.${method.methodName}${method.methodParameters}`;
|
||||
expect(screen.getByText(name)).toBeInTheDocument();
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user