Skip to content

Commit

Permalink
fix: data was binding to paths starting with same prefix
Browse files Browse the repository at this point in the history
  • Loading branch information
ATHULKNAIR committed May 17, 2023
1 parent 63a2910 commit b41a195
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 1 deletion.
3 changes: 2 additions & 1 deletion src/medblocks/form/plugins/openEHRFlat.ts
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,8 @@ export const openEHRFlatPlugin: MbPlugin = {
if (prefix && suffix) {
elementsWithBasePath = Object.keys(parsedData).filter(
path =>
path.startsWith(prefix as string) && path.endsWith(suffix as string)
path.split(':')[0] === (prefix as string) &&
path.endsWith(suffix as string)
);
} else {
elementsWithBasePath = Object.keys(parsedData).filter(path =>
Expand Down
18 changes: 18 additions & 0 deletions test/mb-form.e2e.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1248,4 +1248,22 @@ describe('Form e2e', () => {
let data = await oneEvent(form, 'mb-submit');
expect(data.detail).to.eql({ input2: 'hello there' });
});

// if prefix of path starts with same prefix of another path, then data should not be added to both
it('path starts with similar prefix, should not bind data for other elements', async () => {
const form = await fixture<MbForm>(html`
<mb-form>
<mb-search-multiple path="test/path:0/name" repeatprefix="test/path" repeatsuffix="name" label="Hello there"></base-ehr>
<mb-search-multiple path="test/path1:0/name" repeatprefix="test/path1" repeatsuffix="name" label="Hello there"></base-ehr>
</mb-form>
`);
form.import({ 'test/path1:0/name': 'test value1' });
await elementUpdated(form);

expect(form.data).to.eql({
'test/path:0/name': [],
'test/path1:0/name': ['test value1'],
});
expect(form.export()).to.eql({ 'test/path1:0/name': 'test value1' });
});
});

0 comments on commit b41a195

Please sign in to comment.