Skip to content

Commit

Permalink
add partial in LunaticData
Browse files Browse the repository at this point in the history
fmt
  • Loading branch information
ddecrulle committed Mar 8, 2024
1 parent a4cc8dc commit 07767a0
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 15 deletions.
15 changes: 7 additions & 8 deletions src/use-lunatic/type.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,11 @@ export type LunaticControl = ControlType;

export type VTLBindings = { [variableName: string]: unknown };

export type LunaticData = Record<
Exclude<VariableType, 'COLLECTED'>,
Record<string, unknown>
> & {
COLLECTED: Record<string, LunaticCollectedValue>;
};
export type LunaticData = Partial<
Record<Exclude<VariableType, 'COLLECTED'>, Record<string, unknown>> & {
COLLECTED: Record<string, LunaticCollectedValue>;
}
>;

export type LunaticValues = {
[variableName: string]: unknown;
Expand All @@ -43,13 +42,13 @@ export type LunaticExpression = {
export type TODO = unknown; // Temporary type to mark types as unresolved

export type LunaticVariable = Variable;
export type LunaticCollectedValue = {
export type LunaticCollectedValue = Partial<{
COLLECTED: unknown;
EDITED: unknown;
FORCED: unknown;
INPUTED: unknown;
PREVIOUS: unknown;
};
}>;

export type LunaticOverviewItem = {
id: string;
Expand Down
14 changes: 7 additions & 7 deletions src/use-lunatic/use-lunatic.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -208,11 +208,11 @@ describe('use-lunatic()', () => {
);
result.current.onChange({ name: 'NB' }, 3);
expect(
(result.current.getData(true).COLLECTED.PRENOMS as any).COLLECTED
(result.current.getData(true).COLLECTED?.PRENOMS as any).COLLECTED
).toEqual([null, null, null]);
result.current.onChange({ name: 'NB' }, 2);
expect(
(result.current.getData(true).COLLECTED.PRENOMS as any).COLLECTED
(result.current.getData(true).COLLECTED?.PRENOMS as any).COLLECTED
).toEqual([null, null]);
});
});
Expand Down Expand Up @@ -241,13 +241,13 @@ describe('use-lunatic()', () => {
},
},
});
expect(Object.keys(data.COLLECTED)).toHaveLength(109);
expect(Object.keys(data.CALCULATED)).toHaveLength(0);
expect(data.COLLECTED && Object.keys(data.COLLECTED)).toHaveLength(109);
expect(data.CALCULATED && Object.keys(data?.CALCULATED)).toHaveLength(0);
});
it('should return calculated values', () => {
const data = hookRef.current.getData(true);
expect(Object.keys(data.COLLECTED)).toHaveLength(109);
expect(Object.keys(data.CALCULATED)).toHaveLength(33);
expect(data.COLLECTED && Object.keys(data.COLLECTED)).toHaveLength(109);
expect(data.CALCULATED && Object.keys(data?.CALCULATED)).toHaveLength(33);
});
it('should only return requested variables', () => {
const data = hookRef.current.getData(false, ['COMMENT']);
Expand All @@ -258,7 +258,7 @@ describe('use-lunatic()', () => {
},
},
});
expect(Object.keys(data.COLLECTED)).toHaveLength(1);
expect(data.COLLECTED && Object.keys(data.COLLECTED)).toHaveLength(1);
});
});

Expand Down

0 comments on commit 07767a0

Please sign in to comment.