From faf1c6719b78162587ddd7f7c3cd39d7ef95a6f1 Mon Sep 17 00:00:00 2001 From: Mario See Date: Mon, 19 Nov 2018 15:07:54 -0500 Subject: [PATCH] more testing for connect components (#1046) * adding more tests - covers article.jsx and elements created from its props and state - added png as static file that needs stubbing * video + channelDetails test coverage * chat + channels tests * channels cc refactor * yarn install * update snapshot and string spacing * chat.jsx test mostly tests rendering elements - does not test imported components, as those are already tested separately - does not imported functions from actions or utils as those will be tested separately as well * cleaning up - mocked response with flush promises for state/component to reflect appropriate changes * snapshot updates --- .../chat/__mocks__/algoliasearchUsers.js | 42 +++ .../__snapshots__/alert.test.jsx.snap | 8 +- .../__snapshots__/article.test.jsx.snap | 111 ++++++ .../channelDetails.test.jsx.snap | 340 ++++++++++++++++++ .../__snapshots__/channels.test.jsx.snap | 290 +++++++++++++++ .../__snapshots__/chat.test.jsx.snap | 240 +++++++++++++ .../__snapshots__/content.test.jsx.snap | 28 ++ .../__snapshots__/githubRepo.test.jsx.snap | 25 +- .../__snapshots__/video.test.jsx.snap | 31 ++ app/javascript/chat/__tests__/alert.test.jsx | 52 +-- .../chat/__tests__/article.test.jsx | 125 +++++++ .../chat/__tests__/channelDetails.test.jsx | 273 ++++++++++++++ .../chat/__tests__/channels.test.jsx | 248 +++++++++++++ app/javascript/chat/__tests__/chat.test.jsx | 142 ++++++++ .../chat/__tests__/codeEditor.test.jsx | 8 - .../chat/__tests__/content.test.jsx | 39 ++ .../chat/__tests__/githubRepo.test.jsx | 272 +++++++------- app/javascript/chat/__tests__/video.test.jsx | 48 +++ app/javascript/chat/channelDetails.jsx | 146 +++++--- app/javascript/chat/channels.jsx | 188 ++++++---- jest.config.js | 2 +- package.json | 1 + yarn.lock | 118 +++++- 23 files changed, 2446 insertions(+), 331 deletions(-) create mode 100644 app/javascript/chat/__mocks__/algoliasearchUsers.js create mode 100644 app/javascript/chat/__tests__/__snapshots__/article.test.jsx.snap create mode 100644 app/javascript/chat/__tests__/__snapshots__/channelDetails.test.jsx.snap create mode 100644 app/javascript/chat/__tests__/__snapshots__/channels.test.jsx.snap create mode 100644 app/javascript/chat/__tests__/__snapshots__/chat.test.jsx.snap create mode 100644 app/javascript/chat/__tests__/__snapshots__/content.test.jsx.snap create mode 100644 app/javascript/chat/__tests__/__snapshots__/video.test.jsx.snap create mode 100644 app/javascript/chat/__tests__/article.test.jsx create mode 100644 app/javascript/chat/__tests__/channelDetails.test.jsx create mode 100644 app/javascript/chat/__tests__/channels.test.jsx create mode 100644 app/javascript/chat/__tests__/chat.test.jsx create mode 100644 app/javascript/chat/__tests__/content.test.jsx create mode 100644 app/javascript/chat/__tests__/video.test.jsx diff --git a/app/javascript/chat/__mocks__/algoliasearchUsers.js b/app/javascript/chat/__mocks__/algoliasearchUsers.js new file mode 100644 index 0000000000000..f87c757888ed2 --- /dev/null +++ b/app/javascript/chat/__mocks__/algoliasearchUsers.js @@ -0,0 +1,42 @@ +global.document.head.innerHTML = + "" + + "" + + ""; + +const mockIndex = { + search: query => + new Promise(resolve => { + process.nextTick(() => { + const searchResults = { + ma: { + hits: [ + { + name: 'mat', + path: 'some_path', + title: 'some_title', + id: 'some_id', + }, + ], + nbHits: 1, + page: 0, + nbPages: 1, + hitsPerPage: 10, + processingTimeMS: 1, + exhaustiveNbHits: true, + query: 'ma', + params: + 'query=ma&hitsPerPage=10&filters=supported%3Atrue&restrictIndices=searchables_development%2CTag_development%2Cordered_articles_development%2Cordered_articles_by_published_at_development%2Cordered_articles_by_positive_reactions_count_development%2Cordered_comments_development', + }, + }; + + const results = searchResults[query] || { hits: [] }; + + resolve(results); + }); + }), +}; +const client = { + initIndex: index => mockIndex, // eslint-ignore-line +}; + +export default jest.fn().mockImplementation((id, key) => client); // eslint-ignore-line diff --git a/app/javascript/chat/__tests__/__snapshots__/alert.test.jsx.snap b/app/javascript/chat/__tests__/__snapshots__/alert.test.jsx.snap index 8d2b7b8960592..45f9fd985ce89 100644 --- a/app/javascript/chat/__tests__/__snapshots__/alert.test.jsx.snap +++ b/app/javascript/chat/__tests__/__snapshots__/alert.test.jsx.snap @@ -1,16 +1,16 @@ // Jest Snapshot v1, https://goo.gl/fbAQLP -exports[` should render and test snapshot 1`] = ` +exports[` with hidden class should render and test snapshot 1`] = `
More new messages below
`; -exports[` should render and test snapshot with hidden class 1`] = ` +exports[` without hidden class should render and test snapshot 1`] = `
More new messages below
diff --git a/app/javascript/chat/__tests__/__snapshots__/article.test.jsx.snap b/app/javascript/chat/__tests__/__snapshots__/article.test.jsx.snap new file mode 100644 index 0000000000000..927d187e761f0 --- /dev/null +++ b/app/javascript/chat/__tests__/__snapshots__/article.test.jsx.snap @@ -0,0 +1,111 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`
should load article 1`] = ` +
+ +
+
+
+
+
+

+ Your Approval Means Nothing to Me +

+

+ + princesscarolyn + + Princess Carolyn + + + | July 30, 2014 + + +

+
+
+
+
+
+
+ + + +
+
+`; diff --git a/app/javascript/chat/__tests__/__snapshots__/channelDetails.test.jsx.snap b/app/javascript/chat/__tests__/__snapshots__/channelDetails.test.jsx.snap new file mode 100644 index 0000000000000..f16d6807326a2 --- /dev/null +++ b/app/javascript/chat/__tests__/__snapshots__/channelDetails.test.jsx.snap @@ -0,0 +1,340 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[` as a moderator should render and test snapshot 1`] = ` +
+

+ channel name +

+
+ + something about this channel + +
+ + +
+

+ Invite Members +

+ +

+ Pending Invites: +

+ + +
+ All functionality is early beta. Contact us if you need help with anything. +
+
+
+`; + +exports[` as a moderator should search users and populate searched users div 1`] = ` +preact-render-spy (1 nodes) +------- +
+

channel name

+
+ something about this channel +
+ + +
+

Invite Members

+ +
+ + i am user1 + + + +
+
+ + i am user2 + + + +
+
+ + i am user3 + + + +
+

Pending Invites:

+ + +
+ All functionality is early beta. Contact us if you need help with anything. +
+
+
+ +`; + +exports[` as a user should leave channel and show appropriate message 1`] = ` +preact-render-spy (1 nodes) +------- +
+

channel name

+
+ something about this channel +
+ + +
+

Danger Zone

+

+ You have left this channel + + 😢😢😢 + +

+

It may not be immediately in the sidebar

+

+ Contact the admins at + yo@dev.to + if this was a mistake +

+
+
+ +`; + +exports[` as a user should render and test snapshot 1`] = ` +
+

+ channel name +

+
+ + something about this channel + +
+ + +
+

+ Danger Zone +

+ +
+
+`; diff --git a/app/javascript/chat/__tests__/__snapshots__/channels.test.jsx.snap b/app/javascript/chat/__tests__/__snapshots__/channels.test.jsx.snap new file mode 100644 index 0000000000000..db67bfed0ac96 --- /dev/null +++ b/app/javascript/chat/__tests__/__snapshots__/channels.test.jsx.snap @@ -0,0 +1,290 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[` expanded with chat channels should render and test snapshot 1`] = ` +
+
+ + + +
+ +
+`; + +exports[` expanded without chat channels should render and test snapshot 1`] = ` +
+
+
+ + 👋 + + Welcome to + + DEV Connect + + ! You may message anyone you mutually follow. +
+
+ +
+`; + +exports[` not expanded with chat channels should render and test snapshot 1`] = ` +
+
+ + + +
+
+`; + +exports[` not expanded without chat channels should render and test snapshot 1`] = ` +
+
+
+`; diff --git a/app/javascript/chat/__tests__/__snapshots__/chat.test.jsx.snap b/app/javascript/chat/__tests__/__snapshots__/chat.test.jsx.snap new file mode 100644 index 0000000000000..4db050d959a1c --- /dev/null +++ b/app/javascript/chat/__tests__/__snapshots__/chat.test.jsx.snap @@ -0,0 +1,240 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[` should load chat 1`] = ` +
+
+ + +
+ + + +
+
+
+ + + +
+ +
+
+
+
+
+
+   +
+
+
+
+
+
+ More new messages below +
+
+
+
+