Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Pass component props to option processors #7650

Merged
merged 2 commits into from
Dec 6, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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