Skip to content

Commit

Permalink
[ML] Fix jest tests. Use replace() with global regex instead of repla…
Browse files Browse the repository at this point in the history
…ceAll().
  • Loading branch information
walterra committed Feb 19, 2021
1 parent 4d63196 commit dd0f4c0
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -67,10 +67,6 @@ describe('getScatterplotMatrixVegaLiteSpec()', () => {
column: ['x', 'y'],
row: ['y', 'x'],
});
expect(vegaLiteSpec.spec.transform).toEqual([
{ as: 'x', calculate: "datum['x']" },
{ as: 'y', calculate: "datum['y']" },
]);
expect(vegaLiteSpec.spec.data.values).toEqual(data);
expect(vegaLiteSpec.spec.mark).toEqual({
opacity: 0.75,
Expand All @@ -96,14 +92,6 @@ describe('getScatterplotMatrixVegaLiteSpec()', () => {
column: ['x', 'y'],
row: ['y', 'x'],
});
expect(vegaLiteSpec.spec.transform).toEqual([
{ as: 'x', calculate: "datum['x']" },
{ as: 'y', calculate: "datum['y']" },
{
as: 'outlier_score',
calculate: "datum['ml.outlier_score']",
},
]);
expect(vegaLiteSpec.spec.data.values).toEqual(data);
expect(vegaLiteSpec.spec.mark).toEqual({
opacity: 0.75,
Expand All @@ -112,7 +100,8 @@ describe('getScatterplotMatrixVegaLiteSpec()', () => {
});
expect(vegaLiteSpec.spec.encoding.color).toEqual({
condition: {
test: "(datum['outlier_score'] >= mlOutlierScoreThreshold.cutoff)",
// Note the alternative UTF-8 dot character
test: "(datum['ml․outlier_score'] >= mlOutlierScoreThreshold.cutoff)",
value: COLOR_OUTLIER,
},
value: euiThemeLight.euiColorMediumShade,
Expand All @@ -121,7 +110,8 @@ describe('getScatterplotMatrixVegaLiteSpec()', () => {
{ field: 'x', type: 'quantitative' },
{ field: 'y', type: 'quantitative' },
{
field: 'outlier_score',
// Note the alternative UTF-8 dot character
field: 'ml․outlier_score',
format: '.3f',
type: 'quantitative',
},
Expand All @@ -147,10 +137,6 @@ describe('getScatterplotMatrixVegaLiteSpec()', () => {
column: ['x', 'y'],
row: ['y', 'x'],
});
expect(vegaLiteSpec.spec.transform).toEqual([
{ as: 'x', calculate: "datum['x']" },
{ as: 'y', calculate: "datum['y']" },
]);
expect(vegaLiteSpec.spec.data.values).toEqual(data);
expect(vegaLiteSpec.spec.mark).toEqual({
opacity: 0.75,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ export const getColorSpec = (
// since VEGA treats dots in field names as nested values and escaping
// in columns/rows for repeated charts isn't working as expected.
function getEscapedVegaFieldName(fieldName: string) {
return fieldName.replaceAll('.', '․');
return fieldName.replace(/\./g, '․');
}

// Replace dots for all keys of all data items with an alternative UTF-8 character
Expand Down

0 comments on commit dd0f4c0

Please sign in to comment.