diff --git a/src/__data__/images.ts b/src/__data__/images.ts index 25cedce0e07..71b8d2cdcd8 100644 --- a/src/__data__/images.ts +++ b/src/__data__/images.ts @@ -252,3 +252,30 @@ export const images: Linode.Image[] = [ description: null } ]; + +export const privateImages: Linode.Image[] = [ + { + created_by: 'linode', + deprecated: false, + id: 'linode/debian8.7', + vendor: 'Debian', + size: 1100, + type: 'manual', + created: '2017-08-15T22:28:13', + is_public: false, + label: 'Debian 8.7', + description: null + }, + { + created_by: 'linode', + deprecated: false, + id: 'linode/containerlinux', + vendor: 'CoreOS', + size: 3000, + type: 'manual', + created: '2017-08-15T22:28:13', + is_public: false, + label: 'Container Linux', + description: null + } +]; diff --git a/src/features/linodes/LinodesCreate/TabbedContent/formUtilities.test.ts b/src/features/linodes/LinodesCreate/TabbedContent/formUtilities.test.ts new file mode 100644 index 00000000000..135fadec491 --- /dev/null +++ b/src/features/linodes/LinodesCreate/TabbedContent/formUtilities.test.ts @@ -0,0 +1,37 @@ +import { images, privateImages } from 'src/__data__/images'; +import { filterPublicImages, filterUDFErrors } from './formUtilities'; + +describe('Linode Create Utilities', () => { + it('should filter out public Images', () => { + const filteredImages = filterPublicImages([...images, ...privateImages]); + expect( + filteredImages.every(eachImage => !!eachImage.is_public) + ).toBeTruthy(); + }); + + it('should filter out all errors except UDF errors', () => { + const mockErrors: Linode.ApiFieldError[] = [ + { + field: 'label', + reason: 'label is required' + }, + { + field: 'ssh_keys', + reason: 'ssh_keys are required' + }, + { + field: 'wp_password', + reason: 'a value for the UDF is required' + } + ]; + + const errorResources = { + label: 'A label', + ssh_keys: 'ssh_keys' + }; + + const filteredErrors = filterUDFErrors(errorResources, mockErrors); + expect(filteredErrors[0].field).toBe('wp_password'); + expect(filteredErrors).toHaveLength(1); + }); +}); diff --git a/src/features/linodes/LinodesCreate/TabbedContent/formUtilities.ts b/src/features/linodes/LinodesCreate/TabbedContent/formUtilities.ts index 518cf665571..61578f47cd3 100644 --- a/src/features/linodes/LinodesCreate/TabbedContent/formUtilities.ts +++ b/src/features/linodes/LinodesCreate/TabbedContent/formUtilities.ts @@ -9,7 +9,7 @@ export const filterPublicImages = (images: Linode.Image[]) => { }; /** - * filter out all the UDF errors from our error state. + * filter out all the API errors that aren't UDF errors from our error state. * To do this, we compare the keys from the error state to our "errorResources" * map and return all the errors that don't match the keys in that object *