| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475 |
- import { InvalidGrowiCommandError } from '../models/errors';
- import { parseSlashCommand } from './slash-command-parser';
- describe('parseSlashCommand', () => {
- describe('without growiCommandType', () => {
- test('throws InvalidGrowiCommandError', () => {
- // setup
- const text = '';
- const slashCommand = { text };
- // when/then
- expect(() => {
- parseSlashCommand(slashCommand);
- }).toThrowError(InvalidGrowiCommandError);
- });
- });
- test('returns a GrowiCommand instance with empty growiCommandArgs', () => {
- // setup
- const text = 'search';
- const slashCommand = { text };
- // when
- const result = parseSlashCommand(slashCommand);
- // then
- expect(result.text).toBe(text);
- expect(result.growiCommandType).toBe('search');
- expect(result.growiCommandArgs).toStrictEqual([]);
- });
- test('returns a GrowiCommand instance with space growiCommandType', () => {
- // setup
- const text = ' search ';
- const slashCommand = { text };
- // when
- const result = parseSlashCommand(slashCommand);
- // then
- expect(result.text).toBe(text);
- expect(result.growiCommandType).toBe('search');
- expect(result.growiCommandArgs).toStrictEqual([]);
- });
- test('returns a GrowiCommand instance with space growiCommandArgs', () => {
- // setup
- const text = ' search hoge ';
- const slashCommand = { text };
- // when
- const result = parseSlashCommand(slashCommand);
- // then
- expect(result.text).toBe(text);
- expect(result.growiCommandType).toBe('search');
- expect(result.growiCommandArgs).toStrictEqual(['hoge']);
- });
- test('returns a GrowiCommand instance', () => {
- // setup
- const text = 'search keyword1 keyword2';
- const slashCommand = { text };
- // when
- const result = parseSlashCommand(slashCommand);
- // then
- expect(result.text).toBe(text);
- expect(result.growiCommandType).toBe('search');
- expect(result.growiCommandArgs).toStrictEqual(['keyword1', 'keyword2']);
- });
- });
|