From 80e34cf6d621a6cbbcbec1256e93bdec72034e4b Mon Sep 17 00:00:00 2001 From: Andrew Watkins Date: Sat, 3 Mar 2018 10:14:40 -0700 Subject: [PATCH] Add first successful TypeScript test --- ui/jest.config.js | 5 +- ui/package.json | 1 - ui/src/shared/components/DatabaseList.tsx | 6 +-- ui/src/types/sources.tsx | 29 ++++++----- ui/test/resources.ts | 49 +++++++++++++++++++ .../shared/components/DatabaseList.test.tsx | 25 +++------- ui/yarn.lock | 4 -- 7 files changed, 82 insertions(+), 37 deletions(-) create mode 100644 ui/test/resources.ts diff --git a/ui/jest.config.js b/ui/jest.config.js index d167f1b455..60b3e08b09 100644 --- a/ui/jest.config.js +++ b/ui/jest.config.js @@ -2,7 +2,10 @@ module.exports = { projects: [ { displayName: 'test', - testPathIgnorePatterns: ['build', 'node_modules/(?!(jest-test))'], + testPathIgnorePatterns: [ + 'build', + '/node_modules/(?!(jest-test))', + ], modulePaths: ['', '/node_modules/'], moduleDirectories: ['src'], setupFiles: ['/test/setupTests.js'], diff --git a/ui/package.json b/ui/package.json index c62d68424a..abe40aa808 100644 --- a/ui/package.json +++ b/ui/package.json @@ -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", diff --git a/ui/src/shared/components/DatabaseList.tsx b/ui/src/shared/components/DatabaseList.tsx index 6c1d879c27..a18f929e0e 100644 --- a/ui/src/shared/components/DatabaseList.tsx +++ b/ui/src/shared/components/DatabaseList.tsx @@ -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 { - constructor() { - super() + constructor(props) { + super(props) this.getDbRp = this.getDbRp.bind(this) } diff --git a/ui/src/types/sources.tsx b/ui/src/types/sources.tsx index 10671e0366..d278d08ae5 100644 --- a/ui/src/types/sources.tsx +++ b/ui/src/types/sources.tsx @@ -2,22 +2,29 @@ export interface Source { id: string name: string url: string - links: { - proxy: string - self: string - kapacitors: string - queries: string - permissions: string - users: string - databases: string - roles: string - } + type: string default: boolean - telegraf?: string + 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 +} + export interface Kapacitor { id?: string url: string diff --git a/ui/test/resources.ts b/ui/test/resources.ts new file mode 100644 index 0000000000..392766a6ee --- /dev/null +++ b/ui/test/resources.ts @@ -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: [], +} diff --git a/ui/test/shared/components/DatabaseList.test.tsx b/ui/test/shared/components/DatabaseList.test.tsx index f8115f913d..61f23817e9 100644 --- a/ui/test/shared/components/DatabaseList.test.tsx +++ b/ui/test/shared/components/DatabaseList.test.tsx @@ -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(, {context: {source}) + const dbList = shallow(, { + context: {source}, + }) return { dbList, diff --git a/ui/yarn.lock b/ui/yarn.lock index 7593d989f2..f2c1d4a39a 100644 --- a/ui/yarn.lock +++ b/ui/yarn.lock @@ -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"