Skip to content
Snippets Groups Projects
Verified Commit 8d9b55fd authored by Phil Hughes's avatar Phil Hughes
Browse files

Added frontend for project comment templates

parent 668a3b66
No related branches found
No related tags found
1 merge request!148424Added frontend for project comment templates
......@@ -24,10 +24,13 @@ export default {
},
variables() {
const groupPath = document.body.dataset.groupFullPath;
const projectPath = document.body.dataset.projectFullPath;
return {
groupPath,
hideGroup: !groupPath,
projectPath,
hideProject: !projectPath,
};
},
skip() {
......
......@@ -145,6 +145,7 @@ def project_data
{
project_id: @project.id,
project: @project.path,
project_full_path: @project.full_path,
group: @project.group&.path,
group_full_path: @project.group&.full_path,
namespace_id: @project.namespace&.id
......
......@@ -10,5 +10,9 @@ export {
TRACKING_SAVED_REPLIES_USE_IN_OTHER,
} from '~/vue_shared/components/markdown/constants';
export const COMMENT_TEMPLATES_KEYS = [...COMMENT_TEMPLATES_KEYS_FOSS, 'group'];
export const COMMENT_TEMPLATES_TITLES = { ...COMMENT_TEMPLATES_TITLES_FOSS, group: __('Group') };
export const COMMENT_TEMPLATES_KEYS = [...COMMENT_TEMPLATES_KEYS_FOSS, 'project', 'group'];
export const COMMENT_TEMPLATES_TITLES = {
...COMMENT_TEMPLATES_TITLES_FOSS,
project: __('Project'),
group: __('Group'),
};
query getSavedRepliesEE($groupPath: ID = null, $hideGroup: Boolean = true) {
query getSavedRepliesEE(
$groupPath: ID = null
$hideGroup: Boolean = true
$projectPath: ID = null
$hideProject: Boolean = true
) {
group(fullPath: $groupPath) @skip(if: $hideGroup) {
id
savedReplies(includeAncestorGroups: true) {
......@@ -9,6 +14,16 @@ query getSavedRepliesEE($groupPath: ID = null, $hideGroup: Boolean = true) {
}
}
}
project(fullPath: $projectPath) @skip(if: $hideProject) {
id
savedReplies {
nodes {
id
name
content
}
}
}
currentUser {
id
savedReplies {
......
......@@ -26,6 +26,20 @@ function createResponse() {
},
__typename: 'Group',
},
project: {
id: 'gid://gitlab/Project/2',
savedReplies: {
nodes: [
{
id: 'gid://gitlab/Projects::SavedReply/1',
name: 'project saved reply',
content: 'Project saved reply content',
__typename: 'ProjectsSavedReply',
},
],
},
__typename: 'Project',
},
currentUser: {
id: 'gid://gitlab/User/2',
savedReplies: {
......@@ -61,13 +75,18 @@ function createComponent(options = {}) {
return mountExtended(CommentTemplatesDropdown, {
propsData: {
newCommentTemplatePath: '/new',
newCommentTemplatePaths: [{ path: '/new', text: 'New' }],
},
apolloProvider: mockApollo,
});
}
describe('EE comment templates dropdown', () => {
afterEach(() => {
delete document.body.dataset.groupFullPath;
delete document.body.dataset.projectFullPath;
});
it('renders group and user comment templates', async () => {
const mockApollo = createMockApolloProvider();
wrapper = createComponent({ mockApollo });
......@@ -84,4 +103,25 @@ describe('EE comment templates dropdown', () => {
expect(items.at(2).text()).toBe('Group');
expect(items.at(3).text()).toContain('group saved reply');
});
it('renders project, group and user comment templates', async () => {
document.body.dataset.projectFullPath = 'gitlab-org';
const mockApollo = createMockApolloProvider();
wrapper = createComponent({ mockApollo });
wrapper.find('.js-comment-template-toggle').trigger('click');
await waitForPromises();
const items = wrapper.findAll('li');
expect(items).toHaveLength(6);
expect(items.at(0).text()).toBe('User');
expect(items.at(1).text()).toContain('saved_reply_1');
expect(items.at(2).text()).toBe('Project');
expect(items.at(3).text()).toContain('project saved reply');
expect(items.at(4).text()).toBe('Group');
expect(items.at(5).text()).toContain('group saved reply');
});
});
......@@ -559,6 +559,7 @@ def element(**arguments)
group_full_path: nil,
project_id: project.id,
project: project.path,
project_full_path: project.full_path,
namespace_id: project.namespace.id
}
)
......@@ -578,6 +579,7 @@ def element(**arguments)
group_full_path: project.group.full_path,
project_id: project.id,
project: project.path,
project_full_path: project.full_path,
namespace_id: project.namespace.id
}
)
......@@ -605,6 +607,7 @@ def element(**arguments)
group_full_path: nil,
project_id: issue.project.id,
project: issue.project.path,
project_full_path: project.full_path,
namespace_id: issue.project.namespace.id
}
)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment