From 05007dc9279504078ef69cd4170b0c36df5087c4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Juan=20Juli=C3=A1n=20=28JJ=29=20Merelo?= Date: Mon, 17 Oct 2022 12:00:47 +0200 Subject: [PATCH 1/8] Add failing test --- .../json-files-bubbles-analysis.test.js | 42 +++++++++++++++++++ 1 file changed, 42 insertions(+) create mode 100644 features/facebookImport/test/ministory/json-files-bubbles-analysis.test.js diff --git a/features/facebookImport/test/ministory/json-files-bubbles-analysis.test.js b/features/facebookImport/test/ministory/json-files-bubbles-analysis.test.js new file mode 100644 index 000000000..13a308e9a --- /dev/null +++ b/features/facebookImport/test/ministory/json-files-bubbles-analysis.test.js @@ -0,0 +1,42 @@ +import JSONFilesBubblesAnalysis from "../../src/model/analyses/ministories/json-files-bubbles"; +import commonStructure from "../../src/static/commonStructure"; +import { ZipFileMock } from "@polypoly-eu/poly-import"; +import { runAnalysisForExport } from "../utils/analyses-execution"; + +const commonJsonFiles = commonStructure + .filter((path) => path.match(/\.json$/)) + .map((jsonPath) => { + return jsonPath.substring(1); + }); + +async function analyzeZipWithFiles(files) { + const zipFile = new ZipFileMock(); + if (files.length > 0) { + files.forEach((jsonPath) => { + zipFile.addJsonEntry(jsonPath, { foo: "bar" }); + }); + } + const { analysisResult } = await runAnalysisForExport( + JSONFilesBubblesAnalysis, + zipFile + ); + console.log(analysisResult); + return analysisResult; +} + +describe("JSON files analysis for non-empty zip", () => { + let status; + let analysis; + + beforeAll(async () => { + ({ status, analysis } = await analyzeZipWithFiles(commonJsonFiles)); + }); + + it("reports successful status", () => { + expect(status.isSuccess).toBe(true); + }); + + it("has the right title", () => { + expect(analysis.title).toBe("Files Bubbles"); + }); +}); From a0bb4097a91676a0e03bd2e8054010244d23539b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Juan=20Juli=C3=A1n=20=28JJ=29=20Merelo?= Date: Mon, 17 Oct 2022 12:07:35 +0200 Subject: [PATCH 2/8] :white_check_mark: substitute to refactored function call --- .../src/model/analyses/ministories/json-files-bubbles.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/features/facebookImport/src/model/analyses/ministories/json-files-bubbles.js b/features/facebookImport/src/model/analyses/ministories/json-files-bubbles.js index 42a21810b..a9bfdee55 100644 --- a/features/facebookImport/src/model/analyses/ministories/json-files-bubbles.js +++ b/features/facebookImport/src/model/analyses/ministories/json-files-bubbles.js @@ -2,6 +2,7 @@ import React from "react"; import { BubbleCluster } from "@polypoly-eu/poly-look"; import { RootAnalysis, jsonDataEntities } from "@polypoly-eu/poly-analysis"; +import { json } from "d3"; export default class JsonFilesBubblesAnalysis extends RootAnalysis { get title() { @@ -9,8 +10,9 @@ export default class JsonFilesBubblesAnalysis extends RootAnalysis { } async _contentLinesForEntry(zipFile, jsonEntry) { + console.log(jsonEntry.getContent()); const fileContent = new TextDecoder("utf-8").decode( - await zipFile.getContent(jsonEntry) + await jsonEntry.getContent() ); const linesCount = fileContent .split("\n") From c9defdfacccaf9b24d5365f2730cc3fa0044e2a1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Juan=20Juli=C3=A1n=20=28JJ=29=20Merelo?= Date: Mon, 17 Oct 2022 12:09:30 +0200 Subject: [PATCH 3/8] :recycle: calls --- .../src/model/analyses/ministories/json-files-bubbles.js | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/features/facebookImport/src/model/analyses/ministories/json-files-bubbles.js b/features/facebookImport/src/model/analyses/ministories/json-files-bubbles.js index a9bfdee55..91dbebf0f 100644 --- a/features/facebookImport/src/model/analyses/ministories/json-files-bubbles.js +++ b/features/facebookImport/src/model/analyses/ministories/json-files-bubbles.js @@ -9,8 +9,7 @@ export default class JsonFilesBubblesAnalysis extends RootAnalysis { return "Files Bubbles"; } - async _contentLinesForEntry(zipFile, jsonEntry) { - console.log(jsonEntry.getContent()); + async _contentLinesForEntry(jsonEntry) { const fileContent = new TextDecoder("utf-8").decode( await jsonEntry.getContent() ); @@ -21,7 +20,7 @@ export default class JsonFilesBubblesAnalysis extends RootAnalysis { linesCount + (line.trim().length >= 2 ? 1 : 0), 0 ); - return { zipFile, zipEntry: jsonEntry, count: linesCount }; + return { zipEntry: jsonEntry, count: linesCount }; } async analyze({ zipFile, dataAccount }) { @@ -33,7 +32,7 @@ export default class JsonFilesBubblesAnalysis extends RootAnalysis { const relevantEntries = await jsonDataEntities(zipFile); this._filesMessagesCount = await Promise.all( relevantEntries.map((jsonEntry) => - this._contentLinesForEntry(zipFile, jsonEntry) + this._contentLinesForEntry(jsonEntry) ) ); this.active = true; From ef0f40e2b21c98bb55b5f4dfe7cf36e842deeaaf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Juan=20Juli=C3=A1n=20=28JJ=29=20Merelo?= Date: Mon, 17 Oct 2022 12:10:35 +0200 Subject: [PATCH 4/8] Sanity check --- .../test/ministory/json-files-bubbles-analysis.test.js | 1 + 1 file changed, 1 insertion(+) diff --git a/features/facebookImport/test/ministory/json-files-bubbles-analysis.test.js b/features/facebookImport/test/ministory/json-files-bubbles-analysis.test.js index 13a308e9a..a1f778127 100644 --- a/features/facebookImport/test/ministory/json-files-bubbles-analysis.test.js +++ b/features/facebookImport/test/ministory/json-files-bubbles-analysis.test.js @@ -37,6 +37,7 @@ describe("JSON files analysis for non-empty zip", () => { }); it("has the right title", () => { + expect(analysis).toBeInstanceOf(JSONFilesBubblesAnalysis); expect(analysis.title).toBe("Files Bubbles"); }); }); From bc071caf303ef9401ceaa3f450b59f170302859c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Juan=20Juli=C3=A1n=20=28JJ=29=20Merelo?= Date: Mon, 17 Oct 2022 12:13:08 +0200 Subject: [PATCH 5/8] Sanity check --- .../test/ministory/json-files-bubbles-analysis.test.js | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/features/facebookImport/test/ministory/json-files-bubbles-analysis.test.js b/features/facebookImport/test/ministory/json-files-bubbles-analysis.test.js index a1f778127..2db955e4c 100644 --- a/features/facebookImport/test/ministory/json-files-bubbles-analysis.test.js +++ b/features/facebookImport/test/ministory/json-files-bubbles-analysis.test.js @@ -20,7 +20,6 @@ async function analyzeZipWithFiles(files) { JSONFilesBubblesAnalysis, zipFile ); - console.log(analysisResult); return analysisResult; } @@ -36,8 +35,13 @@ describe("JSON files analysis for non-empty zip", () => { expect(status.isSuccess).toBe(true); }); - it("has the right title", () => { + it("has the right type and title", () => { expect(analysis).toBeInstanceOf(JSONFilesBubblesAnalysis); expect(analysis.title).toBe("Files Bubbles"); }); + + it("has the right message count", () => { + expect(analysis.filesMessagesCount).toHaveLength(8)M + }); + }); From 8d2f073b565a01b0457d8fc18d0c9b089272f8d2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Juan=20Juli=C3=A1n=20=28JJ=29=20Merelo?= Date: Mon, 17 Oct 2022 12:15:13 +0200 Subject: [PATCH 6/8] Some clean up --- .../src/model/analyses/ministories/json-files-bubbles.js | 1 - .../test/ministory/json-files-bubbles-analysis.test.js | 4 ++-- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/features/facebookImport/src/model/analyses/ministories/json-files-bubbles.js b/features/facebookImport/src/model/analyses/ministories/json-files-bubbles.js index 91dbebf0f..f205f6b3d 100644 --- a/features/facebookImport/src/model/analyses/ministories/json-files-bubbles.js +++ b/features/facebookImport/src/model/analyses/ministories/json-files-bubbles.js @@ -2,7 +2,6 @@ import React from "react"; import { BubbleCluster } from "@polypoly-eu/poly-look"; import { RootAnalysis, jsonDataEntities } from "@polypoly-eu/poly-analysis"; -import { json } from "d3"; export default class JsonFilesBubblesAnalysis extends RootAnalysis { get title() { diff --git a/features/facebookImport/test/ministory/json-files-bubbles-analysis.test.js b/features/facebookImport/test/ministory/json-files-bubbles-analysis.test.js index 2db955e4c..9ab0a8495 100644 --- a/features/facebookImport/test/ministory/json-files-bubbles-analysis.test.js +++ b/features/facebookImport/test/ministory/json-files-bubbles-analysis.test.js @@ -41,7 +41,7 @@ describe("JSON files analysis for non-empty zip", () => { }); it("has the right message count", () => { - expect(analysis.filesMessagesCount).toHaveLength(8)M + console.log(analysis); + expect(analysis.filesMessagesCount).toHaveLength(8); }); - }); From b90fbda8e8df74d7db68e19a7d96b7ed688b43b7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Juan=20Juli=C3=A1n=20=28JJ=29=20Merelo?= Date: Mon, 17 Oct 2022 12:15:52 +0200 Subject: [PATCH 7/8] Some clean up --- .../test/ministory/json-files-bubbles-analysis.test.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/features/facebookImport/test/ministory/json-files-bubbles-analysis.test.js b/features/facebookImport/test/ministory/json-files-bubbles-analysis.test.js index 9ab0a8495..dbb5b0aba 100644 --- a/features/facebookImport/test/ministory/json-files-bubbles-analysis.test.js +++ b/features/facebookImport/test/ministory/json-files-bubbles-analysis.test.js @@ -42,6 +42,6 @@ describe("JSON files analysis for non-empty zip", () => { it("has the right message count", () => { console.log(analysis); - expect(analysis.filesMessagesCount).toHaveLength(8); + expect(analysis._filesMessagesCount).toHaveLength(8); }); }); From 217b7897f8030b90c6dbf4158ca5a0675a9fcb92 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Juan=20Juli=C3=A1n=20=28JJ=29=20Merelo?= Date: Mon, 17 Oct 2022 12:19:20 +0200 Subject: [PATCH 8/8] :white_check_mark: and coverage :arrow_up: --- .../test/ministory/json-files-bubbles-analysis.test.js | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/features/facebookImport/test/ministory/json-files-bubbles-analysis.test.js b/features/facebookImport/test/ministory/json-files-bubbles-analysis.test.js index dbb5b0aba..0e8e4983e 100644 --- a/features/facebookImport/test/ministory/json-files-bubbles-analysis.test.js +++ b/features/facebookImport/test/ministory/json-files-bubbles-analysis.test.js @@ -41,7 +41,6 @@ describe("JSON files analysis for non-empty zip", () => { }); it("has the right message count", () => { - console.log(analysis); - expect(analysis._filesMessagesCount).toHaveLength(8); + expect(analysis._filesMessagesCount).toHaveLength(10); }); });