Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: page refresh causes deletion exception #2593

Merged
merged 6 commits into from
Aug 18, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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) => {
Comment on lines +225 to +226
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why not use Object.values(data)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If someone add the new plugins to the data object, it may affect this test case,so I added it manually.

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