import * as assert from "assert";
import * as React from "react";
import { mount, shallow } from "enzyme";
import Number from "../src/Number";
describe("Number", () => {
it("leaves short numbers unchanged", () => {
assert.equal("500", mount({500}).text());
assert.equal("678", mount({678}).text());
});
it("formats long numbers", () => {
assert.equal("5,123", mount({5123}).text());
assert.equal("6,789,345", mount({6789345}).text());
});
it("shortens long numbers when 'short' prop is specified", () => {
assert.equal("5.1K", mount({5123}).text());
assert.equal("6.8M", mount({6789345}).text());
});
it("handles string number inputs", () => {
assert.equal("5,123", mount(5123).text());
assert.equal("6.8M", mount(6789345).text());
});
it("supports non-React formatting", () => {
assert.equal("5,123", Number.format(5123));
assert.equal("6.8M", Number.format("6789345", true));
});
it("throws for non-numeric input", () => {
// shallow render to avoid a console warning due to the new error handling of mounted components in react 16.
assert.throws(() => shallow(nope));
assert.throws(() => Number.format("nope", true));
});
it.only("renders 0 when children is falsy", () => {
assert.equal("0", mount().text());
assert.equal("0", mount({}).text());
assert.equal("0", mount({""}).text());
assert.equal("0", mount(0).text());
assert.equal("0", mount({null}).text());
assert.equal("0", mount({undefined}).text());
});
});