Skip to content

Commit

Permalink
test(comment) add test "extended" email comment
Browse files Browse the repository at this point in the history
refactor email comment code to not use findDOMNode to register click
listener.

add test for extended email comment processing.

Incorrect comment formatting for email replies. #224
  • Loading branch information
garrettbryan committed Feb 1, 2019
1 parent 9886ffb commit e836f67
Show file tree
Hide file tree
Showing 9 changed files with 130 additions and 17 deletions.
27 changes: 24 additions & 3 deletions dist/gitalk-component.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion dist/gitalk-component.js.map

Large diffs are not rendered by default.

7 changes: 7 additions & 0 deletions dist/gitalk.css

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

27 changes: 24 additions & 3 deletions dist/gitalk.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion dist/gitalk.js.map

Large diffs are not rendered by default.

8 changes: 4 additions & 4 deletions dist/gitalk.min.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/gitalk.min.js.map

Large diffs are not rendered by default.

6 changes: 2 additions & 4 deletions src/component/comment.jsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import React, { Component } from 'react'
import ReactDOM from 'react-dom'
import Avatar from './avatar'
import Svg from './svg'
import distanceInWordsToNow from 'date-fns/distance_in_words_to_now'
Expand Down Expand Up @@ -34,10 +33,9 @@ export default class Comment extends Component {
}

componentDidMount () {
const comment = ReactDOM.findDOMNode(this)
const comment = this.node
const emailResponse = comment.querySelector('.email-hidden-toggle>a')
if (emailResponse) {
emailResponse.setAttribute('href', '')
emailResponse.addEventListener('click', e => {
e.preventDefault()
comment.querySelector('.email-hidden-reply').classList.toggle('expanded')
Expand Down Expand Up @@ -75,7 +73,7 @@ export default class Comment extends Component {
}

return (
<div className={`gt-comment ${isAdmin ? 'gt-comment-admin' : ''}`}>
<div ref={node => { this.node = node; return this.node }} className={`gt-comment ${isAdmin ? 'gt-comment-admin' : ''}`}>
<Avatar
className="gt-comment-avatar"
src={comment.user && comment.user.avatar_url}
Expand Down
66 changes: 66 additions & 0 deletions src/component/comment.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ import { shallow } from 'enzyme'
import Comment from './comment'
import Avatar from './avatar'

import cheerio from 'cheerio'

const comment = {
html_url: 'https://github.com/xxxx/xxxxx/issues/1#issuecomment-xxxxx',
body_html: '<p>123</p>',
Expand All @@ -15,7 +17,71 @@ const comment = {
}
}

const emailComment = {
html_url: 'https://github.com/xxxx/xxxxx/issues/1#issuecomment-xxxxx',
body_html: `
<div class="email-fragment">Email response test</div>
<span class="email-hidden-toggle"><a href="#">…</a></span><div class="email-hidden-reply">
<div class="email-quoted-reply">On Thu, 2019-01-31 at 11:20 -0800, wiredmane wrote:
blog test
You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub, or mute the thread.
{"api_version":"1.0","publisher":{"api_key":"05dde50f1d1a384dd78767c5
5493e4bb","name":"GitHub"},"entity":{"external_key":"github/garrettbr
yan/garrettbryan.github.io","title":"garrettbryan/garrettbryan.github
.io","subtitle":"GitHub repository","main_image_url":"
<a href="https://github.githubassets.com/images/email/message_cards/header.png%22,%22avatar_image_url%22:%22https://github.githubassets.com/images/email/message_cards/avatar.png%22,%22action%22:%7B%22name%22:%22Open">https://github.githubassets.com/images/email/message_cards/header.png","avatar_image_url":"https://github.githubassets.com/images/email/message_cards/avatar.png","action":{"name":"Open</a>
in GitHub","url":"
***@***.***
in <a class="issue-link js-issue-link" data-error-text="Failed to load issue title" data-id="405060178" data-permission-text="Issue title is private" data-url="https://github.com/garrettbryan/garrettbryan.github.io/issues/10" href="https://github.com/garrettbryan/garrettbryan.github.io/issues/10">#10</a>: blog test"}],"action":{"name":"View Issue","url":"
<a class="issue-link js-issue-link" data-error-text="Failed to load issue title" data-id="405060178" data-permission-text="Issue title is private" data-url="https://github.com/garrettbryan/garrettbryan.github.io/issues/10" href="https://github.com/garrettbryan/garrettbryan.github.io/issues/10#issuecomment-459471211">#10 (comment)</a>
"}}}
[
{
***@***.***": "<a href="http://schema.org">http://schema.org</a>",
***@***.***": "EmailMessage",
"potentialAction": {
***@***.***": "ViewAction",
"target": "
<a class="issue-link js-issue-link" data-error-text="Failed to load issue title" data-id="405060178" data-permission-text="Issue title is private" data-url="https://github.com/garrettbryan/garrettbryan.github.io/issues/10" href="https://github.com/garrettbryan/garrettbryan.github.io/issues/10#issuecomment-459471211">#10 (comment)</a>
",
"url": "
<a class="issue-link js-issue-link" data-error-text="Failed to load issue title" data-id="405060178" data-permission-text="Issue title is private" data-url="https://github.com/garrettbryan/garrettbryan.github.io/issues/10" href="https://github.com/garrettbryan/garrettbryan.github.io/issues/10#issuecomment-459471211">#10 (comment)</a>
",
"name": "View Issue"
},
"description": "View this Issue on GitHub",
"publisher": {
***@***.***": "Organization",
"name": "GitHub",
"url": "<a href="https://github.com">https://github.com</a>"
}
}
]</div>
<div class="email-fragment"></div>
</div>
`,
created_at: '2017-06-30T09:01:19Z',
user: {
login: 'booxood',
avatar_url: 'https://avatars0.githubusercontent.com/u/2151410?v=3',
html_url: 'https://github.com/booxood'
}
}

describe('Comment', function () {
it('render extended emailed comment', function () {
const props = {
comment: emailComment
}
const wrapper = shallow(<Comment {...props} />)
expect(wrapper.find('.gt-comment-body').render().html()).toEqual(expect.stringContaining(cheerio.load(emailComment.body_html).html()))
})

it('render with no user', function () {
const props = {
comment
Expand Down

0 comments on commit e836f67

Please sign in to comment.