Commit 9f022f4a authored by peterhegman's avatar peterhegman

Apply frontend reviewer feedback

- Refactor `v-if` in Vue template
- Add `null` check to `pronouns` prop
- Add `trim` to `pronouns` prop check
parent 7513e38b
...@@ -30,7 +30,7 @@ export default { ...@@ -30,7 +30,7 @@ export default {
}, },
computed: { computed: {
hasPronouns() { hasPronouns() {
return this.pronouns !== ''; return this.pronouns !== null && this.pronouns.trim() !== '';
}, },
isBusy() { isBusy() {
return isUserBusy(this.availability); return isUserBusy(this.availability);
...@@ -40,25 +40,18 @@ export default { ...@@ -40,25 +40,18 @@ export default {
</script> </script>
<template> <template>
<span :class="containerClasses"> <span :class="containerClasses">
<gl-sprintf <gl-sprintf :message="s__('UserAvailability|%{author} %{spanStart}(Busy)%{spanEnd}')">
v-if="isBusy" <template #author
:message="s__('UserAvailability|%{author} %{spanStart}(Busy)%{spanEnd}')" >{{ name }}
>
<template #author>
{{ name }}
<span v-if="hasPronouns" class="gl-text-gray-500 gl-font-sm gl-font-weight-normal" <span v-if="hasPronouns" class="gl-text-gray-500 gl-font-sm gl-font-weight-normal"
>({{ pronouns }})</span >({{ pronouns }})</span
> ></template
</template> >
<template #span="{ content }"> <template #span="{ content }"
<span class="gl-text-gray-500 gl-font-sm gl-font-weight-normal">{{ content }}</span> ><span v-if="isBusy" class="gl-text-gray-500 gl-font-sm gl-font-weight-normal">{{
content
}}</span>
</template> </template>
</gl-sprintf> </gl-sprintf>
<template v-else>
{{ name }}
<span v-if="hasPronouns" class="gl-text-gray-500 gl-font-sm gl-font-weight-normal"
>({{ pronouns }})</span
>
</template>
</span> </span>
</template> </template>
...@@ -36,10 +36,10 @@ exports[`Event Item with action buttons renders the action buttons 1`] = ` ...@@ -36,10 +36,10 @@ exports[`Event Item with action buttons renders the action buttons 1`] = `
<span <span
class="note-header-author-name gl-font-weight-bold" class="note-header-author-name gl-font-weight-bold"
> >
Tanuki
Tanuki
<!----> <!---->
</span> </span>
</a> </a>
......
import { shallowMount } from '@vue/test-utils'; import { mount } from '@vue/test-utils';
import AssigneeAvatar from '~/sidebar/components/assignees/assignee_avatar.vue'; import AssigneeAvatar from '~/sidebar/components/assignees/assignee_avatar.vue';
import CollapsedAssignee from '~/sidebar/components/assignees/collapsed_assignee.vue'; import CollapsedAssignee from '~/sidebar/components/assignees/collapsed_assignee.vue';
import UserNameWithStatus from '~/sidebar/components/assignees/user_name_with_status.vue';
import userDataMock from '../../user_data_mock'; import userDataMock from '../../user_data_mock';
const TEST_USER = userDataMock(); const TEST_USER = userDataMock();
...@@ -17,11 +16,8 @@ describe('CollapsedAssignee assignee component', () => { ...@@ -17,11 +16,8 @@ describe('CollapsedAssignee assignee component', () => {
...props, ...props,
}; };
wrapper = shallowMount(CollapsedAssignee, { wrapper = mount(CollapsedAssignee, {
propsData, propsData,
stubs: {
UserNameWithStatus,
},
}); });
} }
......
...@@ -53,19 +53,23 @@ describe('UserNameWithStatus', () => { ...@@ -53,19 +53,23 @@ describe('UserNameWithStatus', () => {
}); });
it("renders user's name with pronouns", () => { it("renders user's name with pronouns", () => {
expect(wrapper.text()).toMatchInterpolatedText(`Administrator (${pronouns})`); expect(wrapper.text()).toMatchInterpolatedText(`${name} (${pronouns})`);
}); });
}); });
describe('when user does not have pronouns set', () => { describe('when user does not have pronouns set', () => {
it.each` describe.each`
pronouns pronouns
${undefined} ${undefined}
${null}
${''} ${''}
`("renders the user's name", ({ pronouns }) => { ${' '}
createComponent({ pronouns }); `('when `pronouns` prop is $pronouns', ({ pronouns }) => {
it("renders only the user's name", () => {
createComponent({ pronouns });
expect(wrapper.text()).toMatchInterpolatedText('Administrator'); expect(wrapper.text()).toMatchInterpolatedText(name);
});
}); });
}); });
}); });
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment