slash-command-parser.test.ts 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. import { InvalidGrowiCommandError } from '../models/errors';
  2. import { parseSlashCommand } from './slash-command-parser';
  3. describe('parseSlashCommand', () => {
  4. describe('without growiCommandType', () => {
  5. test('throws InvalidGrowiCommandError', () => {
  6. // setup
  7. const text = '';
  8. const slashCommand = { text };
  9. // when/then
  10. expect(() => {
  11. parseSlashCommand(slashCommand);
  12. }).toThrowError(InvalidGrowiCommandError);
  13. });
  14. });
  15. test('returns a GrowiCommand instance with empty growiCommandArgs', () => {
  16. // setup
  17. const text = 'search';
  18. const slashCommand = { text };
  19. // when
  20. const result = parseSlashCommand(slashCommand);
  21. // then
  22. expect(result.text).toBe(text);
  23. expect(result.growiCommandType).toBe('search');
  24. expect(result.growiCommandArgs).toStrictEqual([]);
  25. });
  26. test('returns a GrowiCommand instance with space growiCommandType', () => {
  27. // setup
  28. const text = ' search ';
  29. const slashCommand = { text };
  30. // when
  31. const result = parseSlashCommand(slashCommand);
  32. // then
  33. expect(result.text).toBe(text);
  34. expect(result.growiCommandType).toBe('search');
  35. expect(result.growiCommandArgs).toStrictEqual([]);
  36. });
  37. test('returns a GrowiCommand instance with space growiCommandArgs', () => {
  38. // setup
  39. const text = ' search hoge ';
  40. const slashCommand = { text };
  41. // when
  42. const result = parseSlashCommand(slashCommand);
  43. // then
  44. expect(result.text).toBe(text);
  45. expect(result.growiCommandType).toBe('search');
  46. expect(result.growiCommandArgs).toStrictEqual(['hoge']);
  47. });
  48. test('returns a GrowiCommand instance', () => {
  49. // setup
  50. const text = 'search keyword1 keyword2';
  51. const slashCommand = { text };
  52. // when
  53. const result = parseSlashCommand(slashCommand);
  54. // then
  55. expect(result.text).toBe(text);
  56. expect(result.growiCommandType).toBe('search');
  57. expect(result.growiCommandArgs).toStrictEqual(['keyword1', 'keyword2']);
  58. });
  59. });