From 7a612901e37db711582356a4ebd95fa64d84583b Mon Sep 17 00:00:00 2001 From: Taha Shahid Date: Sat, 24 Oct 2020 17:54:47 +0500 Subject: [PATCH] Added Test for markdownPreview and its subcomponents --- .../__snapshots__/footer.test.js.snap | 14 +- .../markdownPreview.test.js.snap | 314 ++++++++++++ .../__tests__/markdownPreview.test.js | 447 ++++++++++++++++++ 3 files changed, 771 insertions(+), 4 deletions(-) create mode 100644 src/components/__tests__/__snapshots__/markdownPreview.test.js.snap create mode 100644 src/components/__tests__/markdownPreview.test.js diff --git a/src/components/__tests__/__snapshots__/footer.test.js.snap b/src/components/__tests__/__snapshots__/footer.test.js.snap index 7d62e9f..058000d 100644 --- a/src/components/__tests__/__snapshots__/footer.test.js.snap +++ b/src/components/__tests__/__snapshots__/footer.test.js.snap @@ -8,7 +8,7 @@ exports[`Footer component Matches the snapshot 1`] = ` className="w-full flex flex-col sm:flex-row justify-evenly py-2" >

-
+
-
+
-
+
+ props.username + +`; + +exports[`DisplaySocial Preview renders correctly with no username 1`] = `null`; + +exports[`DisplayWork Preview renders correctly 1`] = ` +
+ [object Object] + + readme-generator + +
+`; + +exports[`DisplayWork Preview renders correctly with no link 1`] = ` +
+ [object Object] + + readme-generator + +
+`; + +exports[`DisplayWork Preview renders correctly with no prefix 1`] = `null`; + +exports[`DisplayWork Preview renders correctly with no prefix and link 1`] = `null`; + +exports[`DisplayWork Preview renders correctly with no prefix, link and project 1`] = `null`; + +exports[`DisplayWork Preview renders correctly with no project 1`] = ` +
+ [object Object] + + https://dummy.com + +
+`; + +exports[`DisplayWork Preview renders correctly with no project and link 1`] = `null`; + +exports[`DisplayWork Preview renders correctly with no project and prefix 1`] = `null`; + +exports[`GitHubStats Preview renders correctly 1`] = `null`; + +exports[`GitHubStats Preview renders correctly 2`] = ` +
+ +
+`; + +exports[`GithubProfileTrophy Preview renders correctly 1`] = `null`; + +exports[`GithubProfileTrophy Preview renders correctly with show true 1`] = ` +
+ + + + + +
+`; + +exports[`Markdown Preview renders correctly 1`] = ` +
+

+ Hi šŸ‘‹, I'm dummy +

+

+ A passionate frontend developer from India +

+
+ šŸ”­ I’m currently working on + + readme-generator + +
+
+

+ Connect with me: +

+ + props.username + +
+ +
+
+ Ā  +
+
+
+`; + +exports[`SectionTitle Preview renders correctly 1`] = ` +

+ dummy +

+`; + +exports[`SectionTitle Preview renders correctly with no label 1`] = `null`; + +exports[`SectionTitle Preview renders correctly with visible false 1`] = `null`; + +exports[`Skills Preview renders correctly 1`] = ` +
+

+ Languages and Tools: +

+ + unity + +
+`; + +exports[`Skills Preview renders correctly with no skills 1`] = `""`; + +exports[`Social Preview renders correctly 1`] = ` +
+

+ Connect with me: +

+ + props.username + +
+`; + +exports[`SubTitle Preview renders correctly 1`] = ` +

+ A passionate frontend developer from India +

+`; + +exports[`SubTitle Preview renders correctly with no subtitle 1`] = `null`; + +exports[`Title Preview renders correctly 1`] = ` +

+ Hi šŸ‘‹, I'm dummy +

+`; + +exports[`Title Preview renders correctly with no prefix 1`] = `null`; + +exports[`Title Preview renders correctly with no title 1`] = `null`; + +exports[`Title Preview renders correctly with no title and prefix 1`] = `null`; + +exports[`TopLanguages Preview renders correctly 1`] = ` +
+ Ā  +
+`; + +exports[`TopLanguages Preview renders correctly with show true 1`] = ` +
+ +
+`; + +exports[`TwitterBadgePreview Preview renders correctly 1`] = `null`; + +exports[`TwitterBadgePreview Preview renders correctly with show true 1`] = ` +
+ + + + + +
+`; + +exports[`VisitorsBadge Preview renders correctly 1`] = `null`; + +exports[`VisitorsBadge Preview renders correctly with show true 1`] = ` +
+ + + +
+`; + +exports[`Work Preview renders correctly 1`] = ` +
+ šŸ”­ I’m currently working on + + readme-generator + +
+`; diff --git a/src/components/__tests__/markdownPreview.test.js b/src/components/__tests__/markdownPreview.test.js new file mode 100644 index 0000000..ea90cd7 --- /dev/null +++ b/src/components/__tests__/markdownPreview.test.js @@ -0,0 +1,447 @@ +import React from "react"; +import renderer from "react-test-renderer"; + +import MarkdownPreview, { GithubProfileTrophyPreview, GitHubStatsPreview, SkillsPreview, SocialPreview, SubTitlePreview, TitlePreview, TopLanguagesPreview, TwitterBadgePreview, VisitorsBadgePreview, WorkPreview, SectionTitle, DisplayWork, DisplaySocial } from "../markdownPreview" + +const DEFAULT_PREFIX = { + title: "Hi šŸ‘‹, I'm", + currentWork: "šŸ”­ I’m currently working on", + currentLearn: "🌱 I’m currently learning", + collaborateOn: "šŸ‘Æ I’m looking to collaborate on", + helpWith: "šŸ¤ I’m looking for help with", + ama: "šŸ’¬ Ask me about", + contact: "šŸ“« How to reach me", + resume: "šŸ“„ Know about my experiences", + funFact: "⚔ Fun fact", + portfolio: "šŸ‘Øā€šŸ’» All of my projects are available at", + blog: "šŸ“ I regulary write articles on", +} + +const DEFAULT_DATA = { + title: "dummy", + subtitle: "A passionate frontend developer from India", + currentWork: "readme-generator", + currentLearn: "", + collaborateOn: "", + helpWith: "", + ama: "", + contact: "", + funFact: "", + twitterBadge: false, + visitorsBadge: false, + badgeStyle: "flat", + badgeColor: "0e75b6", + badgeLabel: "Profile views", + githubProfileTrophy: false, + githubStats: false, + githubStatsOptions: { + theme: "", + titleColor: "", + textColor: "", + bgColor: "", + hideBorder: false, + cacheSeconds: null, + locale: "en", + }, + topLanguages: false, + topLanguagesOptions: { + theme: "", + titleColor: "", + textColor: "", + bgColor: "", + hideBorder: false, + cacheSeconds: null, + locale: "en", + }, + devDynamicBlogs: false, + mediumDynamicBlogs: false, + rssDynamicBlogs: false, +} + +const DEFAULT_LINK = { + currentWork: "https://dummy.com", + collaborateOn: "", + helpWith: "", + portfolio: "", + blog: "", + resume: "", +} + +const DEFAULT_SOCIAL = { + github: "", + dev: "", + linkedin: "", + codepen: "dummy", + stackoverflow: "", + kaggle: "", + codesandbox: "", + fb: "", + instagram: "", + twitter: "", + dribbble: "", + behance: "", + medium: "", + youtube: "", + codechef: "", + hackerrank: "", + codeforces: "", + leetcode: "", + topcoder: "", + hackerearth: "", + geeks_for_geeks: "", + discord: "", + rssurl: "", +} + +const DUMMY_SKILLS = { + skills: { + unity: true, + android: false, + angularjs: false, + apachecordova: false, + } +} + +describe("Markdown Preview", () => { + it("renders correctly", () => { + let prefix = DEFAULT_PREFIX; + let data = DEFAULT_DATA; + let link = DEFAULT_LINK; + let social = DEFAULT_SOCIAL; + let skills = {} + const tree = renderer + .create() + .toJSON() + expect(tree).toMatchSnapshot() + }) +}) +describe("Title Preview", () => { + it("renders correctly", () => { + let prefix = DEFAULT_PREFIX; + let data = DEFAULT_DATA; + const tree = renderer + .create() + .toJSON() + expect(tree).toMatchSnapshot() + }) + it("renders correctly with no prefix", () => { + let prefix = DEFAULT_PREFIX; + const tree = renderer + .create() + .toJSON() + expect(tree).toMatchSnapshot() + }) + it("renders correctly with no title", () => { + let data = DEFAULT_DATA; + const tree = renderer + .create() + .toJSON() + expect(tree).toMatchSnapshot() + }) + it("renders correctly with no title and prefix", () => { + const tree = renderer + .create() + .toJSON() + expect(tree).toMatchSnapshot() + }) +}) +describe("SubTitle Preview", () => { + it("renders correctly", () => { + let data = DEFAULT_DATA; + const tree = renderer + .create() + .toJSON() + expect(tree).toMatchSnapshot() + }) + it("renders correctly with no subtitle", () => { + const tree = renderer + .create() + .toJSON() + expect(tree).toMatchSnapshot() + }) +}) +describe("SectionTitle Preview", () => { + it("renders correctly", () => { + const tree = renderer + .create() + .toJSON() + expect(tree).toMatchSnapshot() + }) + it("renders correctly with no label", () => { + const tree = renderer + .create() + .toJSON() + expect(tree).toMatchSnapshot() + }) + it("renders correctly with visible false", () => { + const tree = renderer + .create() + .toJSON() + expect(tree).toMatchSnapshot() + }) +}) +describe("DisplayWork Preview", () => { + it("renders correctly", () => { + let prefix = DEFAULT_PREFIX; + let data = DEFAULT_DATA; + let link = DEFAULT_LINK; + const tree = renderer + .create() + .toJSON() + expect(tree).toMatchSnapshot() + }) + it("renders correctly with no prefix, link and project", () => { + const tree = renderer + .create() + .toJSON() + expect(tree).toMatchSnapshot() + }) + it("renders correctly with no prefix", () => { + let data = DEFAULT_DATA; + let link = DEFAULT_LINK; + const tree = renderer + .create() + .toJSON() + expect(tree).toMatchSnapshot() + }) + it("renders correctly with no project", () => { + let prefix = DEFAULT_PREFIX; + let link = DEFAULT_LINK; + const tree = renderer + .create() + .toJSON() + expect(tree).toMatchSnapshot() + }) + it("renders correctly with no link", () => { + let prefix = DEFAULT_PREFIX; + let data = DEFAULT_DATA; + const tree = renderer + .create() + .toJSON() + expect(tree).toMatchSnapshot() + }) + it("renders correctly with no prefix and link", () => { + let data = DEFAULT_DATA; + const tree = renderer + .create() + .toJSON() + expect(tree).toMatchSnapshot() + }) + it("renders correctly with no project and link", () => { + let prefix = DEFAULT_PREFIX; + const tree = renderer + .create() + .toJSON() + expect(tree).toMatchSnapshot() + }) + it("renders correctly with no project and prefix", () => { + let link = DEFAULT_LINK; + const tree = renderer + .create() + .toJSON() + expect(tree).toMatchSnapshot() + }) +}) +describe("DisplaySocial Preview", () => { + it("renders correctly", () => { + let social = DEFAULT_SOCIAL; + const tree = renderer + .create( + ) + .toJSON() + expect(tree).toMatchSnapshot() + }) + it("renders correctly with no username", () => { + const tree = renderer + .create( + ) + .toJSON() + expect(tree).toMatchSnapshot() + }) +}) +describe("VisitorsBadge Preview", () => { + it("renders correctly", () => { + let data = DEFAULT_DATA; + let social = DEFAULT_SOCIAL; + const tree = renderer + .create( + ) + .toJSON() + expect(tree).toMatchSnapshot() + }) + it("renders correctly with show true", () => { + let data = DEFAULT_DATA; + let social = DEFAULT_SOCIAL; + const tree = renderer + .create( + ) + .toJSON() + expect(tree).toMatchSnapshot() + }) +}) +describe("GithubProfileTrophy Preview", () => { + it("renders correctly", () => { + let data = DEFAULT_DATA; + let social = DEFAULT_SOCIAL; + const tree = renderer + .create() + .toJSON() + expect(tree).toMatchSnapshot() + }) + it("renders correctly with show true", () => { + let data = DEFAULT_DATA; + let social = DEFAULT_SOCIAL; + const tree = renderer + .create() + .toJSON() + expect(tree).toMatchSnapshot() + }) +}) +describe("TwitterBadgePreview Preview", () => { + it("renders correctly", () => { + let data = DEFAULT_DATA; + let social = DEFAULT_SOCIAL; + const tree = renderer + .create() + .toJSON() + expect(tree).toMatchSnapshot() + }) + it("renders correctly with show true", () => { + let data = DEFAULT_DATA; + let social = DEFAULT_SOCIAL; + const tree = renderer + .create() + .toJSON() + expect(tree).toMatchSnapshot() + }) +}) +describe("Work Preview", () => { + it("renders correctly", () => { + let data = DEFAULT_DATA; + let prefix = DEFAULT_PREFIX; + let link = DEFAULT_LINK; + let props = { data: data, prefix: prefix, link: link } + const tree = renderer + .create() + .toJSON() + expect(tree).toMatchSnapshot() + }) +}) +describe("Social Preview", () => { + it("renders correctly", () => { + let social = DEFAULT_SOCIAL; + const tree = renderer + .create() + .toJSON() + expect(tree).toMatchSnapshot() + }) +}) +describe("Skills Preview", () => { + it("renders correctly", () => { + let skills = DUMMY_SKILLS.skills + const tree = renderer + .create() + .toJSON() + expect(tree).toMatchSnapshot() + }) + it("renders correctly with no skills", () => { + let skills = {} + const tree = renderer + .create() + .toJSON() + expect(tree).toMatchSnapshot() + }) +}) +describe("TopLanguages Preview", () => { + it("renders correctly", () => { + let data = DEFAULT_DATA; + let social = DEFAULT_SOCIAL; + const tree = renderer + .create() + .toJSON() + expect(tree).toMatchSnapshot() + }) + it("renders correctly with show true", () => { + let data = DEFAULT_DATA; + let social = DEFAULT_SOCIAL; + const tree = renderer + .create() + .toJSON() + expect(tree).toMatchSnapshot() + }) +}) +describe("GitHubStats Preview", () => { + it("renders correctly", () => { + let data = DEFAULT_DATA; + let social = DEFAULT_SOCIAL; + const tree = renderer + .create() + .toJSON() + expect(tree).toMatchSnapshot() + }) + it("renders correctly", () => { + let data = DEFAULT_DATA; + let social = DEFAULT_SOCIAL; + const tree = renderer + .create() + .toJSON() + expect(tree).toMatchSnapshot() + }) +})