From 64f6814313063ac1b3f889e19ef92f3f84b73696 Mon Sep 17 00:00:00 2001 From: Nicolas Polizzo Date: Wed, 6 Dec 2023 02:19:31 +0100 Subject: [PATCH] add test for render method --- src/__snapshots__/index.spec.ts.snap | 43 +++++++++++++++++++++++++++- src/index.spec.ts | 10 ++++++- src/index.ts | 6 ++-- 3 files changed, 54 insertions(+), 5 deletions(-) diff --git a/src/__snapshots__/index.spec.ts.snap b/src/__snapshots__/index.spec.ts.snap index d7de040..2cb352c 100644 --- a/src/__snapshots__/index.spec.ts.snap +++ b/src/__snapshots__/index.spec.ts.snap @@ -155,7 +155,48 @@ exports[`mjml-bar-chart mjml markup should render the bar chart 1`] = ` " `; -exports[`mjml-bar-chart renderJSON should render barChart 1`] = ` +exports[`mjml-bar-chart render should render the barChart as HTML 1`] = ` +" +
+ + + +
66
49
33
16
0
+ +
+ + + + + + + + + + + +
+
33
+
14
+
27
+
18
+
66
+
42
+
7
+
15
+
21
+ + + + + +
JanuaryFebruaryMarch
+

support +sales +tech

" +`; + +exports[`mjml-bar-chart renderJSON should render the barChart as JSON 1`] = ` { "attributes": { "class": "mjmlBarChart", diff --git a/src/index.spec.ts b/src/index.spec.ts index 0f686e2..075142c 100644 --- a/src/index.spec.ts +++ b/src/index.spec.ts @@ -147,10 +147,18 @@ describe("mjml-bar-chart", () => { }); describe("renderJSON", () => { - it("should render barChart", () => { + it("should render the barChart as JSON", () => { const json = barChart["renderJSON"](); expect(json).toMatchSnapshot(); }); }); + + describe("render", () => { + it("should render the barChart as HTML", () => { + const html = barChart.render(); + + expect(html).toMatchSnapshot(); + }); + }); }); diff --git a/src/index.ts b/src/index.ts index 7b5bffd..6fefbec 100644 --- a/src/index.ts +++ b/src/index.ts @@ -271,6 +271,8 @@ export default class MjBarChart extends BodyComponent { } private getChartLegend(): JsonNode { + const legends = this.groups.map((_, i) => this.getLegend(i)); + return { ...TR, children: [ @@ -303,9 +305,7 @@ export default class MjBarChart extends BodyComponent { attributes: { style: this.styles("chartLegend"), }, - children: this.groups.map((_, i) => - this.getLegend(i) - ), + children: legends, }, ], },