提交 139ff6b8 编写于 作者: T Tomas Vik

test(mr review): add integration tests for initializing MR discussions

上级 309b8e5e
......@@ -43,7 +43,7 @@ describe('MrItemModel', () => {
const [uri, range] = createCommentThreadMock.mock.calls[0];
expect(uri.path).toBe('src/webview/src/components/LabelNote.vue');
expect(range.start.x).toBe(47);
expect(commentThread.comments.length).toBe(2);
expect(commentThread.comments.length).toBe(1);
const firstComment = commentThread.comments[0];
expect(firstComment.author.name).toBe('Tomas Vik');
expect(firstComment.mode).toBe(vscode.CommentMode.Preview);
......
......@@ -132,11 +132,11 @@ const discussionOnDiff = {
hasNextPage: false,
endCursor: 'MQ',
},
nodes: [noteOnDiff, note2],
nodes: [noteOnDiff],
},
};
const projectWithDiscussions = {
const projectWithIssueDiscussions = {
project: {
id: 'gid://gitlab/Project/278964',
issue: {
......@@ -151,8 +151,24 @@ const projectWithDiscussions = {
},
};
const projectWithMrDiscussions = {
project: {
id: 'gid://gitlab/Project/278964',
mergeRequest: {
discussions: {
pageInfo: {
hasNextPage: false,
endCursor: 'Nw',
},
nodes: [systemNote, singleNote, discussionOnDiff],
},
},
},
};
module.exports = {
projectWithDiscussions,
projectWithIssueDiscussions,
projectWithMrDiscussions,
note1,
note1TextSnippet,
note2,
......
const assert = require('assert');
const sinon = require('sinon');
const vscode = require('vscode');
const { graphql } = require('msw');
const IssuableDataProvider = require('../../src/data_providers/issuable').DataProvider;
const { MrItemModel } = require('../../src/data_providers/items/mr_item_model');
const { tokenService } = require('../../src/services/token_service');
const openMergeRequestResponse = require('./fixtures/rest/open_mr.json');
const versionsResponse = require('./fixtures/rest/versions.json');
const versionResponse = require('./fixtures/rest/mr_version.json');
const { projectWithMrDiscussions, noteOnDiff } = require('./fixtures/graphql/discussions');
const {
getServer,
createJsonEndpoint,
......@@ -31,6 +36,11 @@ describe('MR Review', () => {
'?ref=1f0fa02de1f6b913d674a8be10899fb8540237a9': 'Old Version',
'?ref=b6d6f6fd17b52b8cf4e961218c572805e9aa7463': 'New Version',
}),
graphql.query('GetMrDiscussions', (req, res, ctx) => {
if (req.variables.projectPath === 'gitlab-org/gitlab' && req.variables.iid === '33824')
return res(ctx.data(projectWithMrDiscussions));
return res(ctx.data({ project: null }));
}),
]);
await tokenService.setToken(GITLAB_URL, 'abcd-secret');
});
......@@ -73,6 +83,41 @@ describe('MR Review', () => {
);
});
describe('discussions', () => {
const sandbox = sinon.createSandbox();
let thread;
let commentController;
beforeEach(() => {
thread = {};
/* We fake createCommentController implementation to check
that when we initialize an MR review, we create a correct comment controller
we save the created thread for later use in assertions */
commentController = {
createCommentThread: (uri, range, comments) => {
thread = { uri, range, comments };
return thread;
},
};
sandbox.stub(vscode.comments, 'createCommentController').returns(commentController);
});
afterEach(() => {
sandbox.restore();
});
it('loads MR discussions', async () => {
const mrItem = getTreeItem(mrItemModel);
assert.strictEqual(mrItem.label, '!33824 · Web IDE - remove unused actions (mappings)');
await dataProvider.getChildren(mrItemModel);
const { uri, range, comments } = thread;
assert.strictEqual(uri.path, `/${noteOnDiff.position.newPath}`);
assert.strictEqual(range.start.line, noteOnDiff.position.oldLine - 1);
assert.strictEqual(comments[0].body, noteOnDiff.body);
});
});
describe('clicking on a changed file', () => {
let mrFiles;
......
......@@ -6,7 +6,7 @@ const { graphql } = require('msw');
const webviewController = require('../../src/webview_controller');
const { tokenService } = require('../../src/services/token_service');
const openIssueResponse = require('./fixtures/rest/open_issue.json');
const { projectWithDiscussions } = require('./fixtures/graphql/discussions');
const { projectWithIssueDiscussions } = require('./fixtures/graphql/discussions');
const { getServer, createJsonEndpoint } = require('./test_infrastructure/mock_server');
const { GITLAB_URL } = require('./test_infrastructure/constants');
......@@ -29,7 +29,7 @@ describe('GitLab webview', () => {
server = getServer([
graphql.query('GetIssueDiscussions', (req, res, ctx) => {
if (req.variables.projectPath === 'gitlab-org/gitlab')
return res(ctx.data(projectWithDiscussions));
return res(ctx.data(projectWithIssueDiscussions));
return res(ctx.data({ project: null }));
}),
graphql.mutation('CreateNote', (req, res, ctx) => {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册