-
Notifications
You must be signed in to change notification settings - Fork 8.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
* Convert common/lib files to Typescript and Jest (#37640) * Remove unused lib and associated tests * Convert unquote string to TS and Jest * Convert getFieldType to TS and Jest * Convert httpurl to TS and Jest * Remove latest_change and tests * Convert pivot_object_array to TS and Jest * Address PR feedback * Fix type
- Loading branch information
Corey Robertson
authored
Jul 1, 2019
1 parent
c66eefb
commit f7c0982
Showing
12 changed files
with
115 additions
and
94 deletions.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,28 +4,27 @@ | |
* you may not use this file except in compliance with the Elastic License. | ||
*/ | ||
|
||
import expect from '@kbn/expect'; | ||
import { isValidHttpUrl } from '../httpurl'; | ||
|
||
describe('httpurl.isValidHttpUrl', () => { | ||
it('matches HTTP URLs', () => { | ||
expect(isValidHttpUrl('http://server.com/veggie/hamburger.jpg')).to.be(true); | ||
expect(isValidHttpUrl('https://server.com:4443/veggie/hamburger.jpg')).to.be(true); | ||
expect(isValidHttpUrl('http://user:[email protected]:4443/veggie/hamburger.jpg')).to.be(true); | ||
expect(isValidHttpUrl('http://virtual-machine/veggiehamburger.jpg')).to.be(true); | ||
expect(isValidHttpUrl('https://virtual-machine:44330/veggie.jpg?hamburger')).to.be(true); | ||
expect(isValidHttpUrl('http://192.168.1.50/veggie/hamburger.jpg')).to.be(true); | ||
expect(isValidHttpUrl('https://2600::/veggie/hamburger.jpg')).to.be(true); // ipv6 | ||
expect(isValidHttpUrl('http://2001:4860:4860::8844/veggie/hamburger.jpg')).to.be(true); // ipv6 | ||
expect(isValidHttpUrl('http://server.com/veggie/hamburger.jpg')).toBe(true); | ||
expect(isValidHttpUrl('https://server.com:4443/veggie/hamburger.jpg')).toBe(true); | ||
expect(isValidHttpUrl('http://user:[email protected]:4443/veggie/hamburger.jpg')).toBe(true); | ||
expect(isValidHttpUrl('http://virtual-machine/veggiehamburger.jpg')).toBe(true); | ||
expect(isValidHttpUrl('https://virtual-machine:44330/veggie.jpg?hamburger')).toBe(true); | ||
expect(isValidHttpUrl('http://192.168.1.50/veggie/hamburger.jpg')).toBe(true); | ||
expect(isValidHttpUrl('https://2600::/veggie/hamburger.jpg')).toBe(true); // ipv6 | ||
expect(isValidHttpUrl('http://2001:4860:4860::8844/veggie/hamburger.jpg')).toBe(true); // ipv6 | ||
}); | ||
it('rejects non-HTTP URLs', () => { | ||
expect(isValidHttpUrl('')).to.be(false); | ||
expect(isValidHttpUrl('http://server.com')).to.be(false); | ||
expect(isValidHttpUrl('file:///Users/programmer/Pictures/hamburger.jpeg')).to.be(false); | ||
expect(isValidHttpUrl('ftp://hostz.com:1111/path/to/image.png')).to.be(false); | ||
expect(isValidHttpUrl('ftp://user:password@host:1111/path/to/image.png')).to.be(false); | ||
expect(isValidHttpUrl('')).toBe(false); | ||
expect(isValidHttpUrl('http://server.com')).toBe(false); | ||
expect(isValidHttpUrl('file:///Users/programmer/Pictures/hamburger.jpeg')).toBe(false); | ||
expect(isValidHttpUrl('ftp://hostz.com:1111/path/to/image.png')).toBe(false); | ||
expect(isValidHttpUrl('ftp://user:password@host:1111/path/to/image.png')).toBe(false); | ||
expect( | ||
isValidHttpUrl('data:image/gif;base64,R0lGODlhPQBEAPeoAJosM//AwO/AwHVYZ/z595kzAP/s7P+...') | ||
).to.be(false); | ||
).toBe(false); | ||
}); | ||
}); |
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
27 changes: 0 additions & 27 deletions
27
x-pack/legacy/plugins/canvas/common/lib/__tests__/unquote_string.js
This file was deleted.
Oops, something went wrong.
26 changes: 26 additions & 0 deletions
26
x-pack/legacy/plugins/canvas/common/lib/__tests__/unquote_string.test.ts
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,26 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License; | ||
* you may not use this file except in compliance with the Elastic License. | ||
*/ | ||
|
||
import { unquoteString } from '../unquote_string'; | ||
|
||
describe('unquoteString', () => { | ||
it('removes double quotes', () => { | ||
expect(unquoteString('"hello world"')).toEqual('hello world'); | ||
}); | ||
|
||
it('removes single quotes', () => { | ||
expect(unquoteString("'hello world'")).toEqual('hello world'); | ||
}); | ||
|
||
it('returns unquoted strings', () => { | ||
expect(unquoteString('hello world')).toEqual('hello world'); | ||
expect(unquoteString('hello')).toEqual('hello'); | ||
expect(unquoteString('hello"world')).toEqual('hello"world'); | ||
expect(unquoteString("hello'world")).toEqual("hello'world"); | ||
expect(unquoteString("'hello'world")).toEqual("'hello'world"); | ||
expect(unquoteString('"hello"world')).toEqual('"hello"world'); | ||
}); | ||
}); |
This file was deleted.
Oops, something went wrong.
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,24 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License; | ||
* you may not use this file except in compliance with the Elastic License. | ||
*/ | ||
|
||
import { DatatableColumn } from '../../canvas_plugin_src/functions/types'; | ||
import { unquoteString } from './unquote_string'; | ||
|
||
/** | ||
* Get the type for the column with the given name | ||
* | ||
* @argument columns Array of all columns | ||
* @field Name of the column that we are looking for the type of | ||
* @returns The column type or the string 'null' | ||
*/ | ||
export function getFieldType(columns: DatatableColumn[], field?: string): string { | ||
if (!field) { | ||
return 'null'; | ||
} | ||
const realField = unquoteString(field); | ||
const column = columns.find(dataTableColumn => dataTableColumn.name === realField); | ||
return column ? column.type : 'null'; | ||
} |
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