|
| 1 | +import { ContextMenuCommandAssertions, ContextMenuCommandBuilder } from '../src/index'; |
| 2 | + |
| 3 | +const getBuilder = () => new ContextMenuCommandBuilder(); |
| 4 | + |
| 5 | +describe('Context Menu Commands', () => { |
| 6 | + describe('Assertions tests', () => { |
| 7 | + test('GIVEN valid name THEN does not throw error', () => { |
| 8 | + expect(() => ContextMenuCommandAssertions.validateName('ping')).not.toThrowError(); |
| 9 | + }); |
| 10 | + |
| 11 | + test('GIVEN invalid name THEN throw error', () => { |
| 12 | + expect(() => ContextMenuCommandAssertions.validateName(null)).toThrowError(); |
| 13 | + |
| 14 | + // Too short of a name |
| 15 | + expect(() => ContextMenuCommandAssertions.validateName('')).toThrowError(); |
| 16 | + |
| 17 | + // Invalid characters used |
| 18 | + expect(() => ContextMenuCommandAssertions.validateName('ABC123$%^&')).toThrowError(); |
| 19 | + |
| 20 | + // Too long of a name |
| 21 | + expect(() => |
| 22 | + ContextMenuCommandAssertions.validateName('qwertyuiopasdfghjklzxcvbnmqwertyuiopasdfghjklzxcvbnm'), |
| 23 | + ).toThrowError(); |
| 24 | + }); |
| 25 | + |
| 26 | + test('GIVEN valid type THEN does not throw error', () => { |
| 27 | + expect(() => ContextMenuCommandAssertions.validateType(3)).not.toThrowError(); |
| 28 | + }); |
| 29 | + |
| 30 | + test('GIVEN invalid type THEN throw error', () => { |
| 31 | + expect(() => ContextMenuCommandAssertions.validateType(null)).toThrowError(); |
| 32 | + |
| 33 | + // Out of range |
| 34 | + expect(() => ContextMenuCommandAssertions.validateType(1)).toThrowError(); |
| 35 | + }); |
| 36 | + |
| 37 | + test('GIVEN valid required parameters THEN does not throw error', () => { |
| 38 | + expect(() => ContextMenuCommandAssertions.validateRequiredParameters('owo', 2)).not.toThrowError(); |
| 39 | + }); |
| 40 | + |
| 41 | + test('GIVEN valid default_permission THEN does not throw error', () => { |
| 42 | + expect(() => ContextMenuCommandAssertions.validateDefaultPermission(true)).not.toThrowError(); |
| 43 | + }); |
| 44 | + |
| 45 | + test('GIVEN invalid default_permission THEN throw error', () => { |
| 46 | + expect(() => ContextMenuCommandAssertions.validateDefaultPermission(null)).toThrowError(); |
| 47 | + }); |
| 48 | + }); |
| 49 | + |
| 50 | + describe('ContextMenuCommandBuilder', () => { |
| 51 | + describe('Builder tests', () => { |
| 52 | + test('GIVEN empty builder THEN throw error when calling toJSON', () => { |
| 53 | + expect(() => getBuilder().toJSON()).toThrowError(); |
| 54 | + }); |
| 55 | + |
| 56 | + test('GIVEN valid builder THEN does not throw error', () => { |
| 57 | + expect(() => getBuilder().setName('example').setType(3).toJSON()).not.toThrowError(); |
| 58 | + }); |
| 59 | + |
| 60 | + test('GIVEN invalid name THEN throw error', () => { |
| 61 | + expect(() => getBuilder().setName('$$$')).toThrowError(); |
| 62 | + |
| 63 | + expect(() => getBuilder().setName(' ')).toThrowError(); |
| 64 | + }); |
| 65 | + |
| 66 | + test('GIVEN valid names THEN does not throw error', () => { |
| 67 | + expect(() => getBuilder().setName('hi_there')).not.toThrowError(); |
| 68 | + |
| 69 | + expect(() => getBuilder().setName('A COMMAND')).not.toThrowError(); |
| 70 | + |
| 71 | + // Translation: a_command |
| 72 | + expect(() => getBuilder().setName('o_comandă')).not.toThrowError(); |
| 73 | + |
| 74 | + // Translation: thx (according to GTranslate) |
| 75 | + expect(() => getBuilder().setName('どうも')).not.toThrowError(); |
| 76 | + }); |
| 77 | + |
| 78 | + test('GIVEN valid types THEN does not throw error', () => { |
| 79 | + expect(() => getBuilder().setType(2)).not.toThrowError(); |
| 80 | + |
| 81 | + expect(() => getBuilder().setType(3)).not.toThrowError(); |
| 82 | + }); |
| 83 | + |
| 84 | + test('GIVEN valid builder with defaultPermission false THEN does not throw error', () => { |
| 85 | + expect(() => getBuilder().setName('foo').setDefaultPermission(false)).not.toThrowError(); |
| 86 | + }); |
| 87 | + }); |
| 88 | + }); |
| 89 | +}); |
0 commit comments