| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374 |
- 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']);
- });
- });
|