fixed some issues in table component and added tests (#1873)

* fixed some issues in table component  and added tests

* fixed the enter key handling in text area component
This commit is contained in:
Leila Lali
2018-07-09 14:40:21 -07:00
committed by GitHub
parent 53953f5cda
commit b2ceb09e4d
6 changed files with 168 additions and 13 deletions

View File

@@ -49,7 +49,7 @@ class TestContainer extends ContainerBase<TestComponent> {
}
}
suite('ComponentBase Validation Tests', () => {
suite('ComponentBase Tests', () => {
let testComponent: TestComponent;
let testContainer: TestContainer;
let modelStore: IModelStore;
@@ -129,4 +129,51 @@ suite('ComponentBase Validation Tests', () => {
testContainer.addToContainer(testComponent.descriptor, undefined);
testComponent.validate();
});
test('Component convert size should add px', done => {
let expected = '100px';
let actual = testComponent.convertSize(100);
assert.equal(expected, actual);
actual = testComponent.convertSize('100px');
assert.equal(expected, actual);
expected = '100%';
actual = testComponent.convertSize('100%');
assert.equal(expected, actual);
done();
});
test('Component convert size should keep value if ends with %', done => {
let expected = '100%';
let actual = testComponent.convertSize('100%');
assert.equal(expected, actual);
done();
});
test('Component convert size should return the default value given undefined value %', done => {
let expected = '200';
let actual = testComponent.convertSize(undefined, '200');
assert.equal(expected, actual);
done();
});
test('Component convert to number should return size without px', done => {
let expected = 200;
let actual = testComponent.convertSizeToNumber('200px');
assert.equal(expected, actual);
actual = testComponent.convertSizeToNumber('200');
assert.equal(expected, actual);
done();
});
test('Component convert to number should return 0 given undefined', done => {
let expected = 0;
let actual = testComponent.convertSizeToNumber(undefined);
assert.equal(expected, actual);
done();
});
});

View File

@@ -0,0 +1,77 @@
/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the Source EULA. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
import * as assert from 'assert';
import TableComponent from 'sql/parts/modelComponents/table.component';
'use strict';
suite('TableComponent Tests', () => {
setup(() => {
});
test('Table transformData should convert data and columns successfully given valid inputs', () => {
let data = [
['1', '2', '2'],
['4', '5', '6']
];
let columns = ['c1', 'c2', 'c3'];
let actual: { [key: string]: string }[] = TableComponent.transformData(data, columns);
let expected: { [key: string]: string }[] = [
{
'c1': '1',
'c2': '2',
'c3': '2'
},
{
'c1': '4',
'c2': '5',
'c3': '6'
}
];
assert.deepEqual(actual, expected);
});
test('Table transformData should return empty array given undefined rows', () => {
let data = undefined;
let columns = ['c1', 'c2', 'c3'];
let actual: { [key: string]: string }[] = TableComponent.transformData(data, columns);
let expected: { [key: string]: string }[] = [];
assert.deepEqual(actual, expected);
});
test('Table transformData should return empty array given undefined columns', () => {
let data = [
['1', '2', '2'],
['4', '5', '6']
];
let columns;
let actual: { [key: string]: string }[] = TableComponent.transformData(data, columns);
let expected: { [key: string]: string }[] = [];
assert.deepEqual(actual, expected);
});
test('Table transformData should return array matched with columns given rows with missing column', () => {
let data = [
['1', '2'],
['4', '5']
];
let columns = ['c1', 'c2', 'c3'];
let actual: { [key: string]: string }[] = TableComponent.transformData(data, columns);
let expected: { [key: string]: string }[] = [
{
'c1': '1',
'c2': '2'
},
{
'c1': '4',
'c2': '5'
}
];
assert.deepEqual(actual, expected);
});
});