summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorkushalpandya <kushal@gitlab.com>2017-05-11 01:35:28 +0530
committerkushalpandya <kushal@gitlab.com>2017-05-11 01:35:28 +0530
commitbdfea467f3b9f56c9dd1336b14c21c697f03d49d (patch)
tree1ebab219ec338d035a005982237614fb786cd7ef
parentf660dacf8af9fcb6742418fd685f95e6fbf7cf30 (diff)
downloadgitlab-ce-32016-slash-command-strip-fix.tar.gz
Update tests for slash commands matching and stripping32016-slash-command-strip-fix
-rw-r--r--spec/javascripts/notes_spec.js25
1 files changed, 19 insertions, 6 deletions
diff --git a/spec/javascripts/notes_spec.js b/spec/javascripts/notes_spec.js
index cfd599f793e..be4605a5b89 100644
--- a/spec/javascripts/notes_spec.js
+++ b/spec/javascripts/notes_spec.js
@@ -376,13 +376,20 @@ import '~/notes';
this.notes = new Notes('', []);
});
- it('should return true when comment has slash commands', () => {
- const sampleComment = '/wip /milestone %1.0 /merge /unassign Merging this';
+ it('should return true when comment begins with a slash command', () => {
+ const sampleComment = '/wip \n/milestone %1.0 \n/merge \n/unassign Merging this';
const hasSlashCommands = this.notes.hasSlashCommands(sampleComment);
expect(hasSlashCommands).toBeTruthy();
});
+ it('should return false when comment does NOT begin with a slash command', () => {
+ const sampleComment = 'Hey, /unassign Merging this';
+ const hasSlashCommands = this.notes.hasSlashCommands(sampleComment);
+
+ expect(hasSlashCommands).toBeFalsy();
+ });
+
it('should return false when comment does NOT have any slash commands', () => {
const sampleComment = 'Looking good, Awesome!';
const hasSlashCommands = this.notes.hasSlashCommands(sampleComment);
@@ -392,14 +399,20 @@ import '~/notes';
});
describe('stripSlashCommands', () => {
- const REGEX_SLASH_COMMANDS = /\/\w+/g;
+ it('should strip slash commands from the comment which begins with a slash command', () => {
+ this.notes = new Notes();
+ const sampleComment = '/wip \n/milestone %1.0 \n/merge \n/unassign Merging this';
+ const stripedComment = this.notes.stripSlashCommands(sampleComment);
+
+ expect(stripedComment).not.toBe(sampleComment);
+ });
- it('should strip slash commands from the comment', () => {
+ it('should NOT strip string that has slashes within', () => {
this.notes = new Notes();
- const sampleComment = '/wip /milestone %1.0 /merge /unassign Merging this';
+ const sampleComment = 'http://127.0.0.1:3000/root/gitlab-shell/issues/1';
const stripedComment = this.notes.stripSlashCommands(sampleComment);
- expect(REGEX_SLASH_COMMANDS.test(stripedComment)).toBeFalsy();
+ expect(stripedComment).toBe(sampleComment);
});
});