2019-07-29 21:41:32 +00:00
|
|
|
import {Organization, Bucket} from '../../src/types'
|
2019-07-18 20:37:14 +00:00
|
|
|
import _ from 'lodash'
|
2019-02-21 23:20:32 +00:00
|
|
|
|
2019-02-22 01:38:11 +00:00
|
|
|
describe('Tasks', () => {
|
2019-02-19 23:47:19 +00:00
|
|
|
beforeEach(() => {
|
|
|
|
cy.flush()
|
|
|
|
|
2019-02-26 22:05:53 +00:00
|
|
|
cy.signin().then(({body}) => {
|
2019-02-21 23:20:32 +00:00
|
|
|
cy.wrap(body.org).as('org')
|
2019-03-05 21:32:04 +00:00
|
|
|
cy.wrap(body.bucket).as('bucket')
|
2019-07-18 20:37:14 +00:00
|
|
|
|
|
|
|
cy.createToken(body.org.id, 'test token', 'active', [
|
|
|
|
{action: 'write', resource: {type: 'views'}},
|
|
|
|
{action: 'write', resource: {type: 'documents'}},
|
|
|
|
{action: 'write', resource: {type: 'tasks'}},
|
|
|
|
]).then(({body}) => {
|
|
|
|
cy.wrap(body.token).as('token')
|
|
|
|
})
|
2019-02-19 23:47:19 +00:00
|
|
|
})
|
|
|
|
|
2019-04-01 19:08:42 +00:00
|
|
|
cy.fixture('routes').then(({orgs}) => {
|
|
|
|
cy.get<Organization>('@org').then(({id}) => {
|
|
|
|
cy.visit(`${orgs}/${id}/tasks`)
|
|
|
|
})
|
|
|
|
})
|
2019-02-19 23:47:19 +00:00
|
|
|
})
|
|
|
|
|
2019-07-31 09:46:28 +00:00
|
|
|
it('cannot create a task with an invalid to() function', () => {
|
|
|
|
const taskName = 'Bad Task'
|
|
|
|
|
|
|
|
createFirstTask(taskName, ({name}) => {
|
|
|
|
return `import "influxdata/influxdb/v1"
|
|
|
|
v1.tagValues(bucket: "${name}", tag: "_field")
|
|
|
|
from(bucket: "${name}")
|
|
|
|
|> range(start: -2m)
|
2019-08-23 16:32:10 +00:00
|
|
|
|> to(org: "${name}")`
|
2019-02-19 23:47:19 +00:00
|
|
|
})
|
|
|
|
|
2019-07-31 09:46:28 +00:00
|
|
|
cy.contains('Save').click()
|
2019-03-15 23:34:18 +00:00
|
|
|
|
2019-07-31 09:46:28 +00:00
|
|
|
cy.getByTestID('notification-error').should(
|
|
|
|
'contain',
|
2019-08-23 16:32:10 +00:00
|
|
|
'error calling function "to": missing required keyword argument "bucketID"'
|
2019-07-31 09:46:28 +00:00
|
|
|
)
|
|
|
|
})
|
2019-02-21 22:52:19 +00:00
|
|
|
|
2019-07-31 09:46:28 +00:00
|
|
|
it('can create a task', () => {
|
|
|
|
const taskName = 'Task'
|
|
|
|
createFirstTask(taskName, ({name}) => {
|
|
|
|
return `import "influxdata/influxdb/v1"
|
|
|
|
v1.tagValues(bucket: "${name}", tag: "_field")
|
|
|
|
from(bucket: "${name}")
|
|
|
|
|> range(start: -2m)`
|
|
|
|
})
|
2019-02-21 22:52:19 +00:00
|
|
|
|
2019-07-31 09:46:28 +00:00
|
|
|
cy.contains('Save').click()
|
2019-02-21 22:52:19 +00:00
|
|
|
|
2019-07-31 09:46:28 +00:00
|
|
|
cy.getByTestID('task-card')
|
|
|
|
.should('have.length', 1)
|
|
|
|
.and('contain', taskName)
|
2019-02-21 22:52:19 +00:00
|
|
|
})
|
|
|
|
|
2019-03-07 00:35:30 +00:00
|
|
|
it('can delete a task', () => {
|
2019-02-21 23:20:32 +00:00
|
|
|
cy.get<Organization>('@org').then(({id}) => {
|
2019-07-18 20:37:14 +00:00
|
|
|
cy.get<string>('@token').then(token => {
|
|
|
|
cy.createTask(token, id)
|
|
|
|
cy.createTask(token, id)
|
|
|
|
})
|
2019-03-01 22:14:31 +00:00
|
|
|
|
2019-04-01 19:08:42 +00:00
|
|
|
cy.fixture('routes').then(({orgs}) => {
|
|
|
|
cy.visit(`${orgs}/${id}/tasks`)
|
|
|
|
})
|
2019-02-21 23:20:32 +00:00
|
|
|
|
2019-03-07 00:35:30 +00:00
|
|
|
cy.getByTestID('task-card').should('have.length', 2)
|
2019-03-01 03:04:33 +00:00
|
|
|
|
2019-03-07 00:35:30 +00:00
|
|
|
cy.getByTestID('task-card')
|
|
|
|
.first()
|
|
|
|
.trigger('mouseover')
|
|
|
|
.within(() => {
|
|
|
|
cy.getByTestID('context-delete-menu').click()
|
|
|
|
cy.getByTestID('context-delete-task').click()
|
|
|
|
})
|
|
|
|
|
|
|
|
cy.getByTestID('task-card').should('have.length', 1)
|
|
|
|
})
|
2019-03-01 22:14:31 +00:00
|
|
|
})
|
|
|
|
|
|
|
|
it('can disable a task', () => {
|
|
|
|
cy.get<Organization>('@org').then(({id}) => {
|
2019-07-18 20:37:14 +00:00
|
|
|
cy.get<string>('@token').then(token => {
|
|
|
|
cy.createTask(token, id)
|
|
|
|
})
|
2019-03-01 22:14:31 +00:00
|
|
|
})
|
|
|
|
|
|
|
|
cy.getByTestID('task-card--slide-toggle').should('have.class', 'active')
|
|
|
|
|
|
|
|
cy.getByTestID('task-card--slide-toggle').click()
|
|
|
|
|
|
|
|
cy.getByTestID('task-card--slide-toggle').should('not.have.class', 'active')
|
|
|
|
})
|
|
|
|
|
|
|
|
it('can edit a tasks name', () => {
|
|
|
|
cy.get<Organization>('@org').then(({id}) => {
|
2019-07-18 20:37:14 +00:00
|
|
|
cy.get<string>('@token').then(token => {
|
|
|
|
cy.createTask(token, id)
|
|
|
|
})
|
2019-03-01 22:14:31 +00:00
|
|
|
})
|
|
|
|
|
2019-05-16 23:06:08 +00:00
|
|
|
const newName = 'Task'
|
2019-03-01 22:14:31 +00:00
|
|
|
|
|
|
|
cy.getByTestID('task-card').within(() => {
|
|
|
|
cy.getByTestID('task-card--name').trigger('mouseover')
|
|
|
|
|
|
|
|
cy.getByTestID('task-card--name-button').click()
|
|
|
|
|
2019-07-25 19:13:51 +00:00
|
|
|
cy.get('.cf-input-field')
|
2019-03-01 22:14:31 +00:00
|
|
|
.type(newName)
|
|
|
|
.type('{enter}')
|
|
|
|
})
|
|
|
|
|
2019-04-01 19:08:42 +00:00
|
|
|
cy.fixture('routes').then(({orgs}) => {
|
|
|
|
cy.get<Organization>('@org').then(({id}) => {
|
|
|
|
cy.visit(`${orgs}/${id}/tasks`)
|
|
|
|
})
|
|
|
|
})
|
2019-03-01 22:14:31 +00:00
|
|
|
|
|
|
|
cy.getByTestID('task-card').should('contain', newName)
|
2019-02-21 23:20:32 +00:00
|
|
|
})
|
|
|
|
|
2019-04-04 18:05:39 +00:00
|
|
|
it('fails to create a task without a valid script', () => {
|
2019-07-31 09:46:28 +00:00
|
|
|
createFirstTask('Task', () => '{}')
|
2019-02-19 23:47:19 +00:00
|
|
|
|
|
|
|
cy.contains('Save').click()
|
2019-02-21 22:52:19 +00:00
|
|
|
|
2019-02-26 01:41:18 +00:00
|
|
|
cy.getByTestID('notification-error').should('exist')
|
2019-02-19 23:47:19 +00:00
|
|
|
})
|
2019-02-27 19:21:21 +00:00
|
|
|
|
|
|
|
describe('labeling', () => {
|
2019-02-27 22:17:15 +00:00
|
|
|
it('can click to filter tasks by labels', () => {
|
2019-02-27 19:21:21 +00:00
|
|
|
const newLabelName = 'click-me'
|
|
|
|
|
|
|
|
cy.get<Organization>('@org').then(({id}) => {
|
2019-07-18 20:37:14 +00:00
|
|
|
cy.get<string>('@token').then(token => {
|
|
|
|
cy.createTask(token, id).then(({body}) => {
|
|
|
|
cy.createAndAddLabel('tasks', id, body.id, newLabelName)
|
|
|
|
})
|
|
|
|
|
|
|
|
cy.createTask(token, id).then(({body}) => {
|
|
|
|
cy.createAndAddLabel('tasks', id, body.id, 'bar')
|
|
|
|
})
|
2019-02-27 19:21:21 +00:00
|
|
|
})
|
|
|
|
})
|
|
|
|
|
2019-04-01 19:08:42 +00:00
|
|
|
cy.fixture('routes').then(({orgs}) => {
|
|
|
|
cy.get<Organization>('@org').then(({id}) => {
|
|
|
|
cy.visit(`${orgs}/${id}/tasks`)
|
|
|
|
})
|
|
|
|
})
|
2019-02-27 19:21:21 +00:00
|
|
|
|
2019-03-01 22:14:31 +00:00
|
|
|
cy.getByTestID('task-card').should('have.length', 2)
|
2019-02-27 19:21:21 +00:00
|
|
|
|
|
|
|
cy.getByTestID(`label--pill ${newLabelName}`).click()
|
|
|
|
|
2019-03-01 22:14:31 +00:00
|
|
|
cy.getByTestID('task-card').should('have.length', 1)
|
2019-02-27 19:21:21 +00:00
|
|
|
})
|
|
|
|
})
|
|
|
|
|
|
|
|
describe('searching', () => {
|
|
|
|
it('can search by task name', () => {
|
|
|
|
const searchName = 'beepBoop'
|
|
|
|
cy.get<Organization>('@org').then(({id}) => {
|
2019-07-18 20:37:14 +00:00
|
|
|
cy.get<string>('@token').then(token => {
|
|
|
|
cy.createTask(token, id, searchName)
|
|
|
|
cy.createTask(token, id)
|
|
|
|
})
|
2019-02-27 19:21:21 +00:00
|
|
|
})
|
|
|
|
|
2019-04-01 19:08:42 +00:00
|
|
|
cy.fixture('routes').then(({orgs}) => {
|
|
|
|
cy.get<Organization>('@org').then(({id}) => {
|
|
|
|
cy.visit(`${orgs}/${id}/tasks`)
|
|
|
|
})
|
|
|
|
})
|
2019-02-27 19:21:21 +00:00
|
|
|
|
|
|
|
cy.getByTestID('search-widget').type('bEE')
|
|
|
|
|
2019-03-01 22:14:31 +00:00
|
|
|
cy.getByTestID('task-card').should('have.length', 1)
|
2019-02-27 19:21:21 +00:00
|
|
|
})
|
|
|
|
})
|
2019-02-19 23:47:19 +00:00
|
|
|
})
|
2019-07-31 09:46:28 +00:00
|
|
|
|
|
|
|
function createFirstTask(name: string, flux: (bucket: Bucket) => string) {
|
|
|
|
cy.getByTestID('empty-tasks-list').within(() => {
|
|
|
|
cy.getByTestID('add-resource-dropdown--button').click()
|
|
|
|
})
|
|
|
|
|
|
|
|
cy.getByTestID('add-resource-dropdown--new').click()
|
|
|
|
|
|
|
|
cy.getByInputName('name').type(name)
|
|
|
|
cy.getByInputName('interval').type('24h')
|
|
|
|
cy.getByInputName('offset').type('20m')
|
|
|
|
|
|
|
|
cy.get<Bucket>('@bucket').then(bucket => {
|
|
|
|
cy.getByTestID('flux-editor').within(() => {
|
|
|
|
cy.get('textarea').type(flux(bucket), {force: true})
|
|
|
|
})
|
|
|
|
})
|
|
|
|
}
|