From bc264fb4bc6cf5fe6935d9796a5c62592f1ac90f Mon Sep 17 00:00:00 2001
From: Tom Robinson <tlrobinson@gmail.com>
Date: Fri, 19 May 2017 14:05:38 -0700
Subject: [PATCH] Right align lat/lon. Add tests

---
 .../src/metabase/visualizations/lib/table.js  |  8 +++++--
 .../metabase/visualizations/lib/table.spec.js | 23 ++++++++++++++++++-
 2 files changed, 28 insertions(+), 3 deletions(-)

diff --git a/frontend/src/metabase/visualizations/lib/table.js b/frontend/src/metabase/visualizations/lib/table.js
index d612533ab49..8203808bc94 100644
--- a/frontend/src/metabase/visualizations/lib/table.js
+++ b/frontend/src/metabase/visualizations/lib/table.js
@@ -2,7 +2,7 @@
 
 import type { DatasetData, Column } from "metabase/meta/types/Dataset";
 import type { ClickObject } from "metabase/meta/types/Visualization";
-import { isNumber } from "metabase/lib/schema_metadata";
+import { isNumber, isCoordinate } from "metabase/lib/schema_metadata";
 
 export function getTableCellClickedObject(data: DatasetData, rowIndex: number, columnIndex: number, isPivoted: boolean): ClickObject {
     const { rows, cols } = data;
@@ -37,6 +37,10 @@ export function getTableCellClickedObject(data: DatasetData, rowIndex: number, c
     }
 }
 
+/*
+ * Returns whether the column should be right-aligned in a table.
+ * Includes numbers and lat/lon coordinates, but not zip codes, IDs, etc.
+ */
 export function isColumnRightAligned(column: Column) {
-    return isNumber(column);
+    return isNumber(column) || isCoordinate(column);
 }
diff --git a/frontend/src/metabase/visualizations/lib/table.spec.js b/frontend/src/metabase/visualizations/lib/table.spec.js
index 9e89fa2f791..8b12d8c8480 100644
--- a/frontend/src/metabase/visualizations/lib/table.spec.js
+++ b/frontend/src/metabase/visualizations/lib/table.spec.js
@@ -1,4 +1,5 @@
-import { getTableCellClickedObject } from "./table";
+import { getTableCellClickedObject, isColumnRightAligned } from "./table";
+import { TYPE } from "metabase/lib/types";
 
 const RAW_COLUMN = {
     source: "fields"
@@ -40,4 +41,24 @@ describe("metabase/visualization/lib/table", () => {
             // TODO:
         })
     })
+
+    describe("isColumnRightAligned", () => {
+        it("should return true for numeric columns without a special type", () => {
+            expect(isColumnRightAligned({ base_type: TYPE.Integer })).toBe(true);
+        });
+        it("should return true for numeric columns with special type Number", () => {
+            expect(isColumnRightAligned({ base_type: TYPE.Integer, special_type: TYPE.Number })).toBe(true);
+        });
+        it("should return true for numeric columns with special type latitude or longitude ", () => {
+            expect(isColumnRightAligned({ base_type: TYPE.Integer, special_type: TYPE.Latitude })).toBe(true);
+            expect(isColumnRightAligned({ base_type: TYPE.Integer, special_type: TYPE.Longitude })).toBe(true);
+        });
+        it("should return false for numeric columns with special type zip code", () => {
+            expect(isColumnRightAligned({ base_type: TYPE.Integer, special_type: TYPE.ZipCode })).toBe(false)
+        });
+        it("should return false for numeric columns with special type FK or PK", () => {
+            expect(isColumnRightAligned({ base_type: TYPE.Integer, special_type: TYPE.FK })).toBe(false);
+            expect(isColumnRightAligned({ base_type: TYPE.Integer, special_type: TYPE.FK })).toBe(false);
+        });
+    })
 })
-- 
GitLab