Add first successful TypeScript test

pull/10616/head
Andrew Watkins 2018-03-03 10:14:40 -07:00
parent 30a0ea216c
commit 80e34cf6d6
7 changed files with 82 additions and 37 deletions

View File

@ -2,7 +2,10 @@ module.exports = {
projects: [
{
displayName: 'test',
testPathIgnorePatterns: ['build', 'node_modules/(?!(jest-test))'],
testPathIgnorePatterns: [
'build',
'<rootDir>/node_modules/(?!(jest-test))',
],
modulePaths: ['<rootDir>', '<rootDir>/node_modules/'],
moduleDirectories: ['src'],
setupFiles: ['<rootDir>/test/setupTests.js'],

View File

@ -34,7 +34,6 @@
"@types/enzyme": "^3.1.9",
"@types/jest": "^22.1.4",
"@types/lodash": "^4.14.104",
"@types/mocha": "^2.2.48",
"@types/node": "^9.4.6",
"@types/prop-types": "^15.5.2",
"@types/react": "^16.0.38",

View File

@ -16,7 +16,7 @@ export interface DatabaseListProps {
query: Query
querySource: Source
onChooseNamespace: (namespace: Namespace) => void
source: Source | null
source: Source
}
export interface DatabaseListState {
@ -30,8 +30,8 @@ export interface DatabaseListContext {
const {shape, string} = PropTypes
class DatabaseList extends Component<DatabaseListProps, DatabaseListState> {
constructor() {
super()
constructor(props) {
super(props)
this.getDbRp = this.getDbRp.bind(this)
}

View File

@ -2,20 +2,27 @@ export interface Source {
id: string
name: string
url: string
links: {
proxy: string
type: string
default: boolean
organization: string
insecureSkipVerify: boolean
role: string
telegraf: string
links: SourceLinks
kapacitors?: Kapacitor[]
metaUrl?: string
}
export interface SourceLinks {
self: string
kapacitors: string
proxy: string
queries: string
write: string
permissions: string
users: string
databases: string
roles: string
}
default: boolean
telegraf?: string
kapacitors?: Kapacitor[]
metaUrl?: string
roles?: string
}
export interface Kapacitor {

49
ui/test/resources.ts Normal file
View File

@ -0,0 +1,49 @@
export const source = {
id: '16',
name: 'ssl',
type: 'influx',
username: 'admin',
url: 'https://localhost:9086',
insecureSkipVerify: true,
default: false,
telegraf: 'telegraf',
organization: '0',
role: 'viewer',
links: {
self: '/chronograf/v1/sources/16',
kapacitors: '/chronograf/v1/sources/16/kapacitors',
proxy: '/chronograf/v1/sources/16/proxy',
queries: '/chronograf/v1/sources/16/queries',
write: '/chronograf/v1/sources/16/write',
permissions: '/chronograf/v1/sources/16/permissions',
users: '/chronograf/v1/sources/16/users',
databases: '/chronograf/v1/sources/16/dbs',
},
}
export const query = {
id: '0',
database: 'db1',
measurement: 'm1',
retentionPolicy: 'r1',
fill: 'null',
fields: [
{
value: 'f1',
type: 'field',
alias: 'foo',
args: [],
},
],
tags: {
tk1: ['tv1', 'tv2'],
},
groupBy: {
time: null,
tags: [],
},
areTagsAccepted: true,
rawText: null,
status: null,
shifts: [],
}

View File

@ -2,31 +2,22 @@ import React from 'react'
import DatabaseList from 'src/shared/components/DatabaseList'
import {shallow} from 'enzyme'
const source = {
links: {
self: '/chronograf/v1/sources/16',
kapacitors: '/chronograf/v1/sources/16/kapacitors',
proxy: '/chronograf/v1/sources/16/proxy',
queries: '/chronograf/v1/sources/16/queries',
write: '/chronograf/v1/sources/16/write',
permissions: '/chronograf/v1/sources/16/permissions',
users: '/chronograf/v1/sources/16/users',
databases: '/chronograf/v1/sources/16/dbs',
},
}
import {query, source} from 'test/resources'
const setup = async (override = {}) => {
const setup = (override = {}) => {
const props = {
query: {},
source: {},
querySource: {},
query,
source,
querySource: source,
onChooseNamespace: () => {},
...override,
}
DatabaseList.prototype.getDbRp = jest.fn(() => Promise.resolve())
const dbList = await shallow(<DatabaseList {...props} />, {context: {source})
const dbList = shallow(<DatabaseList {...props} />, {
context: {source},
})
return {
dbList,

View File

@ -49,10 +49,6 @@
version "4.14.104"
resolved "https://registry.yarnpkg.com/@types/lodash/-/lodash-4.14.104.tgz#53ee2357fa2e6e68379341d92eb2ecea4b11bb80"
"@types/mocha@^2.2.48":
version "2.2.48"
resolved "https://registry.yarnpkg.com/@types/mocha/-/mocha-2.2.48.tgz#3523b126a0b049482e1c3c11877460f76622ffab"
"@types/node@*", "@types/node@^9.4.6":
version "9.4.6"
resolved "https://registry.yarnpkg.com/@types/node/-/node-9.4.6.tgz#d8176d864ee48753d053783e4e463aec86b8d82e"