Skip to content

Commit

Permalink
fix: consumer e2e
Browse files Browse the repository at this point in the history
  • Loading branch information
LiteSun committed Dec 30, 2020
1 parent 8948a8f commit 5191da7
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,8 @@ context('Create and Delete Consumer', () => {
cy.contains(domSelectors.pluginsCard, 'key-auth').within(() => {
cy.get('button').first().click();
});

cy.get('#disable').click();
// edit codemirror
cy.get('.CodeMirror')
.first()
Expand Down
6 changes: 3 additions & 3 deletions web/src/components/Plugin/PluginDetail.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,8 @@ const PluginDetail: React.FC<Props> = ({
visible,
readonly = false,
initialData = {},
onClose = () => {},
onChange = () => {},
onClose = () => { },
onChange = () => { },
}) => {
const { formatMessage } = useIntl();
const [form] = Form.useForm();
Expand Down Expand Up @@ -173,7 +173,7 @@ const PluginDetail: React.FC<Props> = ({
}
}}
>
{formatMessage({ id: 'component.global.confirm' })}
{formatMessage({ id: 'component.global.submit' })}
</Button>
</div>
}
Expand Down
6 changes: 3 additions & 3 deletions web/src/components/Plugin/PluginPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ const PluginPage: React.FC<Props> = ({
initialData = {},
schemaType = 'route',
type = 'scoped',
onChange = () => {},
onChange = () => { },
}) => {
const [pluginList, setPluginList] = useState<PluginComponent.Meta[]>([]);
const [name, setName] = useState<string>(NEVER_EXIST_PLUGIN_FLAG);
Expand Down Expand Up @@ -141,10 +141,10 @@ const PluginPage: React.FC<Props> = ({
onClose={() => {
setName(NEVER_EXIST_PLUGIN_FLAG);
}}
onChange={(data) => {
onChange={({ codemirrorData, formData }) => {
onChange({
...initialData,
[name]: { ...initialData[name], disable: !data.formData.disable },
[name]: { ...codemirrorData, disable: !formData.disable },
});
setName(NEVER_EXIST_PLUGIN_FLAG);
}}
Expand Down
32 changes: 16 additions & 16 deletions web/src/pages/Consumer/Create.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,16 @@ import { Card, Steps, notification, Form } from 'antd';
import { history, useIntl } from 'umi';

import ActionBar from '@/components/ActionBar';
import PluginPage, { PLUGIN_MAPPER_SOURCE } from '@/components/Plugin';
import PluginPage from '@/components/Plugin';

import Step1 from './components/Step1';
import Preview from './components/Preview';
import { fetchItem, create, update } from './service';
import { fetchItem, create, update, fetchPlugList } from './service';

const Page: React.FC = (props) => {
const [step, setStep] = useState(1);
const [plugins, setPlugins] = useState<PluginComponent.Data>({});
const [pluginList, setPluginList] = useState<PluginComponent.Meta[]>([])
const [form1] = Form.useForm();
const { formatMessage } = useIntl();

Expand All @@ -41,6 +42,8 @@ const Page: React.FC = (props) => {
setPlugins(rest.plugins);
});
}

fetchPlugList().then(setPluginList);
}, []);

const onSubmit = () => {
Expand All @@ -49,13 +52,12 @@ const Page: React.FC = (props) => {
(username ? update(username, data) : create(data))
.then(() => {
notification.success({
message: `${
username
? formatMessage({ id: 'component.global.edit' })
: formatMessage({ id: 'component.global.create' })
} ${formatMessage({ id: 'menu.consumer' })} ${formatMessage({
id: 'component.status.success',
})}`,
message: `${username
? formatMessage({ id: 'component.global.edit' })
: formatMessage({ id: 'component.global.create' })
} ${formatMessage({ id: 'menu.consumer' })} ${formatMessage({
id: 'component.status.success',
})}`,
});
history.push('/consumer/list');
})
Expand All @@ -74,8 +76,7 @@ const Page: React.FC = (props) => {
if (
!Object.keys(plugins).filter(
(name) =>
(name.indexOf('auth') !== -1 ||
PLUGIN_MAPPER_SOURCE[name]?.category === 'Authentication') &&
(pluginList.find(item => item.name === name)!.type === 'auth') &&
!plugins[name].disable,
).length
) {
Expand All @@ -97,11 +98,10 @@ const Page: React.FC = (props) => {
return (
<>
<PageContainer
title={`${
(props as any).match.params.id
? formatMessage({ id: 'component.global.edit' })
: formatMessage({ id: 'component.global.create' })
} ${formatMessage({ id: 'menu.consumer' })}`}
title={`${(props as any).match.params.id
? formatMessage({ id: 'component.global.edit' })
: formatMessage({ id: 'component.global.create' })
} ${formatMessage({ id: 'menu.consumer' })}`}
>
<Card bordered={false}>
<Steps current={step - 1} style={{ marginBottom: 30 }}>
Expand Down
6 changes: 6 additions & 0 deletions web/src/pages/Consumer/service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,3 +44,9 @@ export const update = (username: string, data: ConsumerModule.Entity) =>
});

export const remove = (username: string) => request(`/consumers/${username}`, { method: 'DELETE' });

export const fetchPlugList = () => {
return request<Res<PluginComponent.Meta[]>>('/plugins?all=true').then((data) => {
return data.data;
});
};

0 comments on commit 5191da7

Please sign in to comment.