Skip to content

Commit

Permalink
[Vue] Fix Sitecore querystring property in Link component (#974)
Browse files Browse the repository at this point in the history
* fixed link querystring issue

* added test for querystring attribute

* removed comments
  • Loading branch information
addy-pathania authored Apr 8, 2022
1 parent 682a9a1 commit 5cd1286
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 4 deletions.
10 changes: 7 additions & 3 deletions packages/sitecore-jss-vue/src/components/Link.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -91,13 +91,17 @@ describe('<Link />', () => {
class: 'my-link',
title: 'My Link',
target: '_blank',
querystring: 'foo=bar',
},
},
};
const rendered = mount(Link, { props }).find('a');
const renderedAttrs = rendered.attributes();
// note: order of comparison is important for `toMatchObject` as renderedAttrs won't fully match props.field.value
expect(props.field.value).toMatchObject(renderedAttrs);
expect(rendered.html()).toContain(
`href="${props.field.value.href}?${props.field.value.querystring}"`
);
expect(rendered.html()).toContain(`class="${props.field.value.class}"`);
expect(rendered.html()).toContain(`title="${props.field.value.title}"`);
expect(rendered.html()).toContain(`target="${props.field.value.target}"`);
});

it('should render other attributes with other props provided', () => {
Expand Down
3 changes: 2 additions & 1 deletion packages/sitecore-jss-vue/src/components/Link.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ export interface LinkFieldValue {
className?: string;
title?: string;
target?: string;
querystring?: string;
}

export interface LinkField {
Expand Down Expand Up @@ -105,7 +106,7 @@ export const Link = defineComponent({
...this.$data,
class: link.class,
...this.$attrs,
href: link.href,
href: link.querystring ? `${link.href}?${link.querystring}` : link.href,
title: link.title,
target: link.target,
};
Expand Down

0 comments on commit 5cd1286

Please sign in to comment.