Skip to content

Commit

Permalink
Pass component props to option processors (#7650)
Browse files Browse the repository at this point in the history
  • Loading branch information
yogevbd authored and SudoPlz committed May 30, 2023
1 parent 71a2cc6 commit c8cfbf5
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 1 deletion.
40 changes: 40 additions & 0 deletions lib/src/commands/Commands.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -226,6 +226,46 @@ describe('Commands', () => {
`Navigation.mergeOptions was invoked on component with id: ${componentId} before it is mounted, this can cause UI issues and should be avoided.\n Use static options instead.`
);
});

it('processes mergeOptions', async () => {
const options = {
animations: {
dismissModal: {
enabled: false,
},
},
};

uut.mergeOptions('myUniqueId', options);
verify(
mockedOptionsProcessor.processOptions(
CommandName.MergeOptions,
deepEqual(options),
undefined
)
).called();
});

it('processing mergeOptions should pass component props', async () => {
const options = {
animations: {
dismissModal: {
enabled: false,
},
},
};
const passProps = { prop: '1' };

when(mockedStore.getPropsForId('myUniqueId')).thenReturn(passProps);
uut.mergeOptions('myUniqueId', options);
verify(
mockedOptionsProcessor.processOptions(
CommandName.MergeOptions,
deepEqual(options),
passProps
)
).called();
});
});

describe('updateProps', () => {
Expand Down
3 changes: 2 additions & 1 deletion lib/src/commands/Commands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,9 +73,10 @@ export class Commands {

public mergeOptions(componentId: string, options: Options) {
const input = cloneDeep(options);
this.optionsProcessor.processOptions(CommandName.MergeOptions, input);

const component = this.store.getComponentInstance(componentId);
const componentProps = this.store.getPropsForId(componentId) || undefined;
this.optionsProcessor.processOptions(CommandName.MergeOptions, input, componentProps);
if (component && !component.isMounted)
console.warn(
`Navigation.mergeOptions was invoked on component with id: ${componentId} before it is mounted, this can cause UI issues and should be avoided.\n Use static options instead.`
Expand Down

0 comments on commit c8cfbf5

Please sign in to comment.