Skip to content
This repository has been archived by the owner on Sep 2, 2020. It is now read-only.

Consolidate redLinks #37

Merged
merged 20 commits into from Jun 13, 2017
Merged

Consolidate redLinks #37

merged 20 commits into from Jun 13, 2017

Conversation

montehurd
Copy link
Collaborator

No description provided.

return fragment
}

describe('DominoDocumentFragment', () => {
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@niedzielski

I should probably split this test out to its own TestDominoDocumentFragment.js file...

Speaking of, could we have tests only run on files in test subdirectories if the files themselves start with the word test?

@montehurd
Copy link
Collaborator Author

montehurd commented Jun 5, 2017

Reminder to self! Update this PR to adhere to new test file naming convention.
(for the frag test utility method as well)

@montehurd montehurd added the WIP label Jun 5, 2017
@montehurd montehurd removed the WIP label Jun 5, 2017
* @return {void}
*/
const hideRedlinks = (document, fragment) => {
const spanTemplate = spanToClone(document)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Have you considered calling spanToClone() something like newRedlinkTemplate()? Otherwise it sounds kind of weird out of context like, "why would I want to clone a span?" Then you could rename the wordy configureSpanAsAnchorReplacement() as configureRedlinkTemplate() or populateRedlinkTemplate().

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like it! Fixed!

@@ -0,0 +1,63 @@
/**
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As far as I can tell, "red links" is two words and so the capitalization so the middle l should be capitalized. e.g., "RedLinks" or "redLinks".

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed!

const content = fragment !== undefined ? fragment : document
redLinkAnchorsInContent(content)
.forEach(redLink => {
const span = spanTemplate.cloneNode(false)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not just create the element each time? Are you seeing a visible performance difference?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Trying to only touch the document object when absolutely necessary. Also, in this case a shallow clone is all we need.

assert.ok(item2.tagName === 'SPAN')
assert.ok(item2.innerHTML === '<b>2</b>')
})
it('should hide the expected redlinks in a document fragment', () => {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would you mind using the same single line of space between it() as you did in WidenImage.test.js or update all the tests?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed!

/**
* Gets a document fragment suitable for use in unit tests
* Details: https://github.com/fgnass/domino/issues/73#issuecomment-200466430
* @param {?String} HTMLString An html string
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missing capitalization of "HTML" :]

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed!

assert.ok(firstChild.tagName === 'DIV')
assert.ok(secondChild.tagName === 'A')
})
it('should not see unexpected method in Domino DocumentFragment', () => {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Consider changing this to something like Domino DocumentFragments should not implement Document.createElement

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done!

it('should not see unexpected method in Domino DocumentFragment', () => {
const frag =
documentFragmentFromHTMLString('<div>Oh look! A fragment!</div><a id="link1"></a>')
assert.ok(frag.createElement === undefined)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since we only want to ensure that createElement() does not exist, consider just using the not operator (!frag.createElement).

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed! With accompanying grumbles about weak typing / implicit type conversions :)

const frag =
documentFragmentFromHTMLString('<div>Oh look! A fragment!</div><a id="link1"></a>')
assert.ok(frag.childNodes.length === 2)
const firstChild = frag.childNodes[0]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Mega style nerd: isolating frag.childNodes[0] seems obvious enough as it is that it's the first child and it only has one usage. Consider dropping firstChild and secondChild for readability.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah good catch. Fixed!

})
it('should return a Domino DocumentFragment with expected childNodes', () => {
const frag =
documentFragmentFromHTMLString('<div>Oh look! A fragment!</div><a id="link1"></a>')
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Consider replacing globally replacing <div>Oh look! A fragment!</div> with <div>text</div> to fit this statement on one line.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed!

const documentFragmentFromHTMLString = HTMLString => {
const document = domino.createDocument()
const template = document.createElement('template')
template.innerHTML = HTMLString
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've been using camelCase on initialisms too. Can you change this to htmlString?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed!

@montehurd montehurd changed the title Consolidate redlinks Consolidate redLinks Jun 13, 2017
@@ -0,0 +1,63 @@
/**
* Configures span to be suitable replacement for redLink anchor.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since this is English, not code, can we say "red link" in the comments?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh sure! Just a sec...

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed!

const frag =
documentFragmentFromHTMLString('<div>text</div><a id="link1"></a>')
assert.ok(frag instanceof domino.impl.DocumentFragment)
})
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Consider adding some new lines between it() here too and also between consecutive describe statements as done in WidenImage.test.js.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done! I wonder if we can update linting to enforce our preference here... too easy to miss 'em.

@niedzielski niedzielski merged commit 7ec3b69 into master Jun 13, 2017
@niedzielski niedzielski deleted the consolidate-redlinks branch June 13, 2017 21:30
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
2 participants