From 8f77d15a3135dcc4ceb9114e81ba58c9d8c8006e Mon Sep 17 00:00:00 2001 From: Keith Grant Date: Fri, 7 Feb 2020 11:55:09 -0800 Subject: [PATCH] fix errors being logged during tests; de-lint --- awx/ui_next/src/components/FormField/FormSubmitError.jsx | 3 +-- awx/ui_next/src/screens/Host/HostAdd/HostAdd.test.jsx | 6 ++++++ .../src/screens/Inventory/InventoryAdd/InventoryAdd.jsx | 1 - .../src/screens/Inventory/InventoryEdit/InventoryEdit.jsx | 1 - .../Organization/OrganizationAdd/OrganizationAdd.test.jsx | 1 + awx/ui_next/src/screens/Team/TeamAdd/TeamAdd.jsx | 2 +- awx/ui_next/src/screens/Team/TeamAdd/TeamAdd.test.jsx | 1 + awx/ui_next/src/screens/User/UserAdd/UserAdd.test.jsx | 1 + 8 files changed, 11 insertions(+), 5 deletions(-) diff --git a/awx/ui_next/src/components/FormField/FormSubmitError.jsx b/awx/ui_next/src/components/FormField/FormSubmitError.jsx index 5e25a7ae50..6dd5db1c32 100644 --- a/awx/ui_next/src/components/FormField/FormSubmitError.jsx +++ b/awx/ui_next/src/components/FormField/FormSubmitError.jsx @@ -10,8 +10,7 @@ function FormSubmitError({ error }) { if (!error) { return; } - // check for field-specific errors from API - if (error.response?.data && typeof error.response.data === 'object') { + if (error?.response?.data && typeof error.response.data === 'object') { const errorMessages = error.response.data; setErrors(errorMessages); if (errorMessages.__all__) { diff --git a/awx/ui_next/src/screens/Host/HostAdd/HostAdd.test.jsx b/awx/ui_next/src/screens/Host/HostAdd/HostAdd.test.jsx index 2a0e419675..ebb302fc42 100644 --- a/awx/ui_next/src/screens/Host/HostAdd/HostAdd.test.jsx +++ b/awx/ui_next/src/screens/Host/HostAdd/HostAdd.test.jsx @@ -30,6 +30,12 @@ describe('', () => { }); test('handleSubmit should post to api', async () => { + HostsAPI.create.mockResolvedValueOnce({ + data: { + ...hostData, + id: 5, + }, + }); await act(async () => { wrapper.find('HostForm').prop('handleSubmit')(hostData); }); diff --git a/awx/ui_next/src/screens/Inventory/InventoryAdd/InventoryAdd.jsx b/awx/ui_next/src/screens/Inventory/InventoryAdd/InventoryAdd.jsx index 521eef2191..a0afa8520b 100644 --- a/awx/ui_next/src/screens/Inventory/InventoryAdd/InventoryAdd.jsx +++ b/awx/ui_next/src/screens/Inventory/InventoryAdd/InventoryAdd.jsx @@ -2,7 +2,6 @@ import React, { useState, useEffect } from 'react'; import { useHistory } from 'react-router-dom'; import { PageSection, Card } from '@patternfly/react-core'; import { CardBody } from '@components/Card'; -import ContentError from '@components/ContentError'; import ContentLoading from '@components/ContentLoading'; import { InventoriesAPI, CredentialTypesAPI } from '@api'; diff --git a/awx/ui_next/src/screens/Inventory/InventoryEdit/InventoryEdit.jsx b/awx/ui_next/src/screens/Inventory/InventoryEdit/InventoryEdit.jsx index a86b1ddad5..cbc1b2126d 100644 --- a/awx/ui_next/src/screens/Inventory/InventoryEdit/InventoryEdit.jsx +++ b/awx/ui_next/src/screens/Inventory/InventoryEdit/InventoryEdit.jsx @@ -5,7 +5,6 @@ import { object } from 'prop-types'; import { CardBody } from '@components/Card'; import { InventoriesAPI, CredentialTypesAPI } from '@api'; import ContentLoading from '@components/ContentLoading'; -import ContentError from '@components/ContentError'; import InventoryForm from '../shared/InventoryForm'; import { getAddedAndRemoved } from '../../../util/lists'; diff --git a/awx/ui_next/src/screens/Organization/OrganizationAdd/OrganizationAdd.test.jsx b/awx/ui_next/src/screens/Organization/OrganizationAdd/OrganizationAdd.test.jsx index 0e499e8cda..4618508afc 100644 --- a/awx/ui_next/src/screens/Organization/OrganizationAdd/OrganizationAdd.test.jsx +++ b/awx/ui_next/src/screens/Organization/OrganizationAdd/OrganizationAdd.test.jsx @@ -14,6 +14,7 @@ describe('', () => { description: 'new description', custom_virtualenv: 'Buzz', }; + OrganizationsAPI.create.mockResolvedValueOnce({ data: {} }); await act(async () => { const wrapper = mountWithContexts(); wrapper.find('OrganizationForm').prop('onSubmit')(updatedOrgData, [], []); diff --git a/awx/ui_next/src/screens/Team/TeamAdd/TeamAdd.jsx b/awx/ui_next/src/screens/Team/TeamAdd/TeamAdd.jsx index 6ef57538a0..d9488b39c4 100644 --- a/awx/ui_next/src/screens/Team/TeamAdd/TeamAdd.jsx +++ b/awx/ui_next/src/screens/Team/TeamAdd/TeamAdd.jsx @@ -12,7 +12,7 @@ class TeamAdd extends React.Component { super(props); this.handleSubmit = this.handleSubmit.bind(this); this.handleCancel = this.handleCancel.bind(this); - this.state = { error: '' }; + this.state = { error: null }; } async handleSubmit(values) { diff --git a/awx/ui_next/src/screens/Team/TeamAdd/TeamAdd.test.jsx b/awx/ui_next/src/screens/Team/TeamAdd/TeamAdd.test.jsx index 07aa2382fc..7d1eddeabf 100644 --- a/awx/ui_next/src/screens/Team/TeamAdd/TeamAdd.test.jsx +++ b/awx/ui_next/src/screens/Team/TeamAdd/TeamAdd.test.jsx @@ -9,6 +9,7 @@ jest.mock('@api'); describe('', () => { test('handleSubmit should post to api', async () => { + TeamsAPI.create.mockResolvedValueOnce({ data: {} }); const wrapper = mountWithContexts(); const updatedTeamData = { name: 'new name', diff --git a/awx/ui_next/src/screens/User/UserAdd/UserAdd.test.jsx b/awx/ui_next/src/screens/User/UserAdd/UserAdd.test.jsx index 0ea4d56e19..1537855d0e 100644 --- a/awx/ui_next/src/screens/User/UserAdd/UserAdd.test.jsx +++ b/awx/ui_next/src/screens/User/UserAdd/UserAdd.test.jsx @@ -13,6 +13,7 @@ describe('', () => { await act(async () => { wrapper = mountWithContexts(); }); + UsersAPI.create.mockResolvedValueOnce({ data: {} }); const updatedUserData = { username: 'sysadmin', email: 'sysadmin@ansible.com',