Skip to content

Commit

Permalink
--wip-- [skip ci]
Browse files Browse the repository at this point in the history
  • Loading branch information
Mike-Heneghan committed Nov 20, 2023
1 parent 7cce5f9 commit b8b249e
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 2 deletions.
22 changes: 22 additions & 0 deletions editor.planx.uk/src/pages/FlowEditor/lib/__tests__/preview.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -577,6 +577,28 @@ describe("changeAnswer", () => {
expect(getState().breadcrumbs).not.toContain(originalAnswer);
expect(getState().cachedBreadcrumbs).toStrictEqual(originalAnswer);
});

test.only("should return only whitelist answers when the option is passed", () => {
const breadcrumbs = breadcrumbsDependentOnPassport;
const flow = { ...flowWithPassportComponents };

setState({
flow,
breadcrumbs,
cachedBreadcrumbs: {},
});
console.log('Here')
console.log('Full passport', computePassport())
console.log('Whitelist passport', computePassport({whiteList: true}))

// Assert our initial passport state is correct
expect(computePassport({whiteList: true})).toEqual({
data: {
"application.fee.exemption.disability": ["true"],
},
});

});
});

describe("resetPreview", () => {
Expand Down
21 changes: 19 additions & 2 deletions editor.planx.uk/src/pages/FlowEditor/lib/store/preview.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,15 @@ import type { SharedStore } from "./shared";
const SUPPORTED_DECISION_TYPES = [TYPES.Checklist, TYPES.Statement];
let memoizedPreviousCardId: string | undefined = undefined;
let memoizedBreadcrumb: Store.breadcrumbs | undefined = undefined;


// const WHITE_LIST_QUESTIONS = ["proposal.ProjectType"]
const WHITE_LIST_QUESTIONS = ["application.fee.exemption.disability"]

interface ComputePassportOptions {
whiteList?: boolean;
}

export interface PreviewStore extends Store.Store {
collectedFlags: (
upToNodeId: Store.nodeId,
Expand All @@ -43,7 +52,7 @@ export interface PreviewStore extends Store.Store {
upcomingCardIds?: Store.nodeId[],
) => Store.nodeId | undefined;
canGoBack: (node: Store.node | null) => boolean;
computePassport: () => Readonly<Store.passport>;
computePassport: (options?: ComputePassportOptions) => Readonly<Store.passport>;
record: (id: Store.nodeId, userData?: Store.userData) => void;
resultData: (
flagSet?: string,
Expand Down Expand Up @@ -196,7 +205,7 @@ export const previewStore: StateCreator<
);
},

computePassport: () => {
computePassport: (options?: ComputePassportOptions) => {
const { flow, breadcrumbs } = get();
const passport = Object.entries(breadcrumbs).reduce(
(acc, [id, { data = {}, answers = [] }]) => {
Expand Down Expand Up @@ -230,6 +239,14 @@ export const previewStore: StateCreator<
);

passportData[key] = uniq(combined);

// Check if key is in the white list, skip if not
console.log('Options', options)
console.log('Whitelist options', options?.whiteList)
console.log(WHITE_LIST_QUESTIONS)
if (options && options?.whiteList && !WHITE_LIST_QUESTIONS.includes(key)) {
return acc;
}
}
}

Expand Down

0 comments on commit b8b249e

Please sign in to comment.