actions.test.ts 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. import { findNewName, nameExits } from './actions';
  2. import { getMockPlugin, getMockPlugins } from '../../plugins/__mocks__/pluginMocks';
  3. describe('Name exists', () => {
  4. const plugins = getMockPlugins(5);
  5. it('should be true', () => {
  6. const name = 'pretty cool plugin-1';
  7. expect(nameExits(plugins, name)).toEqual(true);
  8. });
  9. it('should be false', () => {
  10. const name = 'pretty cool plugin-6';
  11. expect(nameExits(plugins, name));
  12. });
  13. });
  14. describe('Find new name', () => {
  15. it('should create a new name', () => {
  16. const plugins = getMockPlugins(5);
  17. const name = 'pretty cool plugin-1';
  18. expect(findNewName(plugins, name)).toEqual('pretty cool plugin-6');
  19. });
  20. it('should create new name without suffix', () => {
  21. const plugin = getMockPlugin();
  22. plugin.name = 'prometheus';
  23. const plugins = [plugin];
  24. const name = 'prometheus';
  25. expect(findNewName(plugins, name)).toEqual('prometheus-1');
  26. });
  27. it('should handle names that end with -', () => {
  28. const plugin = getMockPlugin();
  29. const plugins = [plugin];
  30. const name = 'pretty cool plugin-';
  31. expect(findNewName(plugins, name)).toEqual('pretty cool plugin-');
  32. });
  33. });