-
Notifications
You must be signed in to change notification settings - Fork 7.1k
Feat/sortable sessions table headers (Visits, Views, and Last Seen Columns) #4100
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
Open
superham
wants to merge
6
commits into
umami-software:master
Choose a base branch
from
superham:feat/sortable-sessions
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
1db7dce
add sortable column headers to sessions table
superham dc7193c
add cypress tests for sorting
superham d31740f
move orderBy/sortDescending params to sessions query
superham 8b748f8
de-duplicate SORT_COLUMNS across db backend
superham 42802df
validate orderBy against values in schema
superham 6f889a7
fix last seen column to use lastAt consistently
superham File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,210 @@ | ||
| describe('Sessions sorting API tests', () => { | ||
| Cypress.session.clearAllSavedSessions(); | ||
|
|
||
| let websiteId; | ||
|
|
||
| before(() => { | ||
| cy.login(Cypress.env('umami_user'), Cypress.env('umami_password')); | ||
| cy.fixture('websites').then(data => { | ||
| cy.request({ | ||
| method: 'POST', | ||
| url: '/api/websites', | ||
| headers: { | ||
| 'Content-Type': 'application/json', | ||
| Authorization: Cypress.env('authorization'), | ||
| }, | ||
| body: data.websiteCreate, | ||
| }).then(response => { | ||
| websiteId = response.body.id; | ||
| expect(response.status).to.eq(200); | ||
| }); | ||
| }); | ||
| }); | ||
|
|
||
| it('Returns sessions with default sort (no sort params).', () => { | ||
| const now = Date.now(); | ||
| const oneDayAgo = now - 86400000; | ||
|
|
||
| cy.request({ | ||
| method: 'GET', | ||
| url: `/api/websites/${websiteId}/sessions`, | ||
| headers: { | ||
| Authorization: Cypress.env('authorization'), | ||
| }, | ||
| qs: { | ||
| startAt: oneDayAgo, | ||
| endAt: now, | ||
| }, | ||
| }).then(response => { | ||
| expect(response.status).to.eq(200); | ||
| expect(response.body).to.have.property('data'); | ||
| expect(response.body).to.have.property('count'); | ||
| expect(response.body).to.have.property('page'); | ||
| expect(response.body).to.have.property('pageSize'); | ||
| }); | ||
| }); | ||
|
|
||
| it('Accepts orderBy=visits with sortDescending=true.', () => { | ||
| const now = Date.now(); | ||
| const oneDayAgo = now - 86400000; | ||
|
|
||
| cy.request({ | ||
| method: 'GET', | ||
| url: `/api/websites/${websiteId}/sessions`, | ||
| headers: { | ||
| Authorization: Cypress.env('authorization'), | ||
| }, | ||
| qs: { | ||
| startAt: oneDayAgo, | ||
| endAt: now, | ||
| orderBy: 'visits', | ||
| sortDescending: 'true', | ||
| }, | ||
| }).then(response => { | ||
| expect(response.status).to.eq(200); | ||
| expect(response.body).to.have.property('data'); | ||
| expect(response.body).to.have.property('orderBy'); | ||
| }); | ||
| }); | ||
|
|
||
| it('Accepts orderBy=views with sortDescending=false.', () => { | ||
| const now = Date.now(); | ||
| const oneDayAgo = now - 86400000; | ||
|
|
||
| cy.request({ | ||
| method: 'GET', | ||
| url: `/api/websites/${websiteId}/sessions`, | ||
| headers: { | ||
| Authorization: Cypress.env('authorization'), | ||
| }, | ||
| qs: { | ||
| startAt: oneDayAgo, | ||
| endAt: now, | ||
| orderBy: 'views', | ||
| sortDescending: 'false', | ||
| }, | ||
| }).then(response => { | ||
| expect(response.status).to.eq(200); | ||
| expect(response.body).to.have.property('data'); | ||
| }); | ||
| }); | ||
|
|
||
| it('Accepts orderBy=createdAt.', () => { | ||
| const now = Date.now(); | ||
| const oneDayAgo = now - 86400000; | ||
|
|
||
| cy.request({ | ||
| method: 'GET', | ||
| url: `/api/websites/${websiteId}/sessions`, | ||
| headers: { | ||
| Authorization: Cypress.env('authorization'), | ||
| }, | ||
| qs: { | ||
| startAt: oneDayAgo, | ||
| endAt: now, | ||
| orderBy: 'createdAt', | ||
| sortDescending: 'true', | ||
| }, | ||
| }).then(response => { | ||
| expect(response.status).to.eq(200); | ||
| expect(response.body).to.have.property('data'); | ||
| }); | ||
| }); | ||
|
|
||
| it('Accepts orderBy=firstAt.', () => { | ||
| const now = Date.now(); | ||
| const oneDayAgo = now - 86400000; | ||
|
|
||
| cy.request({ | ||
| method: 'GET', | ||
| url: `/api/websites/${websiteId}/sessions`, | ||
| headers: { | ||
| Authorization: Cypress.env('authorization'), | ||
| }, | ||
| qs: { | ||
| startAt: oneDayAgo, | ||
| endAt: now, | ||
| orderBy: 'firstAt', | ||
| sortDescending: 'false', | ||
| }, | ||
| }).then(response => { | ||
| expect(response.status).to.eq(200); | ||
| expect(response.body).to.have.property('data'); | ||
| }); | ||
| }); | ||
|
|
||
| it('Falls back gracefully with invalid orderBy value.', () => { | ||
| const now = Date.now(); | ||
| const oneDayAgo = now - 86400000; | ||
|
|
||
| cy.request({ | ||
| method: 'GET', | ||
| url: `/api/websites/${websiteId}/sessions`, | ||
| headers: { | ||
| Authorization: Cypress.env('authorization'), | ||
| }, | ||
| qs: { | ||
| startAt: oneDayAgo, | ||
| endAt: now, | ||
| orderBy: 'invalid_column', | ||
| sortDescending: 'true', | ||
| }, | ||
| }).then(response => { | ||
| expect(response.status).to.eq(200); | ||
| expect(response.body).to.have.property('data'); | ||
| }); | ||
| }); | ||
|
|
||
| it('Works with sorting combined with search.', () => { | ||
| const now = Date.now(); | ||
| const oneDayAgo = now - 86400000; | ||
|
|
||
| cy.request({ | ||
| method: 'GET', | ||
| url: `/api/websites/${websiteId}/sessions`, | ||
| headers: { | ||
| Authorization: Cypress.env('authorization'), | ||
| }, | ||
| qs: { | ||
| startAt: oneDayAgo, | ||
| endAt: now, | ||
| orderBy: 'views', | ||
| sortDescending: 'true', | ||
| search: 'Chrome', | ||
| }, | ||
| }).then(response => { | ||
| expect(response.status).to.eq(200); | ||
| expect(response.body).to.have.property('data'); | ||
| }); | ||
| }); | ||
|
|
||
| it('Works with sorting combined with pagination.', () => { | ||
| const now = Date.now(); | ||
| const oneDayAgo = now - 86400000; | ||
|
|
||
| cy.request({ | ||
| method: 'GET', | ||
| url: `/api/websites/${websiteId}/sessions`, | ||
| headers: { | ||
| Authorization: Cypress.env('authorization'), | ||
| }, | ||
| qs: { | ||
| startAt: oneDayAgo, | ||
| endAt: now, | ||
| orderBy: 'visits', | ||
| sortDescending: 'true', | ||
| page: 1, | ||
| pageSize: 5, | ||
| }, | ||
| }).then(response => { | ||
| expect(response.status).to.eq(200); | ||
| expect(response.body).to.have.property('data'); | ||
| expect(response.body).to.have.property('page', 1); | ||
| expect(response.body).to.have.property('pageSize', 5); | ||
| }); | ||
| }); | ||
|
|
||
| after(() => { | ||
| cy.deleteWebsite(websiteId); | ||
| }); | ||
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,74 @@ | ||
| describe('Sessions sorting UI tests', () => { | ||
| Cypress.session.clearAllSavedSessions(); | ||
|
|
||
| let websiteId; | ||
|
|
||
| before(() => { | ||
| cy.login(Cypress.env('umami_user'), Cypress.env('umami_password')); | ||
| cy.request({ | ||
| method: 'POST', | ||
| url: '/api/websites', | ||
| headers: { | ||
| 'Content-Type': 'application/json', | ||
| Authorization: Cypress.env('authorization'), | ||
| }, | ||
| body: { name: 'Sort Test Site', domain: 'sorttest.com' }, | ||
| }).then(response => { | ||
| websiteId = response.body.id; | ||
| expect(response.status).to.eq(200); | ||
| }); | ||
| }); | ||
|
|
||
| beforeEach(() => { | ||
| cy.login(Cypress.env('umami_user'), Cypress.env('umami_password')); | ||
| cy.visit(`/websites/${websiteId}/sessions`); | ||
| }); | ||
|
|
||
| it('Renders sortable column headers for visits, views, and last seen.', () => { | ||
| cy.getDataTest('sort-visits').should('exist').and('be.visible'); | ||
| cy.getDataTest('sort-views').should('exist').and('be.visible'); | ||
| cy.getDataTest('sort-createdAt').should('exist').and('be.visible'); | ||
| }); | ||
|
|
||
| it('Clicking visits header adds orderBy and sortDescending to URL.', () => { | ||
| cy.getDataTest('sort-visits').click(); | ||
| cy.url().should('include', 'orderBy=visits'); | ||
| cy.url().should('include', 'sortDescending=true'); | ||
| }); | ||
|
|
||
| it('Clicking visits header twice toggles to ascending sort.', () => { | ||
| cy.getDataTest('sort-visits').click(); | ||
| cy.url().should('include', 'sortDescending=true'); | ||
|
|
||
| cy.getDataTest('sort-visits').click(); | ||
| cy.url().should('include', 'orderBy=visits'); | ||
| cy.url().should('include', 'sortDescending=false'); | ||
| }); | ||
|
|
||
| it('Clicking visits header three times clears sort params.', () => { | ||
| cy.getDataTest('sort-visits').click(); | ||
| cy.getDataTest('sort-visits').click(); | ||
| cy.getDataTest('sort-visits').click(); | ||
|
|
||
| cy.url().should('not.include', 'orderBy'); | ||
| cy.url().should('not.include', 'sortDescending'); | ||
| }); | ||
|
|
||
| it('Clicking a different column switches sort target.', () => { | ||
| cy.getDataTest('sort-visits').click(); | ||
| cy.url().should('include', 'orderBy=visits'); | ||
|
|
||
| cy.getDataTest('sort-views').click(); | ||
| cy.url().should('include', 'orderBy=views'); | ||
| cy.url().should('include', 'sortDescending=true'); | ||
| }); | ||
|
|
||
| it('Resets to page 1 when sort changes.', () => { | ||
| cy.getDataTest('sort-visits').click(); | ||
| cy.url().should('include', 'page=1'); | ||
| }); | ||
|
|
||
| after(() => { | ||
| cy.deleteWebsite(websiteId); | ||
| }); | ||
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.