diff --git a/.github/workflows/test.yml-template b/.github/workflows/test.yml-template new file mode 100644 index 00000000..44ac4e96 --- /dev/null +++ b/.github/workflows/test.yml-template @@ -0,0 +1,29 @@ +name: Test + +on: + pull_request: + branches: [ master ] + +jobs: + build: + + runs-on: ubuntu-latest + + strategy: + matrix: + node-version: [20.x] + + steps: + - uses: actions/checkout@v2 + - name: Use Node.js ${{ matrix.node-version }} + uses: actions/setup-node@v1 + with: + node-version: ${{ matrix.node-version }} + - run: npm install + - run: npm start & sleep 5 && npm test + - name: Upload tests report(cypress mochaawesome merged HTML report) + if: ${{ always() }} + uses: actions/upload-artifact@v2 + with: + name: report + path: reports diff --git a/src/scripts/main.js b/src/scripts/main.js index 2cdcd10c..c8ef94c4 100644 --- a/src/scripts/main.js +++ b/src/scripts/main.js @@ -1,5 +1,7 @@ 'use strict'; +// const { createElement } = require('react'); + const food = { Drink: { Wine: {}, @@ -21,7 +23,31 @@ const food = { const tree = document.querySelector('#tree'); function createTree(element, data) { - // WRITE YOUR CODE HERE -} + if (!element) { + throw new Error('Tree container not found'); + } + + if (!data || typeof data !== 'object' || Object.keys(data).length === 0) { + return; + } + + const newUl = document.createElement('ul'); + + for (const key in data) { + if (Object.prototype.hasOwnProperty.call(data, key)) { + const newLi = document.createElement('li'); + newLi.textContent = key; + + createTree(newLi, data[key]); + + newUl.append(newLi); + } + } + + if (newUl.children.length > 0) { + element.append(newUl); + } +} +export { createTree }; createTree(tree, food);