mirror of
https://github.com/featurebasedb/featurebase.git
synced 2026-08-28 10:54:59 +00:00
refactor for easier reading, add more tests
This commit is contained in:
parent
4a18973274
commit
705efc1b8a
2 changed files with 35 additions and 9 deletions
|
|
@ -17,7 +17,7 @@ afterEach(() => {
|
|||
container = null;
|
||||
});
|
||||
|
||||
it("it renders strings in quotes", () => {
|
||||
it("renders strings in quotes", () => {
|
||||
let row = { thing: "quoted string!" };
|
||||
let col = { name: "thing", datatype: "[]string" };
|
||||
|
||||
|
|
@ -39,7 +39,7 @@ it("renders objects as stringified", () => {
|
|||
}`);
|
||||
});
|
||||
|
||||
it("it puts timestamps in MM/DD/YYYY hh:mm:ss a format", () => {
|
||||
it("puts timestamps in MM/DD/YYYY hh:mm:ss a format", () => {
|
||||
let row = { thing: 1635452050094 };
|
||||
let col = { name: "thing", datatype: "timestamp" };
|
||||
|
||||
|
|
@ -48,3 +48,30 @@ it("it puts timestamps in MM/DD/YYYY hh:mm:ss a format", () => {
|
|||
});
|
||||
expect(container.textContent).toBe("10/28/2021 08:14:10 pm");
|
||||
});
|
||||
|
||||
it("renders timestamps with no value as LocaleString", () => {
|
||||
let row = { thing: false };
|
||||
let col = { name: "thing", datatype: "timestamp" };
|
||||
|
||||
act(() => {
|
||||
render(formatTableCell(row, col), container);
|
||||
});
|
||||
expect(container.textContent).toBe(row.thing.toLocaleString());
|
||||
});
|
||||
|
||||
it("renders non-timestamp, non-string, non-objects as LocaleString", () => {
|
||||
let row = { thing: "idk" };
|
||||
let col = { name: "thing", datatype: "idk" };
|
||||
|
||||
act(() => {
|
||||
render(formatTableCell(row, col), container);
|
||||
});
|
||||
expect(container.textContent).toBe(row.thing.toLocaleString());
|
||||
});
|
||||
|
||||
it("returns null for undefined objects", () => {
|
||||
let row = {};
|
||||
let col = { name: "thing", datatype: "" };
|
||||
|
||||
expect(formatTableCell(row, col)).toBeNull();
|
||||
});
|
||||
|
|
|
|||
|
|
@ -11,13 +11,12 @@ export const formatTableCell = (row: any, col: any) => {
|
|||
if (col.datatype === "[]string") {
|
||||
return <span>{'"' + row[col.name] + '"'}</span>;
|
||||
}
|
||||
return (
|
||||
<span>
|
||||
{col.datatype === "timestamp" && row[col.name]
|
||||
? moment.utc(row[col.name]).format("MM/DD/YYYY hh:mm:ss a")
|
||||
: row[col.name].toLocaleString()}
|
||||
</span>
|
||||
);
|
||||
if (col.datatype === "timestamp" && row[col.name]) {
|
||||
return (
|
||||
<span>{moment.utc(row[col.name]).format("MM/DD/YYYY hh:mm:ss a")}</span>
|
||||
);
|
||||
}
|
||||
return <span>{row[col.name].toLocaleString()}</span>;
|
||||
}
|
||||
return null;
|
||||
};
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue