-
Notifications
You must be signed in to change notification settings - Fork 1
Enable multiple levels #10
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A few code styling comments to begin with 😄. Afterwards, we will write a couple of tests and we are good to go!
src/main.js
Outdated
@@ -2,7 +2,19 @@ function convertItemsToUnorderedList(listItems) { | |||
const ulElement = document.createElement("ul"); | |||
listItems.forEach(item => { | |||
const liElement = document.createElement("li"); | |||
liElement.textContent = item.name; | |||
liElement.classList.add("fs-api-entry"); | |||
if (item.type === "file") { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Assuming we are are getting valid input every time, we can ditch the if statement here in favor of a template literal (learn more):
liElement.classList.add(`fs-api-${item.type}`);
src/main.js
Outdated
} else { | ||
liElement.classList.add("fs-api-directory"); | ||
} | ||
const spanElement = document.createElement("span"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you please rename spanElement
to something more semantic (e.g. nameElement
)?
We favor variable names describing the content of each variable, instead of their technical aspects.
src/main.spec.js
Outdated
expect(ul.children[3].children[0].textContent).toBe("SFile.sth"); | ||
expect(ul.children[4].children[0].textContent).toBe("test.go"); | ||
expect(ul.children[5].children[0].textContent).toBe("Troll.go"); | ||
for (i = 0; i < ul.length; i++) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
First, we should not use ul.length
, as it is not in the spec of the HTMLUListElement
(read the spec).
Next, we should simplify this. An example that could work:
for (const li of ul.children) {
// ...do thing here
}
src/main.spec.js
Outdated
expect(ul.children[4].classList.contains("fs-api-file")).toBe(true); | ||
expect(ul.children[5].classList.contains("fs-api-file")).toBe(true); | ||
|
||
for (i = 0; i < 6; i++) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should simplify this as well. Example:
for (const li of ul.children) {
// ...do thing here
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A few more naming updates and I think we are good to go!
src/main.spec.js
Outdated
trees[0].children[1].children[1].children[1].children[0].textContent | ||
).toBe("yarn.lock"); | ||
|
||
//expect(trees[0].children[1].children[0].children[1].textContent).toBe("yarn.lock"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Remove this line please 😄.
src/main.spec.js
Outdated
expect(trees[0].children[5].children[0].textContent).toBe("Troll.go"); | ||
|
||
expect( | ||
trees[0].children[1].children[1].children[0].children[0].textContent |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmmm... I think this is a bit illegible here. What about replacing trees[0].children[1].children[1]
with something more semantic and reusing it also in the test below?
e.g.
const vendorChildren = trees[0].children[1].children[1]; // or vendorSubTree, or something else that sounds more relevant
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this is the last set of comments and then we can move on 🚀.
src/main.spec.js
Outdated
expect(trees[0].children[4].classList.contains("fs-api-file")).toBe(true); | ||
expect(trees[0].children[5].classList.contains("fs-api-file")).toBe(true); | ||
|
||
for (const li of trees) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I guess here you mean const tree of...
src/main.js
Outdated
@@ -2,7 +2,15 @@ function convertItemsToUnorderedList(listItems) { | |||
const ulElement = document.createElement("ul"); | |||
listItems.forEach(item => { | |||
const liElement = document.createElement("li"); | |||
liElement.textContent = item.name; | |||
liElement.classList.add("fs-api-entry"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You can squash these two .add calls into one 😄: https://developer.mozilla.org/en-US/docs/Web/API/Element/classList#Methods
src/main.spec.js
Outdated
expect(trees[0].children[3].children[0].textContent).toBe("SFile.sth"); | ||
expect(trees[0].children[4].children[0].textContent).toBe("test.go"); | ||
expect(trees[0].children[5].children[0].textContent).toBe("Troll.go"); | ||
const vendorChildren = trees[0].children[1].children[1]; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this trees[1]
? If yes, we should use this instead.
src/main.spec.js
Outdated
expect(ul.children[3].textContent).toBe("SFile.sth"); | ||
expect(ul.children[4].textContent).toBe("test.go"); | ||
expect(ul.children[5].textContent).toBe("Troll.go"); | ||
expect(trees[0].children[0].children[0].textContent).toBe("Dir"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we rename trees[0]
to something more semantic (e.g. rootTree
, mainTree
)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you 🎩!
No description provided.