Skip to content

Commit

Permalink
Refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
c3er committed Oct 29, 2023
1 parent 224696b commit 2ffb31f
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 16 deletions.
19 changes: 9 additions & 10 deletions app/lib/toc/tocRenderer.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@ const _info = {
collapsedEntries: [],
}

let collapsedSymbolPath = COLLAPSED_SYMBOL_LIGHT_PATH
let expandedSymbolPath = EXPANDED_SYMBOL_LIGHT_PATH
let _collapsedSymbolPath = COLLAPSED_SYMBOL_LIGHT_PATH
let _expandedSymbolPath = EXPANDED_SYMBOL_LIGHT_PATH

class Section {
#isExpanded = true
Expand Down Expand Up @@ -67,7 +67,7 @@ class Section {

set isExpanded(value) {
_document.getElementById(this.htmlId).style.display = value ? "block" : "none"
this.changeButtonImage(value ? expandedSymbolPath : collapsedSymbolPath)
this.changeButtonImage(value ? _expandedSymbolPath : _collapsedSymbolPath)
this.#isExpanded = value
}

Expand Down Expand Up @@ -159,7 +159,7 @@ class Section {
<div class="${SECTION_HTML_CLASS}">
<nobr style="margin-left: ${indentationWidth}px">
<span class="${EXPAND_BUTTON_HTML_CLASS}" id="${this.buttonHtmlId}">
${toButtonHtml(expandedSymbolPath)}
${toButtonHtml(_expandedSymbolPath)}
</span>
<a href="#${
this.id
Expand Down Expand Up @@ -301,7 +301,6 @@ exports.build = content => {
if (isInCode || !line.startsWith("#")) {
continue
}

sectionLevels.push(calcSectionLevel(line))
}

Expand Down Expand Up @@ -355,16 +354,16 @@ exports.getVisibility = () => _isVisible
exports.updateTheme = theme => {
switch (theme) {
case common.DARK_THEME:
expandedSymbolPath = EXPANDED_SYMBOL_DARK_PATH
collapsedSymbolPath = COLLAPSED_SYMBOL_DARK_PATH
_expandedSymbolPath = EXPANDED_SYMBOL_DARK_PATH
_collapsedSymbolPath = COLLAPSED_SYMBOL_DARK_PATH
break
case common.LIGHT_THEME:
expandedSymbolPath = EXPANDED_SYMBOL_LIGHT_PATH
collapsedSymbolPath = COLLAPSED_SYMBOL_LIGHT_PATH
_expandedSymbolPath = EXPANDED_SYMBOL_LIGHT_PATH
_collapsedSymbolPath = COLLAPSED_SYMBOL_LIGHT_PATH
break
}
for (const section of _rootSection?.flattenTree() ?? []) {
section.changeButtonImage(section.isExpanded ? expandedSymbolPath : collapsedSymbolPath)
section.changeButtonImage(section.isExpanded ? _expandedSymbolPath : _collapsedSymbolPath)
}
}

Expand Down
10 changes: 4 additions & 6 deletions test/integration.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -259,9 +259,7 @@ describe("Integration tests with their own app instance each", () => {
await errorDialogLocator.waitFor()
assert.isTrue(await errorDialogLocator.isVisible())

if (text) {
assert.include(await _page.locator(errorDialog.content.path).innerText(), text)
}
assert.include(await _page.locator(errorDialog.content.path).innerText(), text)

await _page.locator(errorDialog.okButton.path).click()
assert.isTrue(await elementIsHidden(errorDialog.path))
Expand Down Expand Up @@ -611,7 +609,7 @@ describe("Integration tests with their own app instance each", () => {

it("is displayed and can be closed", async () => {
await clickMenuItem(error.SHOW_ERROR_MENU_ID)
await assertErrorDialog()
await assertErrorDialog("error")
})
})

Expand Down Expand Up @@ -666,13 +664,13 @@ describe("Integration tests with their own app instance each", () => {

it("doesn't crash after dropping a directory", async () => {
await drop(lib.DEFAULT_DOCUMENT_DIR)
await assertErrorDialog()
await assertErrorDialog("directory")
})

it("doesn't try to load a binary file", async () => {
const imageFilePath = path.join(lib.DEFAULT_DOCUMENT_DIR, "images", "image.png")
await drop(imageFilePath)
await assertErrorDialog()
await assertErrorDialog("not a text file")
assert.notInclude(await _page.title(), imageFilePath)
})

Expand Down

0 comments on commit 2ffb31f

Please sign in to comment.