diff --git a/cypress/e2e/adminTextToggle.cy.js b/cypress/e2e/adminTextToggle.cy.js deleted file mode 100644 index c75132b..0000000 --- a/cypress/e2e/adminTextToggle.cy.js +++ /dev/null @@ -1,67 +0,0 @@ -describe('Toggle display of child nodes', () => { - beforeEach(() => { - cy.exec('npm run db:seed') - cy.intercept('GET', '/api/texts/0').as('getText') - cy.intercept('GET', '/api/nodes/0').as('getNodes') - cy.visit('/admin/texts/0') - cy.wait('@getText') - cy.wait('@getNodes') - }) - - afterEach(() => { - cy.exec('npm run db:wipe') - }) - - it('shows a toggle button on nodes that have children', () => { - cy.get('#text-detail > ul > li') - .first() - .find('button.toggle-children') - .should('exist') - }) - - it('does not show a toggle button on leaf nodes', () => { - cy.get('#text-detail > ul > li > ul > li > ul > li') - .first() - .find('button.toggle-children') - .should('not.exist') - }) - - it('root node children are visible on initial load', () => { - cy.get('#text-detail > ul > li > ul > li') - .first() - .should('be.visible') - }) - - it('grandchildren are hidden on initial load', () => { - cy.get('#text-detail > ul > li > ul > li > ul') - .first() - .should('not.be.visible') - }) - - it('clicking toggle button on a node shows its children', () => { - cy.get('#text-detail > ul > li > ul > li') - .first() - .find('button.toggle-children') - .click() - cy.get('#text-detail > ul > li > ul > li > ul') - .first() - .should('be.visible') - }) - - it('clicking toggle button again hides children', () => { - cy.get('#text-detail > ul > li > ul > li') - .first() - .find('button.toggle-children') - .click() - cy.get('#text-detail > ul > li > ul > li > ul') - .first() - .should('be.visible') - cy.get('#text-detail > ul > li > ul > li') - .first() - .find('button.toggle-children') - .click() - cy.get('#text-detail > ul > li > ul > li > ul') - .first() - .should('not.be.visible') - }) -}) diff --git a/data/seedDb.php b/data/seedDb.php index 3206372..b9f2b31 100644 --- a/data/seedDb.php +++ b/data/seedDb.php @@ -3,29 +3,23 @@ $texts = [ [ 'id' => 0, - 'name' => 'Tanach', + 'name' => 'test text', ], ]; $nodes = [ [ 'id' => 0, - 'title' => 'Tanach', + 'title' => 'Chapter 1', 'textId' => 0, 'parentNodeId' => null, ], [ 'id' => 1, - 'title' => 'Torah', + 'title' => 'Section 1.1', 'textId' => 0, 'parentNodeId' => 0, ], - [ - 'id' => 2, - 'title' => 'Bereishis', - 'textId' => 0, - 'parentNodeId' => 1, - ], ]; $fileDataMap = [ diff --git a/data/wipeDb.php b/data/wipeDb.php index 4183d5b..c36b4af 100644 --- a/data/wipeDb.php +++ b/data/wipeDb.php @@ -6,7 +6,7 @@ $files = [ ]; foreach ($files as $file) { - echo __DIR__ . "/$file\n"; + echo __DIR__ . "/$file"; $path = __DIR__ . "/$file"; file_put_contents($path, json_encode([], JSON_PRETTY_PRINT)); } diff --git a/public/js/text.js b/public/js/text.js index 0388bf6..f017bd4 100644 --- a/public/js/text.js +++ b/public/js/text.js @@ -43,7 +43,7 @@ function buildTree(nodes) { return roots; } -function renderTree(nodes, textId, depth = 0) { +function renderTree(nodes, textId) { const ul = document.createElement('ul'); nodes.forEach(node => { const li = document.createElement('li'); @@ -61,28 +61,11 @@ function renderTree(nodes, textId, depth = 0) { const bulkBtn = document.createElement('button'); bulkBtn.textContent = 'Bulk add children'; bulkBtn.className = 'bulk-add-children'; - bulkBtn.addEventListener( - 'click', - () => toggleBulkAddForm(li, node.id, textId) - ); + bulkBtn.addEventListener('click', () => toggleBulkAddForm(li, node.id, textId)); li.appendChild(bulkBtn); if (node.children.length > 0) { - const childUl = renderTree(node.children, textId, depth + 1); - const childrenVisible = depth === 0; - childUl.style.display = childrenVisible ? '' : 'none'; - - const toggleBtn = document.createElement('button'); - toggleBtn.className = 'toggle-children'; - toggleBtn.textContent = childrenVisible ? '▼' : '▶'; - toggleBtn.addEventListener('click', () => { - const isHidden = childUl.style.display === 'none'; - childUl.style.display = isHidden ? '' : 'none'; - toggleBtn.textContent = isHidden ? '▼' : '▶'; - }); - - li.appendChild(toggleBtn); - li.appendChild(childUl); + li.appendChild(renderTree(node.children, textId)); } ul.appendChild(li);