From d81fa46e7547c9ddfdde5190ac7590ff24498a9b Mon Sep 17 00:00:00 2001 From: Taha Shahid Date: Sat, 24 Oct 2020 17:33:53 +0500 Subject: [PATCH 1/3] Refactored components in markdownPreview --- src/components/markdownPreview.js | 631 +++++++++++++++--------------- 1 file changed, 322 insertions(+), 309 deletions(-) diff --git a/src/components/markdownPreview.js b/src/components/markdownPreview.js index df18eae..b94f2c3 100644 --- a/src/components/markdownPreview.js +++ b/src/components/markdownPreview.js @@ -5,55 +5,35 @@ import { topLanguagesLinkGenerator, } from "../utils/link-generators" -const MarkdownPreview = props => { - const TitlePreview = props => { - if (props.prefix && props.title) { - return ( -

- {props.prefix + " " + props.title} -

- ) - } - return null +export const TitlePreview = props => { + if (props.prefix && props.title) { + return ( +

+ {props.prefix + " " + props.title} +

+ ) } - const SubTitlePreview = props => { - if (props.subtitle) { - return

{props.subtitle}

- } - return null + return null +} + +export const SubTitlePreview = props => { + if (props.subtitle) { + return

{props.subtitle}

} - const SectionTitle = props => { - if (!props.visible) return null - else if (props.label) { - return

{props.label}

- } - return null + return null +} + +export const SectionTitle = props => { + if (!props.visible) return null + else if (props.label) { + return

{props.label}

} - const DisplayWork = props => { - if (props.prefix && props.project) { - if (props.link) { - return ( -
- {props.prefix + " "} - - {props.project} - -
- ) - } else { - return ( -
- {props.prefix + " "} - {props.project} -
- ) - } - } - if (props.prefix && props.link) { + return null +} + +export const DisplayWork = props => { + if (props.prefix && props.project) { + if (props.link) { return (
{props.prefix + " "} @@ -62,281 +42,314 @@ const MarkdownPreview = props => { className="no-underline text-blue-700" target="blank" > - {props.link} + {props.project}
) - } - return null - } - const WorkPreview = props => { - const prefix = props.work.prefix - const data = props.work.data - const link = props.work.link - return ( - <> - - - - - - - - - - - - ) - } - const DisplaySocial = props => { - if (props.username) { + } else { return ( +
+ {props.prefix + " "} + {props.project} +
+ ) + } + } + if (props.prefix && props.link) { + return ( +
+ {props.prefix + " "} - props.username + {props.link} + +
+ ) + } + return null +} + +export const WorkPreview = props => { + const prefix = props.work.prefix + const data = props.work.data + const link = props.work.link + return ( + <> + + + + + + + + + + + + ) +} + +export const DisplaySocial = props => { + if (props.username) { + return ( + + props.username + + ) + } + return null +} + +export const SocialPreview = props => { + let viewSocial = false + Object.keys(props.social).forEach(key => { + if (props.social[key] && key != "github") viewSocial = true + }) + return ( +
+ + + + + + + + + + + + + + + + + + + + + + + + +
+ ) +} + +export const VisitorsBadgePreview = props => { + let link = + "https://komarev.com/ghpvc/?username=" + + props.github + + `&label=${props.badgeOptions.badgeLabel}` + + `&color=${props.badgeOptions.badgeColor}` + + `&style=${props.badgeOptions.badgeStyle}` + if (props.show) { + return ( +
+ {" "} + {props.github}{" "} +
+ ) + } + return null +} + +export const TwitterBadgePreview = props => { + let link = + "https://img.shields.io/twitter/follow/" + + props.twitter + + "?logo=twitter&style=for-the-badge" + if (props.show) { + return ( +
+ {" "} + + {props.twitter} + {" "} +
+ ) + } + return null +} + +export const GithubProfileTrophyPreview = props => { + let link = + "https://github-profile-trophy.vercel.app/?username=" + props.github + if (props.show) { + return ( +
+ {" "} + + {props.github} + {" "} +
+ ) + } + return null +} + +export const GitHubStatsPreview = ({ github, options, show }) => { + if (show) { + return ( +
+ {github} +
+ ) + } + return null +} + +export const TopLanguagesPreview = ({ github, options, show }) => { + if (show) { + return ( +
+ {github} +
+ ) + } + return
 
+} + +export const SkillsPreview = props => { + var listSkills = [] + skills.forEach(skill => { + if (props.skills[skill]) { + listSkills.push( + + {skill} ) } - return null - } - const SocialPreview = props => { - let viewSocial = false - Object.keys(props.social).forEach(key => { - if (props.social[key] && key != "github") viewSocial = true - }) - return ( -
- - - - - - - - - - - - - - - - - - - - - - - - -
- ) - } - const VisitorsBadgePreview = props => { - let link = - "https://komarev.com/ghpvc/?username=" + - props.github + - `&label=${props.badgeOptions.badgeLabel}` + - `&color=${props.badgeOptions.badgeColor}` + - `&style=${props.badgeOptions.badgeStyle}` - if (props.show) { - return ( -
- {" "} - {props.github}{" "} -
- ) - } - return null - } - const TwitterBadgePreview = props => { - let link = - "https://img.shields.io/twitter/follow/" + - props.twitter + - "?logo=twitter&style=for-the-badge" - if (props.show) { - return ( -
- {" "} - - {props.twitter} - {" "} -
- ) - } - return null - } - const GithubProfileTrophyPreview = props => { - let link = - "https://github-profile-trophy.vercel.app/?username=" + props.github - if (props.show) { - return ( -
- {" "} - - {props.github} - {" "} -
- ) - } - return null - } - - const GitHubStatsPreview = ({ github, options, show }) => { - if (show) { - return ( -
- {github} -
- ) - } - return null - } - const TopLanguagesPreview = ({ github, options, show }) => { - if (show) { - return ( -
- {props.github} -
- ) - } - return
 
- } - const SkillsPreview = props => { - var listSkills = [] - skills.forEach(skill => { - if (props.skills[skill]) { - listSkills.push( - - {skill} - - ) - } - }) - return listSkills.length > 0 ? ( -
- - {listSkills} -
- ) : ( + }) + return listSkills.length > 0 ? ( +
+ + {listSkills} +
+ ) : ( "" ) - } +} + +const MarkdownPreview = props => { + return (
From 7a612901e37db711582356a4ebd95fa64d84583b Mon Sep 17 00:00:00 2001 From: Taha Shahid Date: Sat, 24 Oct 2020 17:54:47 +0500 Subject: [PATCH 2/3] 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() + }) +}) From 40ccef24fda449f3aebb5aed2503f54dffb9d78c Mon Sep 17 00:00:00 2001 From: Taha Shahid Date: Sun, 25 Oct 2020 21:40:05 +0500 Subject: [PATCH 3/3] Refactored test cases to use enzyme --- .../markdownPreview.test.js.snap | 313 ++---------------- .../__tests__/markdownPreview.test.js | 176 ++++------ 2 files changed, 106 insertions(+), 383 deletions(-) diff --git a/src/components/__tests__/__snapshots__/markdownPreview.test.js.snap b/src/components/__tests__/__snapshots__/markdownPreview.test.js.snap index f200bae..f236a83 100644 --- a/src/components/__tests__/__snapshots__/markdownPreview.test.js.snap +++ b/src/components/__tests__/__snapshots__/markdownPreview.test.js.snap @@ -1,314 +1,69 @@ // Jest Snapshot v1, https://goo.gl/fbAQLP -exports[`DisplaySocial Preview renders correctly 1`] = ` - - props.username - -`; +exports[`DisplaySocial Preview renders correctly 1`] = `ShallowWrapper {}`; -exports[`DisplaySocial Preview renders correctly with no username 1`] = `null`; +exports[`DisplaySocial Preview renders correctly with no username 1`] = `ShallowWrapper {}`; -exports[`DisplayWork Preview renders correctly 1`] = ` -
- [object Object] - - readme-generator - -
-`; +exports[`DisplayWork Preview renders correctly 1`] = `ShallowWrapper {}`; -exports[`DisplayWork Preview renders correctly with no link 1`] = ` -
- [object Object] - - readme-generator - -
-`; +exports[`DisplayWork Preview renders correctly with no link 1`] = `ShallowWrapper {}`; -exports[`DisplayWork Preview renders correctly with no prefix 1`] = `null`; +exports[`DisplayWork Preview renders correctly with no prefix 1`] = `ShallowWrapper {}`; -exports[`DisplayWork Preview renders correctly with no prefix and link 1`] = `null`; +exports[`DisplayWork Preview renders correctly with no prefix and link 1`] = `ShallowWrapper {}`; -exports[`DisplayWork Preview renders correctly with no prefix, link and project 1`] = `null`; +exports[`DisplayWork Preview renders correctly with no prefix, link and project 1`] = `ShallowWrapper {}`; -exports[`DisplayWork Preview renders correctly with no project 1`] = ` -
- [object Object] - - https://dummy.com - -
-`; +exports[`DisplayWork Preview renders correctly with no project 1`] = `ShallowWrapper {}`; -exports[`DisplayWork Preview renders correctly with no project and link 1`] = `null`; +exports[`DisplayWork Preview renders correctly with no project and link 1`] = `ShallowWrapper {}`; -exports[`DisplayWork Preview renders correctly with no project and prefix 1`] = `null`; +exports[`DisplayWork Preview renders correctly with no project and prefix 1`] = `ShallowWrapper {}`; -exports[`GitHubStats Preview renders correctly 1`] = `null`; +exports[`GitHubStats Preview renders correctly 1`] = `ShallowWrapper {}`; -exports[`GitHubStats Preview renders correctly 2`] = ` -
- -
-`; +exports[`GitHubStats Preview renders correctly 2`] = `ShallowWrapper {}`; -exports[`GithubProfileTrophy Preview renders correctly 1`] = `null`; +exports[`GithubProfileTrophy Preview renders correctly 1`] = `ShallowWrapper {}`; -exports[`GithubProfileTrophy Preview renders correctly with show true 1`] = ` -
- - - - - -
-`; +exports[`GithubProfileTrophy Preview renders correctly with show true 1`] = `ShallowWrapper {}`; -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[`Markdown Preview renders correctly 1`] = `ShallowWrapper {}`; -exports[`SectionTitle Preview renders correctly 1`] = ` -

- dummy -

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

- Languages and Tools: -

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

- Connect with me: -

- - props.username - -
-`; +exports[`Social Preview renders correctly 1`] = `ShallowWrapper {}`; -exports[`SubTitle Preview renders correctly 1`] = ` -

- A passionate frontend developer from India -

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

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

-`; +exports[`Title Preview renders correctly 1`] = `ShallowWrapper {}`; -exports[`Title Preview renders correctly with no prefix 1`] = `null`; +exports[`Title Preview renders correctly with no prefix 1`] = `ShallowWrapper {}`; -exports[`Title Preview renders correctly with no title 1`] = `null`; +exports[`Title Preview renders correctly with no title 1`] = `ShallowWrapper {}`; -exports[`Title Preview renders correctly with no title and prefix 1`] = `null`; +exports[`Title Preview renders correctly with no title and prefix 1`] = `ShallowWrapper {}`; -exports[`TopLanguages Preview renders correctly 1`] = ` -
- Ā  -
-`; +exports[`TopLanguages Preview renders correctly 1`] = `ShallowWrapper {}`; -exports[`TopLanguages Preview renders correctly with show true 1`] = ` -
- -
-`; +exports[`TopLanguages Preview renders correctly with show true 1`] = `ShallowWrapper {}`; -exports[`TwitterBadgePreview Preview renders correctly 1`] = `null`; +exports[`TwitterBadgePreview Preview renders correctly 1`] = `ShallowWrapper {}`; -exports[`TwitterBadgePreview Preview renders correctly with show true 1`] = ` -
- - - - - -
-`; +exports[`TwitterBadgePreview Preview renders correctly with show true 1`] = `ShallowWrapper {}`; -exports[`VisitorsBadge Preview renders correctly 1`] = `null`; +exports[`VisitorsBadge Preview renders correctly 1`] = `ShallowWrapper {}`; -exports[`VisitorsBadge Preview renders correctly with show true 1`] = ` -
- - - -
-`; +exports[`VisitorsBadge Preview renders correctly with show true 1`] = `ShallowWrapper {}`; -exports[`Work Preview renders correctly 1`] = ` -
- šŸ”­ I’m currently working on - - readme-generator - -
-`; +exports[`Work Preview renders correctly 1`] = `ShallowWrapper {}`; diff --git a/src/components/__tests__/markdownPreview.test.js b/src/components/__tests__/markdownPreview.test.js index ea90cd7..e19d8a2 100644 --- a/src/components/__tests__/markdownPreview.test.js +++ b/src/components/__tests__/markdownPreview.test.js @@ -1,8 +1,10 @@ import React from "react"; -import renderer from "react-test-renderer"; - +import { shallow, configure } from 'enzyme'; +import Adapter from 'enzyme-adapter-react-16'; import MarkdownPreview, { GithubProfileTrophyPreview, GitHubStatsPreview, SkillsPreview, SocialPreview, SubTitlePreview, TitlePreview, TopLanguagesPreview, TwitterBadgePreview, VisitorsBadgePreview, WorkPreview, SectionTitle, DisplayWork, DisplaySocial } from "../markdownPreview" +configure({ adapter: new Adapter() }); + const DEFAULT_PREFIX = { title: "Hi šŸ‘‹, I'm", currentWork: "šŸ”­ I’m currently working on", @@ -109,14 +111,13 @@ describe("Markdown Preview", () => { let link = DEFAULT_LINK; let social = DEFAULT_SOCIAL; let skills = {} - const tree = renderer - .create() - .toJSON() + expect(tree).toMatchSnapshot() }) }) @@ -124,64 +125,55 @@ describe("Title Preview", () => { it("renders correctly", () => { let prefix = DEFAULT_PREFIX; let data = DEFAULT_DATA; - const tree = renderer - .create() - .toJSON() + const tree = shallow() + expect(tree).toMatchSnapshot() }) it("renders correctly with no prefix", () => { let prefix = DEFAULT_PREFIX; - const tree = renderer - .create() - .toJSON() + const tree = shallow() + expect(tree).toMatchSnapshot() }) it("renders correctly with no title", () => { let data = DEFAULT_DATA; - const tree = renderer - .create() - .toJSON() + const tree = shallow() + expect(tree).toMatchSnapshot() }) it("renders correctly with no title and prefix", () => { - const tree = renderer - .create() - .toJSON() + const tree = shallow() + expect(tree).toMatchSnapshot() }) }) describe("SubTitle Preview", () => { it("renders correctly", () => { let data = DEFAULT_DATA; - const tree = renderer - .create() - .toJSON() + const tree = shallow() + expect(tree).toMatchSnapshot() }) it("renders correctly with no subtitle", () => { - const tree = renderer - .create() - .toJSON() + const tree = shallow() + expect(tree).toMatchSnapshot() }) }) describe("SectionTitle Preview", () => { it("renders correctly", () => { - const tree = renderer - .create() - .toJSON() + const tree = shallow() + expect(tree).toMatchSnapshot() }) it("renders correctly with no label", () => { - const tree = renderer - .create() - .toJSON() + const tree = shallow() + expect(tree).toMatchSnapshot() }) it("renders correctly with visible false", () => { - const tree = renderer - .create() - .toJSON() + const tree = shallow() + expect(tree).toMatchSnapshot() }) }) @@ -190,85 +182,75 @@ describe("DisplayWork Preview", () => { let prefix = DEFAULT_PREFIX; let data = DEFAULT_DATA; let link = DEFAULT_LINK; - const tree = renderer - .create() - .toJSON() + const tree = shallow() + expect(tree).toMatchSnapshot() }) it("renders correctly with no prefix, link and project", () => { - const tree = renderer - .create() - .toJSON() + const tree = shallow() + expect(tree).toMatchSnapshot() }) it("renders correctly with no prefix", () => { let data = DEFAULT_DATA; let link = DEFAULT_LINK; - const tree = renderer - .create() - .toJSON() + const tree = shallow() + expect(tree).toMatchSnapshot() }) it("renders correctly with no project", () => { let prefix = DEFAULT_PREFIX; let link = DEFAULT_LINK; - const tree = renderer - .create() - .toJSON() + const tree = shallow() + expect(tree).toMatchSnapshot() }) it("renders correctly with no link", () => { let prefix = DEFAULT_PREFIX; let data = DEFAULT_DATA; - const tree = renderer - .create() - .toJSON() + const tree = shallow() + expect(tree).toMatchSnapshot() }) it("renders correctly with no prefix and link", () => { let data = DEFAULT_DATA; - const tree = renderer - .create() - .toJSON() + const tree = shallow() + expect(tree).toMatchSnapshot() }) it("renders correctly with no project and link", () => { let prefix = DEFAULT_PREFIX; - const tree = renderer - .create() - .toJSON() + const tree = shallow() + expect(tree).toMatchSnapshot() }) it("renders correctly with no project and prefix", () => { let link = DEFAULT_LINK; - const tree = renderer - .create() - .toJSON() + const tree = shallow() + 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() }) }) @@ -276,8 +258,7 @@ 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() }) }) @@ -312,23 +292,21 @@ 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() }) }) @@ -336,23 +314,21 @@ 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() }) }) @@ -362,34 +338,30 @@ describe("Work Preview", () => { let prefix = DEFAULT_PREFIX; let link = DEFAULT_LINK; let props = { data: data, prefix: prefix, link: link } - const tree = renderer - .create() - .toJSON() + const tree = shallow() + expect(tree).toMatchSnapshot() }) }) describe("Social Preview", () => { it("renders correctly", () => { let social = DEFAULT_SOCIAL; - const tree = renderer - .create() - .toJSON() + const tree = shallow() + expect(tree).toMatchSnapshot() }) }) describe("Skills Preview", () => { it("renders correctly", () => { let skills = DUMMY_SKILLS.skills - const tree = renderer - .create() - .toJSON() + const tree = shallow() + expect(tree).toMatchSnapshot() }) it("renders correctly with no skills", () => { let skills = {} - const tree = renderer - .create() - .toJSON() + const tree = shallow() + expect(tree).toMatchSnapshot() }) }) @@ -397,25 +369,23 @@ 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() }) }) @@ -423,25 +393,23 @@ 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() }) })