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/README.md b/README.md index 0adab1fe..2751349a 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ # Tree from object -Write a function `createTree(element, data)` that creates a nested list of `ul/li` from an object. -Use keys as list items. +Write a function `createTree(element, data)` that creates a nested list of `ul/li` from an object. +Use keys as list items. `element` - is a DOM element @@ -10,8 +10,8 @@ Use keys as list items. ![screenshot of the tree](example/object-tree.png) -1. Replace `` with your GitHub username in the link - - [DEMO LINK](https://.github.io/js_tree-from-object-DOM/) +1. Replace `elenachernyshova01-cmd` with your GitHub username in the link + - [DEMO LINK](https://elenachernyshova01-cmd.github.io/js_tree-from-object-DOM/) 2. Follow [this instructions](https://github.com/mate-academy/js_task-DOM-guideline) - Run `npm run test` command to test your code; - Run `npm run test:only -- -n` to run fast test ignoring linter; diff --git a/package-lock.json b/package-lock.json index 2c4b5da7..4916a011 100644 --- a/package-lock.json +++ b/package-lock.json @@ -3831,17 +3831,6 @@ "@parcel/core": "^2.16.4" } }, - "node_modules/@pkgjs/parseargs": { - "version": "0.11.0", - "resolved": "https://registry.npmjs.org/@pkgjs/parseargs/-/parseargs-0.11.0.tgz", - "integrity": "sha512-+1VkjdD0QBLPodGrJUeqarH8VAIvQODIbwh9XpP5Syisf7YoQgsJKPNFoqqLQlu+VQ/tVSshMR6loPMn8U+dPg==", - "dev": true, - "optional": true, - "peer": true, - "engines": { - "node": ">=14" - } - }, "node_modules/@pkgr/core": { "version": "0.2.9", "resolved": "https://registry.npmjs.org/@pkgr/core/-/core-0.2.9.tgz", diff --git a/src/index.html b/src/index.html index 3496ee13..bfd0db15 100644 --- a/src/index.html +++ b/src/index.html @@ -9,6 +9,8 @@ /> + + diff --git a/src/scripts/main.js b/src/scripts/main.js index 2cdcd10c..ad0a263f 100644 --- a/src/scripts/main.js +++ b/src/scripts/main.js @@ -22,6 +22,27 @@ const tree = document.querySelector('#tree'); function createTree(element, data) { // WRITE YOUR CODE HERE + const keys = Object.keys(data); + + if (keys.length === 0) { + return; + } + + const ul = document.createElement('ul'); + + keys.forEach((key) => { + const li = document.createElement('li'); + + li.textContent = key; + + createTree(li, data[key]); + + ul.appendChild(li); + }); + + element.appendChild(ul); } -createTree(tree, food); +if (tree) { + createTree(tree, food); +}