Skip to content

Commit

Permalink
Fix AddCustomSourceLogic
Browse files Browse the repository at this point in the history
  • Loading branch information
Byron Hulcher committed May 10, 2022
1 parent d2d337c commit 7273c8f
Show file tree
Hide file tree
Showing 6 changed files with 44 additions and 32 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,12 @@ export const AddCustomSource: React.FC = () => {

return (
<Layout pageChrome={[NAV.SOURCES, NAV.ADD_SOURCE, sourceData.name]}>
{currentStep === AddCustomSourceSteps.ConfigureCustomStep && <ConfigureCustom />}
{currentStep === AddCustomSourceSteps.SaveCustomStep && <SaveCustom />}
{currentStep === AddCustomSourceSteps.ConfigureCustomStep && (
<ConfigureCustom sourceData={sourceData} />
)}
{currentStep === AddCustomSourceSteps.SaveCustomStep && (
<SaveCustom sourceData={sourceData} />
)}
</Layout>
);
};
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import { kea, MakeLogicType } from 'kea';
import { flashAPIErrors, clearFlashMessages } from '../../../../../../shared/flash_messages';
import { HttpLogic } from '../../../../../../shared/http';
import { AppLogic } from '../../../../../app_logic';
import { CustomSource, SourceDataItem } from '../../../../../types';
import { CustomSource } from '../../../../../types';

export interface AddCustomSourceProps {
baseServiceType?: string;
Expand All @@ -34,7 +34,6 @@ interface AddCustomSourceValues {
currentStep: AddCustomSourceSteps;
customSourceNameValue: string;
newCustomSource: CustomSource;
sourceData: SourceDataItem;
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,24 +21,24 @@ import { ConfigureCustom } from './configure_custom';
describe('ConfigureCustom', () => {
const setCustomSourceNameValue = jest.fn();
const createContentSource = jest.fn();
const sourceData = staticSourceData[1];

beforeEach(() => {
setMockActions({ setCustomSourceNameValue, createContentSource });
setMockValues({
customSourceNameValue: 'name',
buttonLoading: false,
sourceData: staticSourceData[1],
});
});

it('renders', () => {
const wrapper = shallow(<ConfigureCustom />);
const wrapper = shallow(<ConfigureCustom sourceData={sourceData} />);

expect(wrapper.find(EuiForm)).toHaveLength(1);
});

it('handles input change', () => {
const wrapper = shallow(<ConfigureCustom />);
const wrapper = shallow(<ConfigureCustom sourceData={sourceData} />);
const text = 'changed for the better';
const input = wrapper.find(EuiFieldText);
input.simulate('change', { target: { value: text } });
Expand All @@ -47,7 +47,7 @@ describe('ConfigureCustom', () => {
});

it('handles form submission', () => {
const wrapper = shallow(<ConfigureCustom />);
const wrapper = shallow(<ConfigureCustom sourceData={sourceData} />);

const preventDefault = jest.fn();
wrapper.find('EuiForm').simulate('submit', { preventDefault });
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,21 +21,27 @@ import {
EuiText,
EuiTitle,
} from '@elastic/eui';

import { FormattedMessage } from '@kbn/i18n-react';

import { docLinks } from '../../../../../../shared/doc_links';

import connectionIllustration from '../../../../../assets/connection_illustration.svg';
import { SourceDataItem } from '../../../../../types';
import { SOURCE_NAME_LABEL } from '../../../constants';

import { AddSourceHeader } from '../add_source_header';
import { CONFIG_CUSTOM_BUTTON, CONFIG_CUSTOM_LINK_TEXT, CONFIG_INTRO_ALT_TEXT } from '../constants';

import { AddCustomSourceLogic } from './add_custom_source_logic';

export const ConfigureCustom: React.FC = () => {
interface ConfigureCustomProps {
sourceData: SourceDataItem;
}

export const ConfigureCustom: React.FC<ConfigureCustomProps> = ({ sourceData }) => {
const { setCustomSourceNameValue, createContentSource } = useActions(AddCustomSourceLogic);
const { customSourceNameValue, buttonLoading, sourceData } = useValues(AddCustomSourceLogic);
const { customSourceNameValue, buttonLoading } = useValues(AddCustomSourceLogic);

const handleFormSubmit = (e: FormEvent) => {
e.preventDefault();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,18 +25,21 @@ const mockValues = {
accessToken: 'token',
name: 'name',
},
sourceData: staticCustomSourceData,
};

const sourceData = staticCustomSourceData;

describe('SaveCustom', () => {
beforeAll(() => {
jest.clearAllMocks();
setMockValues(mockValues);
});

describe('default behavior', () => {
let wrapper: ShallowWrapper;

beforeAll(() => {
jest.clearAllMocks();
setMockValues(mockValues);

wrapper = shallow(<SaveCustom />);
wrapper = shallow(<SaveCustom sourceData={sourceData} />);
});

it('contains a button back to the sources list', () => {
Expand All @@ -52,20 +55,14 @@ describe('SaveCustom', () => {
let wrapper: ShallowWrapper;

beforeAll(() => {
jest.clearAllMocks();
setMockValues({
...mockValues,
sourceData: {
...staticCustomSourceData,
serviceType: 'sharepoint-server',
configuration: {
...staticCustomSourceData.configuration,
githubRepository: 'elastic/sharepoint-server-connector',
},
},
});

wrapper = shallow(<SaveCustom />);
wrapper = shallow(
<SaveCustom
sourceData={{
...sourceData,
baseServiceType: 'share_point_server',
}}
/>
);
});

it('includes a link to provide feedback', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,14 @@ import {
EuiCallOut,
EuiLink,
} from '@elastic/eui';

import { i18n } from '@kbn/i18n';
import { FormattedMessage } from '@kbn/i18n-react';

import { EuiButtonTo } from '../../../../../../shared/react_router_helpers';
import { AppLogic } from '../../../../../app_logic';
import { SOURCES_PATH, getSourcesPath } from '../../../../../routes';
import { SourceDataItem } from '../../../../../types';

import { CustomSourceDeployment } from '../../custom_source_deployment';

Expand All @@ -35,8 +37,12 @@ import { SAVE_CUSTOM_BODY1 as READY_TO_ACCEPT_REQUESTS_LABEL } from '../constant

import { AddCustomSourceLogic } from './add_custom_source_logic';

export const SaveCustom: React.FC = () => {
const { newCustomSource, sourceData } = useValues(AddCustomSourceLogic);
interface SaveCustomProps {
sourceData: SourceDataItem;
}

export const SaveCustom: React.FC<SaveCustomProps> = ({ sourceData }) => {
const { newCustomSource } = useValues(AddCustomSourceLogic);
const { isOrganization } = useValues(AppLogic);
const { serviceType, baseServiceType, name, categories = [] } = sourceData;

Expand Down Expand Up @@ -95,7 +101,7 @@ export const SaveCustom: React.FC = () => {
<CustomSourceDeployment source={newCustomSource} baseServiceType={baseServiceType} />
</EuiFlexItem>
</EuiFlexGroup>
{serviceType !== 'custom' && (
{baseServiceType && (
<>
<EuiSpacer />
<EuiFlexGroup justifyContent="center">
Expand Down

0 comments on commit 7273c8f

Please sign in to comment.