Commit b43b0cdf authored by Kev's avatar Kev Committed by Stan Hu

Show status of snippet author in header

parent 1cc51c95
...@@ -200,6 +200,13 @@ export default { ...@@ -200,6 +200,13 @@ export default {
<gl-avatar :size="24" :src="snippet.author.avatarUrl" /> <gl-avatar :size="24" :src="snippet.author.avatarUrl" />
<span class="bold">{{ snippet.author.name }}</span> <span class="bold">{{ snippet.author.name }}</span>
</a> </a>
<gl-emoji
v-if="snippet.author.status"
v-gl-tooltip
class="gl-vertical-align-baseline font-size-inherit gl-mr-1"
:title="snippet.author.status.message"
:data-name="snippet.author.status.emoji"
/>
</template> </template>
</gl-sprintf> </gl-sprintf>
</div> </div>
......
...@@ -59,6 +59,11 @@ query GetSnippetQuery($ids: [SnippetID!]) { ...@@ -59,6 +59,11 @@ query GetSnippetQuery($ids: [SnippetID!]) {
name name
username username
webUrl webUrl
status {
__typename
emoji
message
}
} }
} }
} }
......
---
title: Show status of snippet author in header
merge_request: 51030
author: Kev @KevSlashNull
type: fixed
...@@ -17,6 +17,8 @@ describe('Snippet header component', () => { ...@@ -17,6 +17,8 @@ describe('Snippet header component', () => {
let err; let err;
const originalRelativeUrlRoot = gon.relative_url_root; const originalRelativeUrlRoot = gon.relative_url_root;
const GlEmoji = { template: '<img/>' };
function createComponent({ function createComponent({
loading = false, loading = false,
permissions = {}, permissions = {},
...@@ -47,10 +49,15 @@ describe('Snippet header component', () => { ...@@ -47,10 +49,15 @@ describe('Snippet header component', () => {
}, },
stubs: { stubs: {
ApolloMutation, ApolloMutation,
GlEmoji,
}, },
}); });
} }
const findAuthorEmoji = () => wrapper.find(GlEmoji);
const findAuthoredMessage = () => wrapper.find('[data-testid="authored-message"]').text();
const buttonCount = () => wrapper.findAll(GlButton).length;
beforeEach(() => { beforeEach(() => {
gon.relative_url_root = '/foo/'; gon.relative_url_root = '/foo/';
snippet = { snippet = {
...@@ -66,6 +73,7 @@ describe('Snippet header component', () => { ...@@ -66,6 +73,7 @@ describe('Snippet header component', () => {
project: null, project: null,
author: { author: {
name: 'Thor Odinson', name: 'Thor Odinson',
status: null,
}, },
blobs: [Blob], blobs: [Blob],
createdAt: new Date(differenceInMilliseconds(32 * 24 * 3600 * 1000)).toISOString(), createdAt: new Date(differenceInMilliseconds(32 * 24 * 3600 * 1000)).toISOString(),
...@@ -100,17 +108,36 @@ describe('Snippet header component', () => { ...@@ -100,17 +108,36 @@ describe('Snippet header component', () => {
it('renders a message showing snippet creation date and author', () => { it('renders a message showing snippet creation date and author', () => {
createComponent(); createComponent();
const text = wrapper.find('[data-testid="authored-message"]').text(); const text = findAuthoredMessage();
expect(text).toContain('Authored 1 month ago by'); expect(text).toContain('Authored 1 month ago by');
expect(text).toContain('Thor Odinson'); expect(text).toContain('Thor Odinson');
}); });
describe('author status', () => {
it('is rendered when it is set', () => {
snippet.author.status = {
message: 'At work',
emoji: 'hammer',
};
createComponent();
expect(findAuthorEmoji().attributes('title')).toBe(snippet.author.status.message);
expect(findAuthorEmoji().attributes('data-name')).toBe(snippet.author.status.emoji);
});
it('is not rendered when the user has no status', () => {
createComponent();
expect(findAuthorEmoji().exists()).toBe(false);
});
});
it('renders a message showing only snippet creation date if author is null', () => { it('renders a message showing only snippet creation date if author is null', () => {
snippet.author = null; snippet.author = null;
createComponent(); createComponent();
const text = wrapper.find('[data-testid="authored-message"]').text(); const text = findAuthoredMessage();
expect(text).toBe('Authored 1 month ago'); expect(text).toBe('Authored 1 month ago');
}); });
...@@ -121,7 +148,7 @@ describe('Snippet header component', () => { ...@@ -121,7 +148,7 @@ describe('Snippet header component', () => {
updateSnippet: false, updateSnippet: false,
}, },
}); });
expect(wrapper.findAll(GlButton).length).toEqual(0); expect(buttonCount()).toEqual(0);
createComponent({ createComponent({
permissions: { permissions: {
...@@ -129,7 +156,7 @@ describe('Snippet header component', () => { ...@@ -129,7 +156,7 @@ describe('Snippet header component', () => {
updateSnippet: false, updateSnippet: false,
}, },
}); });
expect(wrapper.findAll(GlButton).length).toEqual(1); expect(buttonCount()).toEqual(1);
createComponent({ createComponent({
permissions: { permissions: {
...@@ -137,7 +164,7 @@ describe('Snippet header component', () => { ...@@ -137,7 +164,7 @@ describe('Snippet header component', () => {
updateSnippet: true, updateSnippet: true,
}, },
}); });
expect(wrapper.findAll(GlButton).length).toEqual(2); expect(buttonCount()).toEqual(2);
createComponent({ createComponent({
permissions: { permissions: {
...@@ -149,7 +176,7 @@ describe('Snippet header component', () => { ...@@ -149,7 +176,7 @@ describe('Snippet header component', () => {
canCreateSnippet: true, canCreateSnippet: true,
}); });
return wrapper.vm.$nextTick().then(() => { return wrapper.vm.$nextTick().then(() => {
expect(wrapper.findAll(GlButton).length).toEqual(3); expect(buttonCount()).toEqual(3);
}); });
}); });
......
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