-
Notifications
You must be signed in to change notification settings - Fork 4.4k
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
Cypress tests for query parameters #3810
Merged
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
13c0634
Add Cypress query parameter spec
gabrieldutra b80d23c
Add Dropdown Parameter spec
gabrieldutra 227d3fd
Merge branch 'master' into cypress-parameter-spec
gabrieldutra 6622b8d
Remove .only
gabrieldutra 20218ac
Add Date and Time Parameter
gabrieldutra 136895a
Use requests to create queries
gabrieldutra 70af934
Remove unnecessary data-test
gabrieldutra 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 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 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 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 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,202 @@ | ||
import { createQuery } from '../../support/redash-api'; | ||
|
||
describe('Parameter', () => { | ||
beforeEach(() => { | ||
cy.login(); | ||
}); | ||
|
||
describe('Text Parameter', () => { | ||
beforeEach(() => { | ||
const queryData = { | ||
name: 'Text Parameter', | ||
query: "SELECT '{{test-parameter}}' AS parameter", | ||
}; | ||
|
||
createQuery(queryData, false) | ||
.then(({ id }) => cy.visit(`/queries/${id}`)); | ||
}); | ||
|
||
it('updates the results after clicking in Apply or pressing enter', () => { | ||
cy.getByTestId('ParameterName-test-parameter') | ||
.find('input') | ||
.type('Redash'); | ||
|
||
cy.getByTestId('ParameterName-test-parameter') | ||
.contains('Apply') | ||
.click(); | ||
|
||
cy.getByTestId('DynamicTable') | ||
.should('contain', 'Redash'); | ||
|
||
cy.getByTestId('ParameterName-test-parameter') | ||
.find('input') | ||
.type('{selectall}New value{enter}'); | ||
|
||
cy.getByTestId('DynamicTable') | ||
.should('contain', 'New value'); | ||
}); | ||
}); | ||
|
||
describe('Number Parameter', () => { | ||
beforeEach(() => { | ||
const queryData = { | ||
name: 'Number Parameter', | ||
query: "SELECT '{{test-parameter}}' AS parameter", | ||
options: { | ||
parameters: [ | ||
{ name: 'test-parameter', title: 'Test Parameter', type: 'number' }, | ||
], | ||
}, | ||
}; | ||
|
||
createQuery(queryData, false) | ||
.then(({ id }) => cy.visit(`/queries/${id}`)); | ||
}); | ||
|
||
it('updates the results after clicking in Apply or pressing enter', () => { | ||
cy.getByTestId('ParameterName-test-parameter') | ||
.find('input') | ||
.type('{selectall}42'); | ||
|
||
cy.getByTestId('ParameterName-test-parameter') | ||
.contains('Apply') | ||
.click(); | ||
|
||
cy.getByTestId('DynamicTable') | ||
.should('contain', 42); | ||
|
||
cy.getByTestId('ParameterName-test-parameter') | ||
.find('input') | ||
.type('{selectall}31415{enter}'); | ||
|
||
cy.getByTestId('DynamicTable') | ||
.should('contain', 31415); | ||
}); | ||
}); | ||
|
||
describe('Dropdown Parameter', () => { | ||
beforeEach(() => { | ||
const queryData = { | ||
name: 'Number Parameter', | ||
query: "SELECT '{{test-parameter}}' AS parameter", | ||
options: { | ||
parameters: [ | ||
{ name: 'test-parameter', | ||
title: 'Test Parameter', | ||
type: 'enum', | ||
enumOptions: 'value1\nvalue2\nvalue3' }, | ||
], | ||
}, | ||
}; | ||
|
||
createQuery(queryData, false) | ||
.then(({ id }) => cy.visit(`/queries/${id}`)); | ||
}); | ||
|
||
it('updates the results after selecting a value', () => { | ||
cy.getByTestId('ParameterName-test-parameter') | ||
.find('.ant-select') | ||
.click(); | ||
|
||
cy.contains('li.ant-select-dropdown-menu-item', 'value1') | ||
.click(); | ||
|
||
cy.getByTestId('DynamicTable') | ||
.should('contain', 'value1'); | ||
}); | ||
}); | ||
|
||
describe('Date Parameter', () => { | ||
beforeEach(() => { | ||
const queryData = { | ||
name: 'Date Parameter', | ||
query: "SELECT '{{test-parameter}}' AS parameter", | ||
}; | ||
|
||
createQuery(queryData, false) | ||
.then(({ id }) => cy.visit(`/queries/${id}/source`)); | ||
|
||
cy.clickThrough(` | ||
ParameterSettings-test-parameter | ||
ParameterTypeSelect | ||
DateParameterTypeOption | ||
SaveParameterSettings | ||
`); | ||
|
||
const now = new Date(2019, 0, 1).getTime(); // January 1, 2019 timestamp | ||
cy.clock(now); | ||
}); | ||
|
||
afterEach(() => { | ||
cy.clock().then(clock => clock.restore()); | ||
}); | ||
|
||
it('updates the results after selecting a date', () => { | ||
cy.getByTestId('ParameterName-test-parameter') | ||
.find('input') | ||
.click(); | ||
|
||
cy.get('.ant-calendar-date-panel') | ||
.contains('.ant-calendar-date', '15') | ||
.click(); | ||
|
||
cy.getByTestId('DynamicTable') | ||
.should('contain', '15/01/19'); | ||
}); | ||
}); | ||
|
||
describe('Date and Time Parameter', () => { | ||
beforeEach(() => { | ||
const queryData = { | ||
name: 'Date and Time Parameter', | ||
query: "SELECT '{{test-parameter}}' AS parameter", | ||
}; | ||
|
||
createQuery(queryData, false) | ||
.then(({ id }) => cy.visit(`/queries/${id}/source`)); | ||
|
||
cy.clickThrough(` | ||
ParameterSettings-test-parameter | ||
ParameterTypeSelect | ||
DateTimeParameterTypeOption | ||
SaveParameterSettings | ||
`); | ||
|
||
const now = new Date(2019, 0, 1).getTime(); // January 1, 2019 timestamp | ||
cy.clock(now); | ||
}); | ||
|
||
afterEach(() => { | ||
cy.clock().then(clock => clock.restore()); | ||
}); | ||
|
||
it('updates the results after selecting a date and clicking in ok', () => { | ||
cy.getByTestId('ParameterName-test-parameter') | ||
.find('input') | ||
.click(); | ||
|
||
cy.get('.ant-calendar-date-panel') | ||
.contains('.ant-calendar-date', '15') | ||
.click(); | ||
|
||
cy.get('.ant-calendar-ok-btn') | ||
.click(); | ||
|
||
cy.getByTestId('DynamicTable') | ||
.should('contain', '2019-01-15 00:00'); | ||
}); | ||
|
||
it('shows the current datetime after clicking in Now', () => { | ||
cy.getByTestId('ParameterName-test-parameter') | ||
.find('input') | ||
.click(); | ||
|
||
cy.get('.ant-calendar-date-panel') | ||
.contains('Now') | ||
.click(); | ||
|
||
cy.getByTestId('DynamicTable') | ||
.should('contain', '2019-01-01 00:00'); | ||
}); | ||
}); | ||
}); |
This file contains 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 |
---|---|---|
|
@@ -19,11 +19,11 @@ export function createQuery(data, shouldPublish = true) { | |
}, data); | ||
|
||
// eslint-disable-next-line cypress/no-assigning-return-values | ||
let request = cy.request('POST', '/api/queries', merged); | ||
let request = cy.request('POST', '/api/queries', merged).then(({ body }) => body); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. To be consistent with the |
||
if (shouldPublish) { | ||
request = request.then(({ body }) => ( | ||
cy.request('POST', `/api/queries/${body.id}`, { is_draft: false }) | ||
.then(() => body) | ||
request = request.then(query => ( | ||
cy.request('POST', `/api/queries/${query.id}`, { is_draft: false }) | ||
.then(() => query) | ||
)); | ||
} | ||
|
||
|
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You sure this is needed? Can leave new query unsaved.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's either save the query or this workaround 😬
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh right right!