Skip to content

Commit

Permalink
Created a common function to transform
Browse files Browse the repository at this point in the history
Signed-off-by: sudeep <[email protected]>
  • Loading branch information
sudeepkunhis committed Sep 27, 2022
1 parent a6d503a commit 662a71c
Showing 1 changed file with 28 additions and 22 deletions.
50 changes: 28 additions & 22 deletions src/utils/convertPipes/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ const createTransformation = (
],
});

const createCheckboxTransformation = ({ placeholder, transform }, extra) => ({
const createAlternateTransformation = ({ placeholder, transform }, extra) => ({
placeholder,
transforms: [
{
Expand Down Expand Up @@ -64,12 +64,17 @@ const createContext = (metadata = []) => ({
{ id: `3`, label: "!It's Q3?", type: "DateRange" },
{
id: `4`,
label: "#Q4Don'tDoIt",
label: "#Q4Don'tDoIt",
type: "Date",
properties: { format: "dd/mm/yyyy" },
},
{ id: `5`, label: "label of excellence", type: "Number" },
{ id: `6`, label: "BACWards 6q", type: "Unit", properties: { unit: "Kilometres" } },
{
id: `6`,
label: "BACWards 6q",
type: "Unit",
properties: { unit: "Kilometres" },
},
{
id: `7`,
label: "Q7 Checkbox Options?",
Expand All @@ -92,18 +97,12 @@ const createContext = (metadata = []) => ({
{
id: `8`,
type: "Radio",
label: "Q8 Radio Options",
options: [
{
id: `AppleId`,
label: "Apples",
},
{
id: `PearId`,
label: "Pears",
},
{
id: `OrangeId`,
label: "Oranges",
id: `FavouriteFruit`,
dynamicAnswer: true,
dynamicAnswerID: `7`,
},
],
},
Expand Down Expand Up @@ -186,7 +185,7 @@ describe("convertPipes", () => {
}),
createTransformation({
placeholder: "untitled_answer",
identifier: "answer2",
identifier: "answer2",
source: "answers",
argument: "number",
transform: "format_currency",
Expand Down Expand Up @@ -295,7 +294,7 @@ describe("convertPipes", () => {
expect(convertPipes(createContext())(html)).toEqual(
createWrapper(
"{Q7_Checkbox_Options}",
createCheckboxTransformation(
createAlternateTransformation(
{
placeholder: "Q7_Checkbox_Options",
transform: "concatenate_list",
Expand All @@ -312,16 +311,23 @@ describe("convertPipes", () => {
);
});

it("should pipe radio answers", () => {
it("should pipe dynamic radio answers", () => {
const html = createPipe({ id: "8" });
expect(convertPipes(createContext())(html)).toEqual(
createWrapper(
"{8}",
createPlaceholders({
placeholder: "8",
identifier: "answer8",
source: "answers",
})
"{Q8_Radio_Options}",
createAlternateTransformation(
{
placeholder: "Q8_Radio_Options",
transform: "first_non_empty_item",
},
{
items: [
{ source: "answers", identifier: "answer8" },
{ source: "answers", identifier: "answer7" },
],
}
)
)
);
});
Expand Down

0 comments on commit 662a71c

Please sign in to comment.