Merge branch 'master' into e2e/chronograf_admin_all_users
commit
b77318ce45
|
@ -27,7 +27,8 @@ import {
|
|||
deleteInfluxDBs,
|
||||
toInitialState,
|
||||
writePoints,
|
||||
clickAttached
|
||||
clickAttached,
|
||||
changeUserInfo,
|
||||
} from './support/commands'
|
||||
|
||||
declare global {
|
||||
|
@ -60,6 +61,7 @@ declare global {
|
|||
toInitialState: typeof toInitialState
|
||||
writePoints: typeof writePoints
|
||||
clickAttached: typeof clickAttached
|
||||
changeUserInfo: typeof changeUserInfo
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,3 +1,5 @@
|
|||
import {Source} from '../support/types'
|
||||
|
||||
/*
|
||||
In these tests you will find a realHover function.
|
||||
realHover is used whenever there is a need to fire a hover event, which will make certain elements visible.
|
||||
|
@ -6,7 +8,7 @@
|
|||
describe('Chronograf', () => {
|
||||
let chronograf: any
|
||||
let url: string
|
||||
let sourceId: string
|
||||
let source: Source
|
||||
|
||||
before(() => {
|
||||
cy.fixture('chronograf').then(chronografData => {
|
||||
|
@ -16,10 +18,9 @@ describe('Chronograf', () => {
|
|||
|
||||
beforeEach(() => {
|
||||
cy.toInitialState()
|
||||
cy.createInfluxDBConnection()
|
||||
cy.get('@connections').then(sources => {
|
||||
sourceId = sources[0].id
|
||||
url = `/sources/${sourceId}/admin-chronograf`
|
||||
cy.createInfluxDBConnection().then((src: Source) => {
|
||||
source = src
|
||||
url = `/sources/${source.id}/admin-chronograf`
|
||||
})
|
||||
})
|
||||
|
||||
|
|
|
@ -1,7 +1,10 @@
|
|||
import {Source} from '../support/types'
|
||||
|
||||
|
||||
describe('InfluxDB', () => {
|
||||
let influxDB: any
|
||||
let url: string
|
||||
let sourceId: string
|
||||
let source: Source
|
||||
|
||||
before(() => {
|
||||
cy.fixture('influxDB').then(influxDBData => {
|
||||
|
@ -11,10 +14,9 @@ describe('InfluxDB', () => {
|
|||
|
||||
beforeEach(() => {
|
||||
cy.toInitialState()
|
||||
cy.createInfluxDBConnection()
|
||||
cy.get('@connections').then(sources => {
|
||||
sourceId = sources[0].id
|
||||
url = `/sources/${sourceId}/admin-influxdb`
|
||||
cy.createInfluxDBConnection().then((src: Source) => {
|
||||
source = src
|
||||
url = `/sources/${source.id}/admin-influxdb`
|
||||
})
|
||||
})
|
||||
|
||||
|
@ -79,8 +81,8 @@ describe('InfluxDB', () => {
|
|||
|
||||
describe('Users', () => {
|
||||
beforeEach(() => {
|
||||
cy.createInfluxDB(influxDB.db.name, sourceId)
|
||||
cy.createInfluxDBRole(influxDB.role.name, sourceId)
|
||||
cy.createInfluxDB(influxDB.db.name, source.id)
|
||||
cy.createInfluxDBRole(influxDB.role.name, source.id)
|
||||
cy.visit(url + '/users')
|
||||
})
|
||||
|
||||
|
@ -229,11 +231,11 @@ describe('InfluxDB', () => {
|
|||
|
||||
describe('Roles', () => {
|
||||
beforeEach(() => {
|
||||
cy.createInfluxDB(influxDB.db.name, sourceId)
|
||||
cy.createInfluxDB(influxDB.db.name, source.id)
|
||||
cy.createInfluxDBUser(
|
||||
influxDB.user.name,
|
||||
influxDB.user.password,
|
||||
sourceId
|
||||
source.id
|
||||
)
|
||||
cy.visit(url + '/roles')
|
||||
})
|
||||
|
@ -275,7 +277,7 @@ describe('InfluxDB', () => {
|
|||
})
|
||||
|
||||
cy.getByTestID('apply-changes--button').click({force: true})
|
||||
cy.url().should('match',new RegExp(`roles$`))
|
||||
cy.url().should('match', new RegExp(`roles$`))
|
||||
cy.getByTestID(`role-${influxDB.role.name}--row`).within(() => {
|
||||
cy.get('a').contains(influxDB.role.name).click({force: true})
|
||||
})
|
||||
|
@ -290,7 +292,7 @@ describe('InfluxDB', () => {
|
|||
})
|
||||
|
||||
cy.get('.subsection--tab.active').click({force: true})
|
||||
cy.url().should('match',new RegExp(`roles$`))
|
||||
cy.url().should('match', new RegExp(`roles$`))
|
||||
cy.getByTestID('wizard-bucket-selected').click({force: true})
|
||||
cy.getByTestID('dropdown-menu').within(() => {
|
||||
cy.getByTestID('dropdown--item')
|
||||
|
|
|
@ -1,12 +1,16 @@
|
|||
import {Source} from '../support/types'
|
||||
|
||||
describe('Use Dashboards', () => {
|
||||
let source: Source
|
||||
|
||||
beforeEach(() => {
|
||||
cy.toInitialState()
|
||||
cy.createInfluxDBConnection()
|
||||
cy.visit('/login')
|
||||
cy.get('@connections').then(connections => {
|
||||
cy.visit(`/sources/${connections[0].id}/dashboards`)
|
||||
})
|
||||
cy.createDashboard('Reader Dashboard')
|
||||
.then((src: Source) => {
|
||||
source = src
|
||||
cy.visit(`/sources/${source.id}/dashboards`)
|
||||
cy.createDashboard('Reader Dashboard')
|
||||
})
|
||||
})
|
||||
|
||||
it('create, rename and delete a dashboard', () => {
|
||||
|
@ -22,9 +26,7 @@ describe('Use Dashboards', () => {
|
|||
.should('have.text', newName)
|
||||
|
||||
// delete the dashboard
|
||||
cy.get('@connections').then(connections => {
|
||||
cy.visit(`/sources/${connections[0].id}/dashboards`)
|
||||
})
|
||||
cy.visit(`/sources/${source.id}/dashboards`)
|
||||
|
||||
// DOM Element where the dashboard resides
|
||||
cy.get('.panel-body > table > tbody')
|
||||
|
@ -37,11 +39,13 @@ describe('Use Dashboards', () => {
|
|||
|
||||
describe('Use Dashboards as reader', () => {
|
||||
beforeEach(() => {
|
||||
cy.createChronografUser('Reader', 'oauth-mock', 'oauth2')
|
||||
cy.OAuthLoginAsDiffUser('Reader')
|
||||
cy.get('@connections').then(connections => {
|
||||
cy.visit(`/sources/${connections[0].id}/dashboards`)
|
||||
})
|
||||
cy.getByTestID('sidebar')
|
||||
.should('be.visible')
|
||||
.then(() => {
|
||||
cy.createChronografUser('Reader', 'oauth-mock', 'oauth2').then(() => {
|
||||
cy.OAuthLoginAsDiffUser('Reader')
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
it('ensure that all elements used to edit Chronograf are not visible', () => {
|
||||
|
@ -61,7 +65,7 @@ describe('Use Dashboards', () => {
|
|||
|
||||
cy.get('.dashboard-empty--menu').should('not.exist')
|
||||
cy.getByTestID('add-cell').should('not.exist')
|
||||
cy.getByTestID('show-variables--button').click()
|
||||
cy.getByTestID('show-variables--button').should('be.visible').click()
|
||||
cy.getByTestID('add-template-variable').should('not.exist')
|
||||
cy.getByTestID('show-annotations--button').click()
|
||||
cy.getByTestID('add-annotation--button').should('not.exist')
|
||||
|
|
|
@ -1,17 +1,21 @@
|
|||
import {Source} from '../support/types'
|
||||
|
||||
describe('query builder', () => {
|
||||
let influxDB: any
|
||||
let source: Source
|
||||
|
||||
beforeEach(() => {
|
||||
cy.toInitialState()
|
||||
cy.createInfluxDBConnection()
|
||||
cy.createDashboard()
|
||||
cy.get('@connections').then((sources: any) => {
|
||||
|
||||
cy.createInfluxDBConnection().then((src: Source) => {
|
||||
cy.createDashboard()
|
||||
cy.fixture('influxDB.json').then((influxDBData: any) => {
|
||||
influxDB = influxDBData
|
||||
source = src
|
||||
|
||||
cy.createInfluxDB(influxDB.db.name, sources[0].id)
|
||||
cy.createInfluxDB(influxDB.db.name, source.id)
|
||||
cy.writePoints(
|
||||
sources[0].id,
|
||||
source.id,
|
||||
influxDB.db.name,
|
||||
influxDB.db.measurements[0].name,
|
||||
influxDB.db.measurements[0].tagValues[0],
|
||||
|
@ -19,29 +23,26 @@ describe('query builder', () => {
|
|||
)
|
||||
|
||||
cy.writePoints(
|
||||
sources[0].id,
|
||||
source.id,
|
||||
influxDB.db.name,
|
||||
influxDB.db.measurements[1].name,
|
||||
influxDB.db.measurements[1].tagValues[1],
|
||||
influxDB.db.measurements[1].fieldValues[0]
|
||||
)
|
||||
})
|
||||
|
||||
cy.get('@dashboards').then((dashboards: any) => {
|
||||
cy.visit(`/sources/${sources[0].id}/dashboards/${dashboards[0].id}`)
|
||||
cy.get('@dashboards').then((dashboards: any) => {
|
||||
cy.visit(`/sources/${source.id}/dashboards/${dashboards[0].id}`)
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
cy.get('#Line').click()
|
||||
cy.get('.dash-graph').contains('Add Data').click()
|
||||
cy.get('.source-selector').within(() => {
|
||||
cy.get('@connections').then((sources: any) => {
|
||||
cy.get('.dropdown--selected').should('have.text', 'Dynamic Source')
|
||||
cy.get('.dropdown--button').click()
|
||||
cy.get('.dropdown--menu').contains(sources[0].name).click()
|
||||
cy.get('.dropdown--selected').should('have.text', sources[0].name)
|
||||
})
|
||||
|
||||
cy.get('.dropdown--selected').should('have.text', 'Dynamic Source')
|
||||
cy.get('.dropdown--button').click()
|
||||
cy.get('.dropdown--menu').contains(source.name).click()
|
||||
cy.get('.dropdown--selected').should('have.text', source.name)
|
||||
cy.get('button').contains('Flux').click().should('have.class', 'active')
|
||||
})
|
||||
|
||||
|
@ -106,8 +107,7 @@ describe('query builder', () => {
|
|||
cy.getByTestID('builder-card--body').within(() => {
|
||||
cy.get('.dropdown-selected').click()
|
||||
cy.get('.dropdown-menu').within(() => {
|
||||
cy.getByTestID('custom-dropdown-item')
|
||||
.click()
|
||||
cy.getByTestID('custom-dropdown-item').click()
|
||||
})
|
||||
cy.get('input').type('13s{enter}')
|
||||
cy.get('.dropdown-selected').should('contain.text', '13s')
|
||||
|
|
|
@ -1,4 +1,3 @@
|
|||
|
||||
const apiUrl = '/chronograf/v1'
|
||||
|
||||
export const getByTestID = (
|
||||
|
@ -10,8 +9,10 @@ export const getByTestID = (
|
|||
return cy.get(`[data-test="${dataTest}"]`, options)
|
||||
}
|
||||
|
||||
function changeUserInfo(name: string) {
|
||||
cy.request({
|
||||
export const changeUserInfo = (
|
||||
name: string
|
||||
): Cypress.Chainable<Cypress.Response<any>> => {
|
||||
return cy.request({
|
||||
method: 'POST',
|
||||
url: Cypress.env('oauth2ServerURL') + '/config',
|
||||
body: {
|
||||
|
@ -49,8 +50,17 @@ export const writePoints = (
|
|||
}
|
||||
|
||||
export const OAuthLogin = (name: string) => {
|
||||
changeUserInfo(name)
|
||||
return cy.visit('/oauth/oauth-mock/login')
|
||||
return cy.changeUserInfo(name).then(response => {
|
||||
return cy
|
||||
.log(
|
||||
`OAuth change config - status ${response.status}, ${response.statusText}`
|
||||
)
|
||||
.then(() => {
|
||||
expect(response.status).to.be.equal(200)
|
||||
cy.log('visit login page')
|
||||
return cy.visit('/oauth/oauth-mock/login')
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
export const OAuthLogout = () => {
|
||||
|
@ -58,8 +68,16 @@ export const OAuthLogout = () => {
|
|||
}
|
||||
|
||||
export const OAuthLoginAsDiffUser = (name: string) => {
|
||||
changeUserInfo(name)
|
||||
return cy.visit('/oauth/oauth-mock/logout')
|
||||
return cy.changeUserInfo(name).then(response => {
|
||||
return cy
|
||||
.log(
|
||||
`OAuth change config - status ${response.status}, ${response.statusText}`
|
||||
)
|
||||
.then(() => {
|
||||
expect(response.status).to.be.equal(200)
|
||||
return cy.visit('/oauth/oauth-mock/logout')
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -79,7 +97,7 @@ export const createInfluxDBConnection = (
|
|||
connectionName?: string,
|
||||
isUnsafeSSL?: boolean,
|
||||
metaUrl?: string
|
||||
) => {
|
||||
): Cypress.Chainable => {
|
||||
return cy
|
||||
.request({
|
||||
method: 'POST',
|
||||
|
@ -93,8 +111,8 @@ export const createInfluxDBConnection = (
|
|||
metaUrl: metaUrl ?? Cypress.env('metaUrl'),
|
||||
},
|
||||
})
|
||||
.then(() => {
|
||||
wrapConnections()
|
||||
.then(({body}) => {
|
||||
return body
|
||||
})
|
||||
}
|
||||
|
||||
|
@ -104,8 +122,8 @@ export const createInfluxDBConnection = (
|
|||
export const removeInfluxDBConnections = () => {
|
||||
return cy
|
||||
.request('GET', `${apiUrl}/sources`)
|
||||
.then(response => {
|
||||
response.body.sources.forEach((source: any) => {
|
||||
.then(({body: responseBody}) => {
|
||||
cy.wrap(responseBody.sources).each((source: any) => {
|
||||
cy.request('DELETE', `${source.links.self}`)
|
||||
})
|
||||
})
|
||||
|
@ -139,7 +157,7 @@ export const deleteDashboards = () => {
|
|||
return cy
|
||||
.request('GET', `${apiUrl}/dashboards`)
|
||||
.then(({body: responseBody}) => {
|
||||
responseBody.dashboards.forEach((dashboard: any) => {
|
||||
cy.wrap(responseBody.dashboards).each((dashboard: any) => {
|
||||
cy.request('DELETE', dashboard.links.self)
|
||||
})
|
||||
})
|
||||
|
@ -211,7 +229,7 @@ export const createChronografUser = (
|
|||
scheme: string,
|
||||
organization?: string,
|
||||
role?: string
|
||||
) => {
|
||||
): Cypress.Chainable<Cypress.Response<any>> => {
|
||||
return cy
|
||||
.request({
|
||||
method: 'POST',
|
||||
|
@ -228,7 +246,10 @@ export const createChronografUser = (
|
|||
scheme: scheme,
|
||||
},
|
||||
})
|
||||
.then(() => {
|
||||
.then((response: Cypress.Response<any>) => {
|
||||
cy.log(
|
||||
`Chronograf new user - status ${response.status}, ${response.statusText}`
|
||||
)
|
||||
wrapChronografUsers()
|
||||
})
|
||||
}
|
||||
|
@ -242,8 +263,8 @@ export const deleteChronografUser = (name: string) => {
|
|||
return cy
|
||||
.request('GET', `${apiUrl}/users`)
|
||||
.then(({body: responseBody}) => {
|
||||
responseBody.users.forEach((user: any) => {
|
||||
if (userName == user.name) {
|
||||
cy.wrap(responseBody.users).each((user: any) => {
|
||||
if (userName === user.name) {
|
||||
cy.request('DELETE', user.links.self)
|
||||
}
|
||||
})
|
||||
|
@ -263,8 +284,10 @@ export const deleteChronografUsers = () => {
|
|||
url: `${apiUrl}/users`,
|
||||
})
|
||||
.then(({body: responseBody}) => {
|
||||
responseBody.users.slice(1).forEach((user: any) => {
|
||||
cy.request('DELETE', user.links.self)
|
||||
cy.wrap(responseBody.users).each((user: any) => {
|
||||
if (user.name !== 'test@oauth2.mock') {
|
||||
cy.request('DELETE', user.links.self)
|
||||
}
|
||||
})
|
||||
})
|
||||
.then(() => {
|
||||
|
@ -309,8 +332,10 @@ export const deleteOrgs = () => {
|
|||
return cy
|
||||
.request('GET', `${apiUrl}/organizations`)
|
||||
.then(({body: responseBody}) => {
|
||||
responseBody.organizations.slice(1).forEach((organization: any) => {
|
||||
cy.request('DELETE', organization.links.self)
|
||||
cy.wrap(responseBody.organizations).each((organization: any) => {
|
||||
if (organization.id !== 'default') {
|
||||
cy.request('DELETE', organization.links.self)
|
||||
}
|
||||
})
|
||||
})
|
||||
.then(() => {
|
||||
|
@ -366,8 +391,8 @@ export const deleteInfluxDBUsers = (sourceId: string) => {
|
|||
return cy
|
||||
.request('GET', `${apiUrl}/sources/${sourceId}/users`)
|
||||
.then(({body: responseBody}) => {
|
||||
responseBody.users.forEach((user: any) => {
|
||||
if (user.name != Cypress.env('username')) {
|
||||
cy.wrap(responseBody.users).each((user: any) => {
|
||||
if (user.name !== Cypress.env('username')) {
|
||||
cy.request('DELETE', user.links.self)
|
||||
}
|
||||
})
|
||||
|
@ -415,13 +440,13 @@ export const deleteInfluxDBRole = (name: string, sourceId: string) => {
|
|||
* @param sourceId - Source ID.
|
||||
*/
|
||||
export const deleteInfluxDBRoles = (sourceId: string) => {
|
||||
return cy
|
||||
.request('GET', `${apiUrl}/sources/${sourceId}/roles`)
|
||||
.then(({body: responseBody}) => {
|
||||
responseBody.roles.forEach((role: any) => {
|
||||
cy.request('GET', `${apiUrl}/sources/${sourceId}/roles`).then(
|
||||
({body: responseBody}) => {
|
||||
cy.wrap(responseBody.roles).each((role: any) => {
|
||||
cy.request('DELETE', role.links.self)
|
||||
})
|
||||
})
|
||||
}
|
||||
)
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -456,7 +481,7 @@ export const deleteInfluxDBs = (sourceId: string) => {
|
|||
return cy
|
||||
.request('GET', `${apiUrl}/sources/${sourceId}/dbs`)
|
||||
.then(({body: responseBody}) => {
|
||||
responseBody.databases.forEach((db: any) => {
|
||||
cy.wrap(responseBody.databases).each((db: any) => {
|
||||
cy.request('DELETE', db.links.self)
|
||||
})
|
||||
})
|
||||
|
@ -515,26 +540,33 @@ function wrapChronografUsers() {
|
|||
*/
|
||||
export function toInitialState() {
|
||||
cy.OAuthLogin('test')
|
||||
cy.visit('/')
|
||||
cy.request({
|
||||
method: 'GET',
|
||||
url: `${apiUrl}/sources`,
|
||||
}).then(({body: responseBody}) => {
|
||||
responseBody.sources.forEach((source: any) => {
|
||||
cy.deleteInfluxDBs(source.id)
|
||||
cy.deleteInfluxDBRoles(source.id)
|
||||
cy.deleteInfluxDBUsers(source.id)
|
||||
})
|
||||
})
|
||||
.url()
|
||||
.should('contain', '/sources')
|
||||
.then(() => {
|
||||
cy.get('body')
|
||||
.should('be.visible')
|
||||
.then(() => {
|
||||
cy.request({
|
||||
method: 'GET',
|
||||
url: `${apiUrl}/sources`,
|
||||
}).then(({body: responseBody}) => {
|
||||
responseBody.sources.forEach((source: any) => {
|
||||
cy.deleteInfluxDBs(source.id)
|
||||
cy.deleteInfluxDBRoles(source.id)
|
||||
cy.deleteInfluxDBUsers(source.id)
|
||||
})
|
||||
})
|
||||
|
||||
cy.deleteDashboards()
|
||||
cy.deleteChronografUsers()
|
||||
cy.deleteOrgs()
|
||||
cy.removeInfluxDBConnections()
|
||||
cy.deleteDashboards()
|
||||
cy.deleteChronografUsers()
|
||||
cy.deleteOrgs()
|
||||
cy.removeInfluxDBConnections()
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
export const clickAttached = (subject?: JQuery<HTMLElement>): void => {
|
||||
if(!subject) {
|
||||
if (!subject) {
|
||||
console.error('no element provided to "clickAttached"')
|
||||
return
|
||||
}
|
||||
|
@ -571,4 +603,5 @@ Cypress.Commands.add('deleteInfluxDB', deleteInfluxDB)
|
|||
Cypress.Commands.add('deleteInfluxDBs', deleteInfluxDBs)
|
||||
Cypress.Commands.add('toInitialState', toInitialState)
|
||||
Cypress.Commands.add('writePoints', writePoints)
|
||||
Cypress.Commands.add('clickAttached', {prevSubject: 'element'} ,clickAttached)
|
||||
Cypress.Commands.add('clickAttached', {prevSubject: 'element'}, clickAttached)
|
||||
Cypress.Commands.add('changeUserInfo', changeUserInfo)
|
||||
|
|
|
@ -0,0 +1,4 @@
|
|||
export interface Source {
|
||||
id: string,
|
||||
name: string
|
||||
}
|
Loading…
Reference in New Issue