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

feat: add page reload judgment #2370

Merged
merged 14 commits into from
May 6, 2022

Conversation

oil-oil
Copy link
Contributor

@oil-oil oil-oil commented Mar 9, 2022

Please answer these questions before submitting a pull request, or your PR will get closed.

  • Bugfix
  • New feature provided
  • Improve performance
  • Backport patches

What changes will this PR take into?

When the table needs to be reloaded after operation, judge whether there is no data on the current page. If there is no data, move the page number to the previous page.

Related issues

resolve: #2129

Checklist:

  • Did you explain what problem does this PR solve? Or what new features have been added?
  • Have you added corresponding test cases?
  • Have you modified the corresponding document?
  • Is this PR backward compatible? If it is not backward compatible, please discuss on the mailing list first

@codecov-commenter
Copy link

codecov-commenter commented Mar 9, 2022

Codecov Report

Merging #2370 (5b6671c) into master (561ed37) will increase coverage by 0.26%.
The diff coverage is 93.33%.

@@            Coverage Diff             @@
##           master    #2370      +/-   ##
==========================================
+ Coverage   68.52%   68.79%   +0.26%     
==========================================
  Files         131      131              
  Lines        3419     3432      +13     
  Branches      826      833       +7     
==========================================
+ Hits         2343     2361      +18     
+ Misses       1076     1071       -5     
Flag Coverage Δ
frontend-e2e-test 68.79% <93.33%> (+0.26%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

Impacted Files Coverage Δ
web/src/pages/Route/List.tsx 83.63% <85.71%> (+0.60%) ⬆️
web/src/hooks/usePagination.ts 100.00% <100.00%> (ø)
web/src/pages/Consumer/List.tsx 91.66% <100.00%> (+3.09%) ⬆️
web/src/pages/Proto/List.tsx 100.00% <100.00%> (+3.84%) ⬆️
web/src/pages/SSL/List.tsx 85.00% <100.00%> (ø)
web/src/pages/Service/List.tsx 94.11% <100.00%> (ø)
web/src/pages/Upstream/List.tsx 94.28% <100.00%> (+2.85%) ⬆️
web/src/pages/Consumer/Create.tsx 82.69% <0.00%> (ø)
web/src/pages/Consumer/components/Step1.tsx 100.00% <0.00%> (ø)
web/src/components/Plugin/PluginPage.tsx 98.82% <0.00%> (+0.08%) ⬆️
... and 6 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 561ed37...5b6671c. Read the comment docs.

Copy link
Contributor

@Baoyuantop Baoyuantop left a comment

Choose a reason for hiding this comment

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

need test case add

web/src/pages/Consumer/List.tsx Outdated Show resolved Hide resolved
@oil-oil
Copy link
Contributor Author

oil-oil commented Mar 14, 2022

I will modify the simulation operation to send a request to ensure the stability of the test.

@oil-oil
Copy link
Contributor Author

oil-oil commented Mar 16, 2022

@Baoyuantop @guoqqqi I have updated the test case, and now I can pass the test successfully. Please review it for me again.🤓

@Baoyuantop
Copy link
Contributor

The structure of the test needs to be more rationalized.

it('should delete last data and jump to first page', () => {
cy.visit('/');
cy.contains('Consumer').click();
cy.wait(500);
Copy link
Member

Choose a reason for hiding this comment

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

Do we really need to wait for this?

Comment on lines 35 to 41
const deleteProto = () => {
cy.wait(500);
cy.contains('Delete').click();
cy.contains('button', 'Confirm').click();
cy.get(selector.notification).should('contain', data.deleteProtoSuccess);
cy.get(selector.notificationCloseIcon).click();
};
Copy link
Member

Choose a reason for hiding this comment

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

We can use the custom command from the official documentation, By the way, we do not recommend using wait
https://docs.cypress.io/api/cypress-api/custom-commands
https://docs.cypress.io/api/commands/wait#Wait-for-an-arbitrary-period-of-milliseconds

cy.wait(500);
cy.get(selector.page_item).click();
cy.wait(500);
deleteProto();
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
deleteProto();
deleteProto();

IMO, I think it looks strange the way it's written.

}
};

return { paginationConfig, savePageList, checkPageList };
Copy link
Member

Choose a reason for hiding this comment

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

Since we have abstracted the pager into a hook, is it enough for us to write a test for the pagination

deleteConsumerSuccess: 'Delete Consumer Successfully',
};

beforeEach(() => {
Copy link
Contributor

Choose a reason for hiding this comment

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

beforeEach or before?

Copy link
Contributor

@Baoyuantop Baoyuantop left a comment

Choose a reason for hiding this comment

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

LGTM

@Baoyuantop
Copy link
Contributor

cc @guoqqqi

cy.visit('/');
cy.contains('Consumer').click();
cy.get(selector.page_item).click();
cy.wait(1000);
Copy link
Member

Choose a reason for hiding this comment

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

Why wait for 1 s?

Copy link
Member

Choose a reason for hiding this comment

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

@oil-oil ping

cy.contains('Consumer').click();
cy.get(selector.page_item).click();
cy.wait(1000);
cy.contains('Delete').click({ force: true });
Copy link
Member

Choose a reason for hiding this comment

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

the force: true will not ensure that the click on delete will be successful, so why use force here?

Comment on lines 35 to 45
beforeEach(() => {
cy.login();
Array.from({ length: 11 }).forEach(async (value, key) => {
const payload = {
content: 'test',
desc: '',
id: `protoId${key}`,
};
cy.requestWithToken({ method: 'POST', payload, url: '/apisix/admin/proto' });
});
});
Copy link
Member

Choose a reason for hiding this comment

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

Note that using an array loop in beforeEach will cause the loop to be run once for each test case run

cy.visit('/');
cy.contains('Protocol Buffers').click();
cy.get(selector.page_item).click();
cy.wait(1000);
Copy link
Member

Choose a reason for hiding this comment

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

ditto

@@ -30,5 +33,14 @@ export default function usePagination() {
history.replace(`${location.pathname}?page=${page}&pageSize=${pageSize}`);
};

return { paginationConfig, savePageList };
const checkPageList = (ref: MutableRefObject<ActionType | undefined>) => {
const { current, pageSize, total } = ref.current!.pageInfo as PageInfo;
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
const { current, pageSize, total } = ref.current!.pageInfo as PageInfo;
const { current, pageSize, total } = ref.current?.pageInfo as PageInfo;

!. will just remove undefined and null from the current's type. Maybe ?. is better?

@oil-oil oil-oil requested a review from guoqqqi April 2, 2022 10:31
@oil-oil oil-oil requested a review from Baoyuantop April 12, 2022 07:04
Copy link
Contributor

@Baoyuantop Baoyuantop left a comment

Choose a reason for hiding this comment

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

@SkyeYoung
Copy link
Member

There is no preview here, the code looks ok.

@Baoyuantop Baoyuantop requested a review from LiteSun April 24, 2022 05:06
};

before(() => {
cy.login();
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
cy.login();
cy.login().then( () => { cy.requestWithToken({ method: 'PUT', payload, url: '/apisix/admin/consumers' });
});

};

before(() => {
cy.login();
Copy link
Member

Choose a reason for hiding this comment

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

ditto

@oil-oil
Copy link
Contributor Author

oil-oil commented Apr 28, 2022

@LiteSun OK, I'll update it

@oil-oil oil-oil requested a review from LiteSun April 30, 2022 06:39
@Baoyuantop
Copy link
Contributor

cc @LiteSun

@Baoyuantop Baoyuantop merged commit 30fa852 into apache:master May 6, 2022
hongbinhsu pushed a commit to fitphp/apix-dashboard that referenced this pull request May 24, 2022
* upstream: (28 commits)
  docs: update some tips in develop.md (apache#2451)
  fix: create upstream error when pass host is node and nodes without port (apache#2421)
  fix: correct data  type of filed Active.checks.active.https_verify_certificate (apache#2422)
  feat: basic support Apache APISIX 2.13.0 (apache#2428)
  feat: add page reload judgment (apache#2370)
  docs: Update RPM install package link (apache#2439)
  docs: Remove hyperlinks from documents (apache#2431)
  chore(deps): bump actions/upload-artifact from 2 to 3 (apache#2423)
  fix: consumer without plugins causes page crashes (apache#2437)
  chore(deps): bump axios from 0.21.1 to 0.21.4 in /web (apache#2420)
  feat: Modify plugin preview page (apache#2359)
  chore(deps): bump moment from 2.29.1 to 2.29.2 in /web (apache#2418)
  chore: use json schema instead hard code (apache#2399)
  refactor: migrate route tests to e2enew (apache#2411)
  chore(deps): bump actions/setup-python from 2.3.2 to 3.1.1 (apache#2414)
  chore: update the year of copyright and fix typo (apache#2417)
  docs: update online playground url (apache#2416)
  chore: update README for online demo (apache#2404)
  refactor: migrate id compatible tests to e2enew (apache#2400)
  docs: fix invalid link (apache#2366)
  ...

# Conflicts:
#	api/internal/route.go
#	web/src/components/Footer/index.tsx
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Bug: route pagination error when delete the route item in the last page
6 participants