diff --git a/frontend/src/metabase/auth/components/SSOLoginButton.jsx b/frontend/src/metabase/auth/components/SSOLoginButton.jsx index 7af959a1a02d070b58eff7922fd55ba64da5dbe7..ee07b5c6894cad02a48daac7513664ae1e3e9d0c 100644 --- a/frontend/src/metabase/auth/components/SSOLoginButton.jsx +++ b/frontend/src/metabase/auth/components/SSOLoginButton.jsx @@ -1,7 +1,7 @@ import React, { Component } from "react"; import PropTypes from "prop-types"; import Icon from "metabase/components/Icon"; -import { capitalize } from 'humanize' +import { capitalize } from "humanize-plus" const propTypes = { provider: PropTypes.string.isRequired diff --git a/frontend/src/metabase/dashboard/components/DashCard.jsx b/frontend/src/metabase/dashboard/components/DashCard.jsx index e3fde07c0d7575d9b04063a4f40c93047002a2bd..60bf51b52dcb4bf59a74fcc460ef8562daecda9e 100644 --- a/frontend/src/metabase/dashboard/components/DashCard.jsx +++ b/frontend/src/metabase/dashboard/components/DashCard.jsx @@ -28,6 +28,7 @@ export default class DashCard extends Component { static propTypes = { dashcard: PropTypes.object.isRequired, dashcardData: PropTypes.object.isRequired, + cardDurations: PropTypes.object.isRequired, parameterValues: PropTypes.object.isRequired, markNewCardSeen: PropTypes.func.isRequired, fetchCardData: PropTypes.func.isRequired, diff --git a/frontend/src/metabase/dashboard/components/DashCard.spec.js b/frontend/src/metabase/dashboard/components/DashCard.spec.js new file mode 100644 index 0000000000000000000000000000000000000000..3debcfc1fdc5766494ecc6438dd757308b3917c1 --- /dev/null +++ b/frontend/src/metabase/dashboard/components/DashCard.spec.js @@ -0,0 +1,55 @@ +import React from "react"; +import renderer from "react-test-renderer"; +import { render } from "enzyme"; +import { assocIn } from "icepick"; + +import DashCard from "./DashCard"; + +jest.mock("metabase/visualizations/components/Visualization.jsx"); + +const DEFAULT_PROPS = { + dashcard: { + card: { id: 1 }, + series: [], + parameter_mappings: [] + }, + dashcardData: { + 1: { cols: [], rows: [] } + }, + cardDurations: {}, + parameterValues: {}, + markNewCardSeen: () => {}, + fetchCardData: () => {} +}; + +describe("DashCard", () => { + it("should render with no special classNames", () => { + expect( + renderer.create(<DashCard {...DEFAULT_PROPS} />).toJSON() + ).toMatchSnapshot(); + }); + it("should render unmapped card with Card--unmapped className", () => { + const props = assocIn(DEFAULT_PROPS, ["parameterValues", "foo"], "bar"); + const dashCard = render(<DashCard {...props} />); + expect(dashCard.find(".Card--recent")).toHaveLength(0); + expect(dashCard.find(".Card--unmapped")).toHaveLength(1); + expect(dashCard.find(".Card--slow")).toHaveLength(0); + }); + it("should render slow card with Card--slow className", () => { + const props = assocIn(DEFAULT_PROPS, ["cardDurations", 1], { + average: 1, + fast_threshold: 1 + }); + const dashCard = render(<DashCard {...props} />); + expect(dashCard.find(".Card--recent")).toHaveLength(0); + expect(dashCard.find(".Card--unmapped")).toHaveLength(0); + expect(dashCard.find(".Card--slow")).toHaveLength(1); + }); + it("should render new card with Card--recent className", () => { + const props = assocIn(DEFAULT_PROPS, ["dashcard", "isAdded"], true); + const dashCard = render(<DashCard {...props} />); + expect(dashCard.find(".Card--recent")).toHaveLength(1); + expect(dashCard.find(".Card--unmapped")).toHaveLength(0); + expect(dashCard.find(".Card--slow")).toHaveLength(0); + }); +}); diff --git a/frontend/src/metabase/dashboard/components/__snapshots__/DashCard.spec.js.snap b/frontend/src/metabase/dashboard/components/__snapshots__/DashCard.spec.js.snap new file mode 100644 index 0000000000000000000000000000000000000000..7d53bb0546c633702bbfcff72740f1f13ff2aad3 --- /dev/null +++ b/frontend/src/metabase/dashboard/components/__snapshots__/DashCard.spec.js.snap @@ -0,0 +1,4 @@ +exports[`DashCard should render with no special classNames 1`] = ` +<div + className="Card bordered rounded flex flex-column hover-parent hover--visibility" /> +`; diff --git a/frontend/src/metabase/lib/formatting.js b/frontend/src/metabase/lib/formatting.js index 1a2a30921af916035253fe3af8f0f1092a0d90f7..f6db24482f44966263512c399afdcf79bdefa09f 100644 --- a/frontend/src/metabase/lib/formatting.js +++ b/frontend/src/metabase/lib/formatting.js @@ -1,7 +1,7 @@ import d3 from "d3"; import inflection from "inflection"; import moment from "moment"; -import Humanize from "humanize"; +import Humanize from "humanize-plus"; import React from "react"; import ExternalLink from "metabase/components/ExternalLink.jsx"; diff --git a/frontend/src/metabase/query_builder/components/ExpandableString.jsx b/frontend/src/metabase/query_builder/components/ExpandableString.jsx index 002cefdf5cd9ef05943077c7a27ae69fcbdd3568..cc147b27489598dd8772871435402d53d4d521f1 100644 --- a/frontend/src/metabase/query_builder/components/ExpandableString.jsx +++ b/frontend/src/metabase/query_builder/components/ExpandableString.jsx @@ -1,6 +1,6 @@ import React, { Component } from "react"; -import Humanize from 'humanize'; +import Humanize from "humanize-plus"; export default class ExpandableString extends Component { constructor(props, context) { diff --git a/package.json b/package.json index ea6da9ccaedb7cbc95f78228f09b7c3e259bea33..40dfc566286e6b6478ab94cbffc0ab7274fabcd6 100644 --- a/package.json +++ b/package.json @@ -178,9 +178,13 @@ "modulePaths": [ "<rootDir>/frontend/src" ], + "setupFiles": [ + "<rootDir>/frontend/test/metabase-bootstrap.js" + ], "moduleNameMapper": { "\\.(jpg|jpeg|png|gif|eot|otf|webp|svg|ttf|woff|woff2|mp4|webm|wav|mp3|m4a|aac|oga)$": "<rootDir>/__mocks__/fileMock.js", - "\\.(css|less)$": "<rootDir>/frontend/test/__mocks__/styleMock.js" + "\\.(css|less)$": "<rootDir>/frontend/test/__mocks__/styleMock.js", + "^promise-loader\\?global\\!metabase\\/lib\\/ga-metadata$": "<rootDir>/frontend/src/metabase/lib/ga-metadata.js" } } } diff --git a/webpack.config.js b/webpack.config.js index ee560eb282106139e925d4155bb37dc81732a63a..dd8ececed932577030aeff8e04ff6b06249c1b1f 100644 --- a/webpack.config.js +++ b/webpack.config.js @@ -137,8 +137,7 @@ var config = module.exports = { 'underscore': __dirname + '/node_modules/underscore/underscore-min.js', 'd3': __dirname + '/node_modules/d3/d3.min.js', 'crossfilter': __dirname + '/node_modules/crossfilter/index.js', - 'dc': __dirname + '/node_modules/dc/dc.min.js', - 'humanize': __dirname + '/node_modules/humanize-plus/dist/humanize.min.js' + 'dc': __dirname + '/node_modules/dc/dc.min.js' } },