Skip to content
Snippets Groups Projects
Unverified Commit 71681c30 authored by Tom Robinson's avatar Tom Robinson
Browse files

Add DashCard tests

parent 0ab5f2c6
No related branches found
No related tags found
No related merge requests found
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
......
......@@ -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,
......
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);
});
});
exports[`DashCard should render with no special classNames 1`] = `
<div
className="Card bordered rounded flex flex-column hover-parent hover--visibility" />
`;
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";
......
import React, { Component } from "react";
import Humanize from 'humanize';
import Humanize from "humanize-plus";
export default class ExpandableString extends Component {
constructor(props, context) {
......
......@@ -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"
}
}
}
......@@ -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'
}
},
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment