Skip to content

Commit

Permalink
fix: page refresh causes deletion exception (#2593)
Browse files Browse the repository at this point in the history
  • Loading branch information
Morakes authored Aug 18, 2022
1 parent 0c0d854 commit d166405
Show file tree
Hide file tree
Showing 2 changed files with 89 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ context('Delete Plugin List with the Drawer', () => {

const data = {
basicAuthPlugin: 'basic-auth',
keyAuthPlugin: 'key-auth',
jwtAuthPlugin: 'jwt-auth',
};

beforeEach(() => {
Expand Down Expand Up @@ -214,4 +216,90 @@ context('Delete Plugin List with the Drawer', () => {
cy.visit('/plugin/list');
cy.get(selector.empty).should('be.visible');
});

it('should be deleted one of the plugins instead of all', function () {
cy.visit('/plugin/list');
cy.get(selector.refresh).click();
cy.contains('Enable').click();

const pluginList = [data.jwtAuthPlugin, data.basicAuthPlugin, data.keyAuthPlugin];
pluginList.forEach((item) => {
cy.contains(item)
.parents(selector.pluginCardBordered)
.within(() => {
cy.get('button').click({
force: true,
});
});
cy.get(selector.drawer)
.should('be.visible')
.within(() => {
cy.get(selector.disabledSwitcher).click();
cy.get(selector.checkedSwitcher).should('exist');
});
cy.contains('button', 'Submit').click();

cy.get(selector.drawer, {
timeout,
}).should('not.exist');
cy.get(selector.notification).should('contain', 'Configure Plugin Successfully');
cy.get(selector.notificationCloseIcon).click({ multiple: true });
});

cy.reload();
cy.contains(data.basicAuthPlugin)
.parents(selector.pluginCardBordered)
.within(() => {
cy.get('button').click({
force: true,
});
});
cy.get(selector.drawer).should('be.visible');
cy.contains('button', 'Delete').click();
cy.contains('button', 'Confirm').click({
force: true,
});
cy.get(selector.drawer, {
timeout,
}).should('not.exist');
cy.get(selector.notification).should('contain', 'Delete Plugin Successfully');
cy.get(selector.notificationCloseIcon).click({ multiple: true });

const remainPlugin = pluginList.filter((item) => item !== data.basicAuthPlugin);
remainPlugin.forEach((item) =>
cy
.contains(item)
.parents(selector.pluginCardBordered)
.within(() => {
cy.get('button').should('contain', 'Edit');
}),
);

cy.visit('/plugin/list');
cy.contains('Enable').click();

remainPlugin.forEach((item) => {
cy.contains(item)
.parents(selector.pluginCardBordered)
.within(() => {
cy.get('button').click();
});
cy.get(selector.drawer)
.should('be.visible')
.within(() => {
cy.get(selector.checkedSwitcher).should('exist');
});
cy.contains('button', 'Delete').click();
cy.contains('button', 'Confirm').click({
force: true,
});
cy.get(selector.drawer, {
timeout,
}).should('not.exist');
cy.get(selector.notification).should('contain', 'Delete Plugin Successfully');
cy.get(selector.notificationCloseIcon).click({ multiple: true });
});
cy.visit('/plugin/list');
cy.get(selector.empty).should('be.visible');
});
});
2 changes: 1 addition & 1 deletion web/src/components/Plugin/PluginPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,6 @@ const PluginPage: React.FC<Props> = ({
const [plugins, setPlugins] = useState({});

useEffect(() => {
setPlugins(initialData);
fetchList().then((data) => {
const filteredData = data.filter(
(item) =>
Expand All @@ -103,6 +102,7 @@ const PluginPage: React.FC<Props> = ({
const openPluginList = pluginList.filter(
(item) => initialData[item.name] && !initialData[item.name].disable,
);
setPlugins(initialData);
setEnablePluginsList(openPluginList);
}, [initialData, pluginList]);

Expand Down

0 comments on commit d166405

Please sign in to comment.