Skip to content

Commit

Permalink
Add comment and tests
Browse files Browse the repository at this point in the history
  • Loading branch information
poulch committed Jun 29, 2023
1 parent 18e0895 commit 9eddace
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 0 deletions.
54 changes: 54 additions & 0 deletions src/attributes/components/AttributeValueEditDialog/utils.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
import { AttributeValueEditDialogFormData } from "@dashboard/attributes/utils/data";

import { getAttributeValueFields } from "./utils";

describe("getAttributeValueFields", () => {
it("should return fileUrl and contentType if attributeValue has fileUrl", () => {
// Arrange
const attributeValue = {
fileUrl: "fileUrl",
contentType: "contentType",
value: "value",
} as AttributeValueEditDialogFormData;
const isSwatch = true;

// Act
const result = getAttributeValueFields(attributeValue, isSwatch);

// Assert
expect(result).toEqual({
fileUrl: "fileUrl",
contentType: "contentType",
});
});

it("should return value when attributeValue has value and is swatch type", () => {
// Arrange
const attributeValue = {
value: "value",
} as AttributeValueEditDialogFormData;
const isSwatch = true;

// Act
const result = getAttributeValueFields(attributeValue, isSwatch);

// Assert
expect(result).toEqual({
value: "value",
});
});

it("should return empty object when attributeValue has value but type is not swatch", () => {
// Arrange
const attributeValue = {
value: "value",
} as AttributeValueEditDialogFormData;
const isSwatch = false;

// Act
const result = getAttributeValueFields(attributeValue, isSwatch);

// Assert
expect(result).toEqual({});
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ export const getAttributeValueFields = (
};
}

// Value should be only use when input type is swatch
if (attributeValue?.value && isSwatch) {
return { value: attributeValue?.value ?? "" };
}
Expand Down

0 comments on commit 9eddace

Please sign in to comment.