Merge pull request #2201 from performonkey/master
Fix patch doc add duplicate content type
This commit is contained in:
@ -47,5 +47,31 @@ describe("content-types-manager", () => {
|
||||
type: "element",
|
||||
});
|
||||
});
|
||||
|
||||
it("should not append duplicate content type", () => {
|
||||
const element = {
|
||||
type: "element",
|
||||
name: "xml",
|
||||
elements: [
|
||||
{
|
||||
type: "element",
|
||||
name: "Types",
|
||||
elements: [
|
||||
{
|
||||
type: "element",
|
||||
name: "Default",
|
||||
attributes: {
|
||||
ContentType: "image/png",
|
||||
Extension: "png",
|
||||
},
|
||||
},
|
||||
],
|
||||
},
|
||||
],
|
||||
};
|
||||
appendContentType(element, "image/png", "png");
|
||||
|
||||
expect(element.elements.length).toBe(1);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
@ -4,6 +4,18 @@ import { getFirstLevelElements } from "./util";
|
||||
|
||||
export const appendContentType = (element: Element, contentType: string, extension: string): void => {
|
||||
const relationshipElements = getFirstLevelElements(element, "Types");
|
||||
|
||||
const exist = relationshipElements.some(
|
||||
(el) =>
|
||||
el.type === "element" &&
|
||||
el.name === "Default" &&
|
||||
el?.attributes?.ContentType === contentType &&
|
||||
el?.attributes?.Extension === extension,
|
||||
);
|
||||
if (exist) {
|
||||
return;
|
||||
}
|
||||
|
||||
// eslint-disable-next-line functional/immutable-data
|
||||
relationshipElements.push({
|
||||
attributes: {
|
||||
|
Reference in New Issue
Block a user