diff --git a/.github/workflows/pr-check.yml b/.github/workflows/pr-check.yml new file mode 100644 index 0000000000..c8d5650588 --- /dev/null +++ b/.github/workflows/pr-check.yml @@ -0,0 +1,136 @@ +name: PR check +on: [ push, pull_request ] +jobs: + build-packages: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + - uses: actions/setup-node@v2 + with: + node-version: '14' + cache: 'npm' + - run: npm ci + - run: npm run build:packages + - uses: actions/upload-artifact@v2 + with: + name: built-packages + path: 'dist/' + retention-days: 1 + build-docs: + needs: build-packages + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + - uses: actions/setup-node@v2 + with: + node-version: '14' + - run: npm ci + - run: npm run docs:build + build-playground: + needs: build-packages + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + - uses: actions/setup-node@v2 + with: + node-version: '14' + - run: npm ci + - uses: actions/download-artifact@v2 + with: + name: built-packages + path: dist + - run: npm run build playground -- --configuration=production-wp +# lint: +# runs-on: ubuntu-latest +# steps: +# - uses: actions/checkout@v2 +# - uses: actions/setup-node@v2 +# with: +# node-version: '14' +# - run: npm ci +# - run: npm run ci:lint +# e2e: +# needs: build-packages +# runs-on: ubuntu-latest +# steps: +# - uses: actions/checkout@v2 +# - uses: actions/setup-node@v2 +# with: +# node-version: '14' +# - run: npm ci +# - uses: actions/download-artifact@v2 +# with: +# name: built-packages +# path: dist +# - name: BrowserStack Setup +# uses: 'browserstack/github-actions@master' +# with: +# username: ${{ secrets.BROWSERSTACK_USERNAME }} +# access-key: ${{ secrets.BROWSERSTACK_ACCESS_KEY }} +# - name: Start BrowserStackLocal Tunnel +# uses: browserstack/github-actions/setup-local@master +# with: +# local-testing: start +# - name: Test +# run: npm run ng -- e2e playground-e2e --configuration=production-wp +# - name: Stop BrowserStackLocal Tunnel +# uses: browserstack/github-actions/setup-local@master +# with: +# local-testing: stop + unit-test: + needs: build-packages + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + - uses: actions/setup-node@v2 + with: + node-version: '14' + - run: npm ci + - uses: actions/download-artifact@v2 + with: + name: built-packages + path: dist + - name: BrowserStack Setup + uses: 'browserstack/github-actions@master' + with: + username: ${{ secrets.BROWSERSTACK_USERNAME }} + access-key: ${{ secrets.BROWSERSTACK_ACCESS_KEY }} + - name: Start BrowserStackLocal Tunnel + uses: browserstack/github-actions/setup-local@master + with: + local-testing: start + - name: Test packages + run: npm run test playground -- -c=production-wp --watch=false + - name: Test schematics + run: npm run test:schematics + - name: Stop BrowserStackLocal Tunnel + uses: browserstack/github-actions/setup-local@master + with: + local-testing: stop + - name: Upload coverage to codecov + uses: codecov/codecov-action@v2 + packages-smoke: + needs: build-packages + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + - uses: actions/setup-node@v2 + with: + node-version: '14' + - uses: actions/download-artifact@v2 + with: + name: built-packages + path: packages-smoke/.lib/ + - run: npm ci + working-directory: packages-smoke + - name: Build + run: npm run build -- --configuration=production + working-directory: packages-smoke + - name: E2E + run: npm run e2e + working-directory: packages-smoke + - name: SSR + run: | + npm run build:ssr + npm run serve:ssr + working-directory: packages-smoke diff --git a/.travis.yml b/.travis.yml deleted file mode 100644 index 20e62c96fd..0000000000 --- a/.travis.yml +++ /dev/null @@ -1,46 +0,0 @@ -sudo: false -language: node_js -addons: - chrome: stable -node_js: - - '12' - - -env: - global: - - SAUCE_USERNAME=nixa - - SAUCE_ACCESS_KEY=a922753805a4-7538-6644-c450-48fdf18c - - BROWSER_STACK_USERNAME=debac1 - - BROWSER_STACK_KEY=sHJfQQC3yDFg5iMZdrhA - - BROWSER_PROVIDER_READY_FILE=/tmp/nebular/readyfile - - BROWSER_PROVIDER_ERROR_FILE=/tmp/nebular/errorfile - - LOGS_DIR=/tmp/nebular/logs - - DEV_DEPLOY_HOST=https://nebular-dev-demo.firebaseapp.com/ - - FIREBASE_KEY=WxTLWO1mVWCO0EvbRCfF2qgBXUVUNoKxP5QULy41zVj5HNBovHEZ3ZknbAXoZ2ew/1 - - secure: iQsTgStaSZaDFyQBrDNVD9PemiEK53c2tkHGBIRAPwMgxTP3F1MlUFJDHabpeZlpAoUJ1xwSrJEtW7kF1o8gQL2uu8845BA9Ry/0fuazhKr9qj8cDkYzNPsO8F8KKeeJMseg/UCfFxAKb1AcNA4L/5oDbFO+DTN4LDIlSd86ySZ1dGv+PEeBOuyahE+8nqZvzoZE7C3xhCa4RMGC+DtRMkcK80qSvX9wvnRuRULP89Vb4zBs/YlNxn1vtAFaNgfW5c5EiTXfm2KG41k25uggnh0LX0VEQJ7N4w/1ZXoTjg06HX8VX2gjXefjtEZOiq0vh0aF5aSHfbyGbi0fpcWQcFWrBkC7CfElAoILU/IuQjNTR9wz2oSP1uLJjarCVsF3Mk1cFd1kXxqJEqr4ca8ZOwQOgcydymCa55QjgsYmG4VLF1QnJJmx7oJ+CO2DEe7haJhPcHZsKLus1ubFQNSiu2nasr1mql6IDHzcCEoj3+vGo3ersNraKQPH5M0sQoZ4A6ErwyMirgCodgCxDp42BieWIM4ZOf6ZaEmWE/n8FwTMjBvsiMl6UXshjtNO+1v+WlDF+8mBiumeLv2vhfpjhPji07i27+U4lTDVj78eqe5Vsiv4KlvPF+yQ/vI6qLXNIjSXRViMS200VSR1y2uXG6ACtHXAxtszrRmfgk8kI8E= - - NG_CLI_ANALYTICS=false - - secure: HPaMw9w/sNMtubB8F1/+vqsPeYDQAsqmtHorlw9RIRmH4CCpN3IE/zrltM8ufX8GzToVnK5y3r2zgI+FrVomqAk6tH8nJe1v5bjMxxUDTI1YRfnPOnVxIXnxkQ+l0oZnDjXggfXtBnoLpoz++aHXoRKG+dPVAtur9tjZs2J1d/kNBnt2DWtk9Mb1J1EFVHVMCTD3/+KJzIhzLux8JUY8uxk5DfjKxTDmd24Qj7BGvaaVNmLJdMAVvXGnfV2e2vMbfxdH8rSZAr303GDAfkQama8W/YsQi5RFtxWXS/7bPTOUYSSD7sYqXYzYyW1LBZX0Fws9TOWX1pL5WT2TryP//Ccs4OE7w5Dkzfb2DmYNlWoPhSYj8w1y5RJ6PEzbOk0KkzEzbb5exVW4MHRTDb4LK4F5GhmtS30w9DFwRSfC2VeYmIoZwGxOZq4kT8pWjIAaD8jW7Lqmo/1dj0YBbQlLuvfBR0A9vtBYjbmrYcqMqu5FLyzHkwCdAh0z7vkJHk1BSi8oW5xs7Vvuaou0200aBbv6tt+NEhUjdm+h0IxM3eypqaQuIJGaofwLe0W/9SqRS3/72uae6qXUBREdJXjWJvrbFSR34LpHx0noPyil1H6VVJFSYjKqkj5h68U+CvK5BNAkGgRZLmwL8Q0fuWZGY8cEpnVFAX6qDHOLLS6aJYQ= - matrix: - - MODE=packages_smoke - - MODE=deploy_docs - - MODE=browserstack_e2e - - MODE=browserstack_unit_test - - MODE=build - - MODE=docs - - MODE=lint -branches: - only: - - master - - next - -matrix: - fast_finish: true - -install: - - npm install - -before_script: - - mkdir -p $LOGS_DIR - -script: - - ./scripts/ci/travis-script.sh diff --git a/angular.json b/angular.json index 503f456941..6325435f36 100644 --- a/angular.json +++ b/angular.json @@ -152,7 +152,7 @@ }, "configurations": { "production-wp": { - "devServerTarget": "playground:production-wp" + "devServerTarget": "playground:serve:production-wp" } } }, @@ -250,6 +250,26 @@ "extractLicenses": false, "sourceMap": true, "namedChunks": true + }, + "production-wp": { + "budgets": [ + { + "type": "initial", + "maximumWarning": "500kb" + }, + { + "type": "anyComponentStyle", + "maximumWarning": "2kb" + } + ], + "fileReplacements": [ + { + "replace": "docs/environments/environment.ts", + "with": "docs/environments/environment.prod.ts" + } + ], + "outputHashing": "all", + "tsConfig": "docs/tsconfig.wp.json" } }, "defaultConfiguration": "production" diff --git a/docs/tsconfig.wp.json b/docs/tsconfig.wp.json new file mode 100644 index 0000000000..9c79aa767e --- /dev/null +++ b/docs/tsconfig.wp.json @@ -0,0 +1,8 @@ +{ + "extends": "./tsconfig.app.json", + "paths": { + "@nebular/*": [ + "dist/*" + ] + } +} diff --git a/karma.conf.js b/karma.conf.js index 53c1201111..71fb442f6b 100644 --- a/karma.conf.js +++ b/karma.conf.js @@ -8,7 +8,6 @@ module.exports = function (config) { plugins: [ require('karma-jasmine'), require('karma-chrome-launcher'), - require('karma-sauce-launcher'), require('karma-browserstack-launcher'), require('karma-jasmine-html-reporter'), require('karma-coverage'), @@ -39,11 +38,6 @@ module.exports = function (config) { base: 'ChromeHeadless', flags: ['--no-sandbox', '--window-size=1024,768'], }, - SauceChromeCI: { - base: 'SauceLabs', - browserName: 'chrome', - version: 'latest', - }, BrowserstackChromeCI: { base: 'BrowserStack', browser: 'Chrome', @@ -52,50 +46,22 @@ module.exports = function (config) { os_version: '10', }, }, - sauceLabs: { - testName: 'Nebular Unit Tests', - startConnect: false, - recordVideo: false, - recordScreenshots: false, - idleTimeout: 600, - commandTimeout: 600, - maxDuration: 5400, - }, - browserStack: { - project: 'Nebular Unit Tests', + }; + + if (process.env.CI) { + config.browserStack = { startTunnel: false, - retryLimit: 1, + build: process.env.BROWSERSTACK_BUILD_NAME, + project: process.env.BROWSERSTACK_PROJECT_NAME, + tunnelIdentifier: process.env.BROWSERSTACK_LOCAL_IDENTIFIER, timeout: 600, - pollingTimeout: 20000, video: false, - }, - }; - - if (process.env['TRAVIS']) { - const [platform] = process.env.MODE.split('_'); - const buildId = `TRAVIS #${process.env['TRAVIS_BUILD_NUMBER']} (${process.env['TRAVIS_BUILD_ID']})`; - + user: process.env.BROWSERSTACK_USERNAME, + key: process.env.BROWSERSTACK_ACCESS_KEY, + }; configuration.singleRun = true; - - if (platform === 'sauce') { - const key = require('./scripts/ci/sauce/config'); - - configuration.reporters.push('saucelabs'); - configuration.sauceLabs.build = buildId; - configuration.sauceLabs.tunnelIdentifier = process.env['TRAVIS_JOB_ID']; - configuration.sauceLabs.username = process.env['SAUCE_USERNAME']; - configuration.sauceLabs.accessKey = key; - configuration.browsers = ['SauceChromeCI']; - } else if (platform === 'browserstack') { - const key = require('./scripts/ci/browserstack/config'); - - configuration.reporters.push('BrowserStack'); - configuration.browserStack.build = buildId; - configuration.browserStack.tunnelIdentifier = process.env['TRAVIS_JOB_ID']; - configuration.browserStack.username = process.env['BROWSER_STACK_USERNAME']; - configuration.browserStack.accessKey = key; - configuration.browsers = ['BrowserstackChromeCI']; - } + configuration.browsers = ['BrowserstackChromeCI']; + configuration.reporters.push('BrowserStack'); } config.set(configuration); diff --git a/package-lock.json b/package-lock.json index 45f51751ec..621da0a036 100644 --- a/package-lock.json +++ b/package-lock.json @@ -5102,61 +5102,6 @@ "integrity": "sha512-Y9J6ZjXtoYh8RnXVCMOU/ttDmk1aBjunq9vO0ta5x85WDQiQfUF9sIPBITdbiiIVcBo03Hi3jMxigBtsddlXRw==", "dev": true }, - "archiver": { - "version": "2.1.1", - "resolved": "https://registry.npmjs.org/archiver/-/archiver-2.1.1.tgz", - "integrity": "sha1-/2YrSnggFJSj7lRNOjP+dJZQnrw=", - "dev": true, - "requires": { - "archiver-utils": "^1.3.0", - "async": "^2.0.0", - "buffer-crc32": "^0.2.1", - "glob": "^7.0.0", - "lodash": "^4.8.0", - "readable-stream": "^2.0.0", - "tar-stream": "^1.5.0", - "zip-stream": "^1.2.0" - }, - "dependencies": { - "lodash": { - "version": "4.17.11", - "resolved": "https://registry.npmjs.org/lodash/-/lodash-4.17.11.tgz", - "integrity": "sha512-cQKh8igo5QUhZ7lg38DYWAxMvjSAKG0A8wGSVimP07SIUEK2UO+arSRKbRZWtelMtN5V0Hkwh5ryOto/SshYIg==", - "dev": true - } - } - }, - "archiver-utils": { - "version": "1.3.0", - "resolved": "https://registry.npmjs.org/archiver-utils/-/archiver-utils-1.3.0.tgz", - "integrity": "sha1-5QtMCccL89aA4y/xt5lOn52JUXQ=", - "dev": true, - "requires": { - "glob": "^7.0.0", - "graceful-fs": "^4.1.0", - "lazystream": "^1.0.0", - "lodash": "^4.8.0", - "normalize-path": "^2.0.0", - "readable-stream": "^2.0.0" - }, - "dependencies": { - "lodash": { - "version": "4.17.11", - "resolved": "https://registry.npmjs.org/lodash/-/lodash-4.17.11.tgz", - "integrity": "sha512-cQKh8igo5QUhZ7lg38DYWAxMvjSAKG0A8wGSVimP07SIUEK2UO+arSRKbRZWtelMtN5V0Hkwh5ryOto/SshYIg==", - "dev": true - }, - "normalize-path": { - "version": "2.1.1", - "resolved": "https://registry.npmjs.org/normalize-path/-/normalize-path-2.1.1.tgz", - "integrity": "sha1-GrKLVW4Zg2Oowab35vogE3/mrtk=", - "dev": true, - "requires": { - "remove-trailing-separator": "^1.0.1" - } - } - } - }, "archy": { "version": "1.0.0", "resolved": "https://registry.npmjs.org/archy/-/archy-1.0.0.tgz", @@ -5875,16 +5820,6 @@ "file-uri-to-path": "1.0.0" } }, - "bl": { - "version": "1.2.2", - "resolved": "https://registry.npmjs.org/bl/-/bl-1.2.2.tgz", - "integrity": "sha512-e8tQYnZodmebYDWGH7KMRvtzKXaJHx3BbilrgZCfvyLUYdKpK1t5PSPmpkny/SgiTSCnjfLW7v5rlONXVFkQEA==", - "dev": true, - "requires": { - "readable-stream": "^2.3.5", - "safe-buffer": "^5.1.1" - } - }, "blocking-proxy": { "version": "1.0.1", "resolved": "https://registry.npmjs.org/blocking-proxy/-/blocking-proxy-1.0.1.tgz", @@ -6047,40 +5982,12 @@ } } }, - "buffer-alloc": { - "version": "1.2.0", - "resolved": "https://registry.npmjs.org/buffer-alloc/-/buffer-alloc-1.2.0.tgz", - "integrity": "sha512-CFsHQgjtW1UChdXgbyJGtnm+O/uLQeZdtbDo8mfUgYXCHSM1wgrVxXm6bSyrUuErEb+4sYVGCzASBRot7zyrow==", - "dev": true, - "requires": { - "buffer-alloc-unsafe": "^1.1.0", - "buffer-fill": "^1.0.0" - } - }, - "buffer-alloc-unsafe": { - "version": "1.1.0", - "resolved": "https://registry.npmjs.org/buffer-alloc-unsafe/-/buffer-alloc-unsafe-1.1.0.tgz", - "integrity": "sha512-TEM2iMIEQdJ2yjPJoSIsldnleVaAk1oW3DBVUykyOLsEsFmEc9kn+SFFPz+gl54KQNxlDnAwCXosOS9Okx2xAg==", - "dev": true - }, - "buffer-crc32": { - "version": "0.2.13", - "resolved": "https://registry.npmjs.org/buffer-crc32/-/buffer-crc32-0.2.13.tgz", - "integrity": "sha1-DTM+PwDqxQqhRUq9MO+MKl2ackI=", - "dev": true - }, "buffer-equal": { "version": "1.0.0", "resolved": "https://registry.npmjs.org/buffer-equal/-/buffer-equal-1.0.0.tgz", "integrity": "sha1-WWFrSYME1Var1GaWayLu2j7KX74=", "dev": true }, - "buffer-fill": { - "version": "1.0.0", - "resolved": "https://registry.npmjs.org/buffer-fill/-/buffer-fill-1.0.0.tgz", - "integrity": "sha1-+PeLdniYiO858gXNY39o5wISKyw=", - "dev": true - }, "buffer-from": { "version": "1.1.1", "resolved": "https://registry.npmjs.org/buffer-from/-/buffer-from-1.1.1.tgz", @@ -6747,29 +6654,6 @@ "integrity": "sha512-Rd3se6QB+sO1TwqZjscQrurpEPIfO0/yYnSin6Q/rD3mOutHvUrCAhJub3r90uNb+SESBuE0QYoB90YdfatsRg==", "dev": true }, - "compress-commons": { - "version": "1.2.2", - "resolved": "https://registry.npmjs.org/compress-commons/-/compress-commons-1.2.2.tgz", - "integrity": "sha1-UkqfEJA/OoEzibAiXSfEi7dRiQ8=", - "dev": true, - "requires": { - "buffer-crc32": "^0.2.1", - "crc32-stream": "^2.0.0", - "normalize-path": "^2.0.0", - "readable-stream": "^2.0.0" - }, - "dependencies": { - "normalize-path": { - "version": "2.1.1", - "resolved": "https://registry.npmjs.org/normalize-path/-/normalize-path-2.1.1.tgz", - "integrity": "sha1-GrKLVW4Zg2Oowab35vogE3/mrtk=", - "dev": true, - "requires": { - "remove-trailing-separator": "^1.0.1" - } - } - } - }, "compressible": { "version": "2.0.17", "resolved": "https://registry.npmjs.org/compressible/-/compressible-2.0.17.tgz", @@ -7704,25 +7588,6 @@ } } }, - "crc": { - "version": "3.8.0", - "resolved": "https://registry.npmjs.org/crc/-/crc-3.8.0.tgz", - "integrity": "sha512-iX3mfgcTMIq3ZKLIsVFAbv7+Mc10kxabAGQb8HvjA1o3T1PIYprbakQ65d3I+2HGHt6nSKkM9PYjgoJO2KcFBQ==", - "dev": true, - "requires": { - "buffer": "^5.1.0" - } - }, - "crc32-stream": { - "version": "2.0.0", - "resolved": "https://registry.npmjs.org/crc32-stream/-/crc32-stream-2.0.0.tgz", - "integrity": "sha1-483TtN8xaN10494/u8t7KX/pCPQ=", - "dev": true, - "requires": { - "crc": "^3.4.4", - "readable-stream": "^2.0.0" - } - }, "create-require": { "version": "1.1.1", "resolved": "https://registry.npmjs.org/create-require/-/create-require-1.1.1.tgz", @@ -10490,12 +10355,6 @@ "resolved": "https://registry.npmjs.org/from/-/from-0.1.7.tgz", "integrity": "sha1-g8YK/Fi5xWmXAH7Rp2izqzA6RP4=" }, - "fs-constants": { - "version": "1.0.0", - "resolved": "https://registry.npmjs.org/fs-constants/-/fs-constants-1.0.0.tgz", - "integrity": "sha512-y6OAwoSIf7FyjMIv94u+b5rdheZEjzR63GTyZJm5qh4Bi+2YgwLCcI/fPFZkL5PSixOt6ZNKm+w+Hfp/Bciwow==", - "dev": true - }, "fs-extra": { "version": "8.1.0", "resolved": "https://registry.npmjs.org/fs-extra/-/fs-extra-8.1.0.tgz", @@ -13719,26 +13578,6 @@ "integrity": "sha512-pzum1TL7j90DTE86eFt48/s12hqwQuiD+e5aXx2Dc9wDEn2LfGq6RoAxEZZjFiN0RDSCOnosEKRZWxbQ+iMpQQ==", "dev": true }, - "karma-sauce-launcher": { - "version": "1.2.0", - "resolved": "https://registry.npmjs.org/karma-sauce-launcher/-/karma-sauce-launcher-1.2.0.tgz", - "integrity": "sha512-lEhtGRGS+3Yw6JSx/vJY9iQyHNtTjcojrSwNzqNUOaDceKDu9dPZqA/kr69bUO9G2T6GKbu8AZgXqy94qo31Jg==", - "dev": true, - "requires": { - "q": "^1.5.0", - "sauce-connect-launcher": "^1.2.2", - "saucelabs": "^1.4.0", - "wd": "^1.4.0" - }, - "dependencies": { - "q": { - "version": "1.5.1", - "resolved": "https://registry.npmjs.org/q/-/q-1.5.1.tgz", - "integrity": "sha1-fjL3W0E4EpHQRhHxvxQQmsAGUdc=", - "dev": true - } - } - }, "karma-source-map-support": { "version": "1.4.0", "resolved": "https://registry.npmjs.org/karma-source-map-support/-/karma-source-map-support-1.4.0.tgz", @@ -21360,27 +21199,6 @@ } } }, - "sauce-connect-launcher": { - "version": "1.2.6", - "resolved": "https://registry.npmjs.org/sauce-connect-launcher/-/sauce-connect-launcher-1.2.6.tgz", - "integrity": "sha512-yBTYfzI6AWRwoXJoIqmVgz+eCpWX6CsJ4Ap8fowjsGlN+27OKbnQxv6POd4Rzh57BH9WeA9K8orIzNxO8mMBQA==", - "dev": true, - "requires": { - "adm-zip": "~0.4.3", - "async": "^2.1.2", - "https-proxy-agent": "^2.2.1", - "lodash": "^4.16.6", - "rimraf": "^2.5.4" - }, - "dependencies": { - "lodash": { - "version": "4.17.11", - "resolved": "https://registry.npmjs.org/lodash/-/lodash-4.17.11.tgz", - "integrity": "sha512-cQKh8igo5QUhZ7lg38DYWAxMvjSAKG0A8wGSVimP07SIUEK2UO+arSRKbRZWtelMtN5V0Hkwh5ryOto/SshYIg==", - "dev": true - } - } - }, "saucelabs": { "version": "1.5.0", "resolved": "https://registry.npmjs.org/saucelabs/-/saucelabs-1.5.0.tgz", @@ -23249,21 +23067,6 @@ "integrity": "sha512-GNzQvQTOIP6RyTfE2Qxb8ZVlNmw0n88vp1szwWRimP02mnTsx3Wtn5qRdqY9w2XduFNUgvOwhNnQsjwCp+kqaQ==", "dev": true }, - "tar-stream": { - "version": "1.6.2", - "resolved": "https://registry.npmjs.org/tar-stream/-/tar-stream-1.6.2.tgz", - "integrity": "sha512-rzS0heiNf8Xn7/mpdSVVSMAWAoy9bfb1WOTYC78Z0UQKeKa/CWS8FOq0lKGNa8DWKAn9gxjCvMLYc5PGXYlK2A==", - "dev": true, - "requires": { - "bl": "^1.0.0", - "buffer-alloc": "^1.2.0", - "end-of-stream": "^1.0.0", - "fs-constants": "^1.0.0", - "readable-stream": "^2.3.0", - "to-buffer": "^1.1.1", - "xtend": "^4.0.0" - } - }, "temp-fs": { "version": "0.9.9", "resolved": "https://registry.npmjs.org/temp-fs/-/temp-fs-0.9.9.tgz", @@ -23491,12 +23294,6 @@ "is-negated-glob": "^1.0.0" } }, - "to-buffer": { - "version": "1.1.1", - "resolved": "https://registry.npmjs.org/to-buffer/-/to-buffer-1.1.1.tgz", - "integrity": "sha512-lx9B5iv7msuFYE3dytT+KE5tap+rNYw+K4jVkb9R/asAb+pbBSM17jtunHplhBe6RRJdZx3Pn2Jph24O32mOVg==", - "dev": true - }, "to-factory": { "version": "1.0.0", "resolved": "https://registry.npmjs.org/to-factory/-/to-factory-1.0.0.tgz", @@ -24313,12 +24110,6 @@ "integrity": "sha1-HCQ6ULWVwb5Up1S/7OhWO5/42BM=", "dev": true }, - "vargs": { - "version": "0.1.0", - "resolved": "https://registry.npmjs.org/vargs/-/vargs-0.1.0.tgz", - "integrity": "sha1-a2GE2mUgzDIEzhtAfKwm2SYJ6/8=", - "dev": true - }, "vary": { "version": "1.1.2", "resolved": "https://registry.npmjs.org/vary/-/vary-1.1.2.tgz", @@ -24507,53 +24298,6 @@ "defaults": "^1.0.3" } }, - "wd": { - "version": "1.11.2", - "resolved": "https://registry.npmjs.org/wd/-/wd-1.11.2.tgz", - "integrity": "sha512-zXJY9ARjQQYN2LatLTRcW39EYzIVqKNhGpp4XWJmRgHBioG4FoenIOsoVbaO8lnFGgv31V99kAy5hB4eWGIwzA==", - "dev": true, - "requires": { - "archiver": "2.1.1", - "async": "2.0.1", - "lodash": "4.17.11", - "mkdirp": "^0.5.1", - "q": "1.4.1", - "request": "2.88.0", - "vargs": "0.1.0" - }, - "dependencies": { - "async": { - "version": "2.0.1", - "resolved": "https://registry.npmjs.org/async/-/async-2.0.1.tgz", - "integrity": "sha1-twnMAoCpw28J9FNr6CPIOKkEniU=", - "dev": true, - "requires": { - "lodash": "^4.8.0" - } - }, - "lodash": { - "version": "4.17.11", - "resolved": "https://registry.npmjs.org/lodash/-/lodash-4.17.11.tgz", - "integrity": "sha512-cQKh8igo5QUhZ7lg38DYWAxMvjSAKG0A8wGSVimP07SIUEK2UO+arSRKbRZWtelMtN5V0Hkwh5ryOto/SshYIg==", - "dev": true - }, - "minimist": { - "version": "0.0.8", - "resolved": "http://registry.npmjs.org/minimist/-/minimist-0.0.8.tgz", - "integrity": "sha1-hX/Kv8M5fSYluCKCYuhqp6ARsF0=", - "dev": true - }, - "mkdirp": { - "version": "0.5.1", - "resolved": "http://registry.npmjs.org/mkdirp/-/mkdirp-0.5.1.tgz", - "integrity": "sha1-MAV0OOrGz3+MR2fzhkjWaX11yQM=", - "dev": true, - "requires": { - "minimist": "0.0.8" - } - } - } - }, "weak-map": { "version": "1.0.0", "resolved": "https://registry.npmjs.org/weak-map/-/weak-map-1.0.0.tgz", @@ -25602,26 +25346,6 @@ "resolved": "https://registry.npmjs.org/zepto/-/zepto-1.2.0.tgz", "integrity": "sha1-4Se9nmb9hGvl6rSME5SIL3wOT5g=" }, - "zip-stream": { - "version": "1.2.0", - "resolved": "https://registry.npmjs.org/zip-stream/-/zip-stream-1.2.0.tgz", - "integrity": "sha1-qLxF9MG0lpnGuQGYuqyqzbzUugQ=", - "dev": true, - "requires": { - "archiver-utils": "^1.3.0", - "compress-commons": "^1.2.0", - "lodash": "^4.8.0", - "readable-stream": "^2.0.0" - }, - "dependencies": { - "lodash": { - "version": "4.17.11", - "resolved": "https://registry.npmjs.org/lodash/-/lodash-4.17.11.tgz", - "integrity": "sha512-cQKh8igo5QUhZ7lg38DYWAxMvjSAKG0A8wGSVimP07SIUEK2UO+arSRKbRZWtelMtN5V0Hkwh5ryOto/SshYIg==", - "dev": true - } - } - }, "zone.js": { "version": "0.11.4", "resolved": "https://registry.npmjs.org/zone.js/-/zone.js-0.11.4.tgz", diff --git a/package.json b/package.json index c4559c3cb3..c777affd0c 100644 --- a/package.json +++ b/package.json @@ -20,7 +20,7 @@ "docs:start": "npm start -- docs --port 4100", "docs:serve": "npm-run-all docs:prepare docs:start", "docs:build": "npm-run-all docs:prepare docs:prod docs:dirs", - "docs:prod": "npm run build -- docs --configuration production --base-href '/nebular/'", + "docs:prod": "npm run build -- docs --configuration production-wp --base-href '/nebular/'", "docs:dirs": "npm-run-all -s docs:copy-index docs:sitemap", "docs:copy-index": "gulp docs-copy-index", "docs:sitemap": "gulp create-sitemap", @@ -37,6 +37,7 @@ "build:bootstrap": "cp -r src/framework/bootstrap dist", "build:dev-schematics": "gulp build-development-schematics", "test": "ng test", + "test:packages": "npm-run-all \"test theme -- --code-coverage --watch=false\" test:schematics \"test auth -- --code-coverage --watch=false\" \"test moment -- --code-coverage --watch=false\" \"test security -- --code-coverage --watch=false\" \"test date-fns -- --code-coverage --watch=false\" \"test firebase-auth -- --code-coverage --watch=false\" \"test eva-icons -- --code-coverage --watch=false\"", "test:wp": "ng test --configuration=production-wp", "test:coverage": "rimraf coverage && ng test playground --code-coverage --watch=false", "test:schematics": "gulp build-packages-schematics-for-test && jasmine dist/**/*.spec.js", @@ -44,12 +45,7 @@ "lint:styles": "stylelint ./src/framework/**/*.scss && stylelint ./docs/**/*.scss", "lint:fix": "lint-staged --config ./.lintstagedrc-fix.json", "e2e": "ng e2e playground-e2e", - "e2e:wp": "ng e2e playground-e2e --configuration:production-wp", "ci:lint": "npm-run-all -p lint lint:styles", - "ci:docs": "npm run docs:build", - "ci:build": "npm-run-all build:packages build:wp", - "ci:test": "rimraf coverage && npm run build:package && npm run test:wp -- --code-coverage --watch=false && npm run test:schematics", - "ci:e2e": "npm-run-all build:package e2e:wp", "version:bump": "gulp version", "version:changelog": "conventional-changelog -- -p angular -i CHANGELOG.md -s", "release:validate": "npm-run-all build:packages build:wp ci:lint e2e:wp && npm run test:wp -- --watch=false", @@ -140,7 +136,6 @@ "karma-coverage": "~2.0.3", "karma-jasmine": "~4.0.0", "karma-jasmine-html-reporter": "~1.7.0", - "karma-sauce-launcher": "1.2.0", "karma-spec-reporter": "0.0.32", "lint-staged": "^11.2.3", "ng-packagr": "^12.2.3", diff --git a/packages-smoke/README.md b/packages-smoke/README.md index 1b32932417..d3ef78ba44 100644 --- a/packages-smoke/README.md +++ b/packages-smoke/README.md @@ -7,7 +7,7 @@ We just install newly build packages in this app and build it in production mode 1. Run `npm run build:packages` in the project root. 2. Copy built packages from `dist/*` to `packages-smoke/.lib/` -3. Go to folder packages-smoke run `npm install` +3. Go to `packages-smoke` directory and run `npm install` 4. Verifying application build: - `npm run build -- --configuration=production` - `npm run e2e` diff --git a/packages-smoke/e2e/src/app.e2e-spec.ts b/packages-smoke/e2e/src/app.e2e-spec.ts index 10fd985b8d..0b1c96e2ad 100644 --- a/packages-smoke/e2e/src/app.e2e-spec.ts +++ b/packages-smoke/e2e/src/app.e2e-spec.ts @@ -1,11 +1,10 @@ import { browser, by, element } from 'protractor'; describe('workspace-project App', () => { - it('should render', done => { - browser.get('/') - .then(() => { - expect(element(by.css('bs-root')).getText()).toContain('Nebular Works!!!'); - done(); - }); + it('should render', (done: DoneFn) => { + browser.get('/').then(() => { + expect(element(by.css('bs-root')).getText()).toContain('Nebular Works!!!'); + done(); + }); }); }); diff --git a/packages-smoke/package-lock.json b/packages-smoke/package-lock.json index 89cbc35d8c..137c0f530e 100644 --- a/packages-smoke/package-lock.json +++ b/packages-smoke/package-lock.json @@ -1756,6 +1756,21 @@ "to-fast-properties": "^2.0.0" } }, + "@cspotcode/source-map-consumer": { + "version": "0.8.0", + "resolved": "https://registry.npmjs.org/@cspotcode/source-map-consumer/-/source-map-consumer-0.8.0.tgz", + "integrity": "sha512-41qniHzTU8yAGbCp04ohlmSrZf8bkf/iJsl3V0dRGsQN/5GFfx+LbCSsCpp2gqrqjTVg/K6O8ycoV35JIwAzAg==", + "dev": true + }, + "@cspotcode/source-map-support": { + "version": "0.7.0", + "resolved": "https://registry.npmjs.org/@cspotcode/source-map-support/-/source-map-support-0.7.0.tgz", + "integrity": "sha512-X4xqRHqN8ACt2aHVe51OxeA2HjbcL4MqFqXkrmQszJ1NOUuUu5u6Vqx/0lZSVNku7velL5FC/s5uEAj1lsBMhA==", + "dev": true, + "requires": { + "@cspotcode/source-map-consumer": "0.8.0" + } + }, "@csstools/convert-colors": { "version": "1.4.0", "resolved": "https://registry.npmjs.org/@csstools/convert-colors/-/convert-colors-1.4.0.tgz", @@ -1872,30 +1887,65 @@ "version": "file:.lib/auth", "requires": { "tslib": "^2.3.0" + }, + "dependencies": { + "tslib": { + "version": "2.3.1", + "resolved": "https://registry.npmjs.org/tslib/-/tslib-2.3.1.tgz", + "integrity": "sha512-77EbyPPpMz+FRFRuAFlWMtmgUWGe9UOG2Z25NqCwiIjRhOf5iKGuzSe5P2w1laq+FkRy4p+PCuVkJSGkzTEKVw==" + } } }, "@nebular/date-fns": { "version": "file:.lib/date-fns", "requires": { "tslib": "^2.3.0" + }, + "dependencies": { + "tslib": { + "version": "2.3.1", + "resolved": "https://registry.npmjs.org/tslib/-/tslib-2.3.1.tgz", + "integrity": "sha512-77EbyPPpMz+FRFRuAFlWMtmgUWGe9UOG2Z25NqCwiIjRhOf5iKGuzSe5P2w1laq+FkRy4p+PCuVkJSGkzTEKVw==" + } } }, "@nebular/eva-icons": { "version": "file:.lib/eva-icons", "requires": { "tslib": "^2.3.0" + }, + "dependencies": { + "tslib": { + "version": "2.3.1", + "resolved": "https://registry.npmjs.org/tslib/-/tslib-2.3.1.tgz", + "integrity": "sha512-77EbyPPpMz+FRFRuAFlWMtmgUWGe9UOG2Z25NqCwiIjRhOf5iKGuzSe5P2w1laq+FkRy4p+PCuVkJSGkzTEKVw==" + } } }, "@nebular/moment": { "version": "file:.lib/moment", "requires": { "tslib": "^2.3.0" + }, + "dependencies": { + "tslib": { + "version": "2.3.1", + "resolved": "https://registry.npmjs.org/tslib/-/tslib-2.3.1.tgz", + "integrity": "sha512-77EbyPPpMz+FRFRuAFlWMtmgUWGe9UOG2Z25NqCwiIjRhOf5iKGuzSe5P2w1laq+FkRy4p+PCuVkJSGkzTEKVw==" + } } }, "@nebular/security": { "version": "file:.lib/security", "requires": { "tslib": "^2.3.0" + }, + "dependencies": { + "tslib": { + "version": "2.3.1", + "resolved": "https://registry.npmjs.org/tslib/-/tslib-2.3.1.tgz", + "integrity": "sha512-77EbyPPpMz+FRFRuAFlWMtmgUWGe9UOG2Z25NqCwiIjRhOf5iKGuzSe5P2w1laq+FkRy4p+PCuVkJSGkzTEKVw==" + } } }, "@nebular/theme": { @@ -1903,6 +1953,18 @@ "requires": { "intersection-observer": "0.7.0", "tslib": "^2.3.0" + }, + "dependencies": { + "intersection-observer": { + "version": "0.7.0", + "resolved": "https://registry.npmjs.org/intersection-observer/-/intersection-observer-0.7.0.tgz", + "integrity": "sha512-Id0Fij0HsB/vKWGeBe9PxeY45ttRiBmhFyyt/geBdDHBYNctMRTE3dC1U3ujzz3lap+hVXlEcVaB56kZP/eEUg==" + }, + "tslib": { + "version": "2.3.1", + "resolved": "https://registry.npmjs.org/tslib/-/tslib-2.3.1.tgz", + "integrity": "sha512-77EbyPPpMz+FRFRuAFlWMtmgUWGe9UOG2Z25NqCwiIjRhOf5iKGuzSe5P2w1laq+FkRy4p+PCuVkJSGkzTEKVw==" + } } }, "@ngtools/webpack": { @@ -2258,6 +2320,30 @@ "integrity": "sha512-L7z9BgrNEcYyUYtF+HaEfiS5ebkh9jXqbszz7pC0hRBPaatV0XjSD3+eHrpqFemQfgwiFF0QPIarnIihIDn7OA==", "dev": true }, + "@tsconfig/node10": { + "version": "1.0.8", + "resolved": "https://registry.npmjs.org/@tsconfig/node10/-/node10-1.0.8.tgz", + "integrity": "sha512-6XFfSQmMgq0CFLY1MslA/CPUfhIL919M1rMsa5lP2P097N2Wd1sSX0tx1u4olM16fLNhtHZpRhedZJphNJqmZg==", + "dev": true + }, + "@tsconfig/node12": { + "version": "1.0.9", + "resolved": "https://registry.npmjs.org/@tsconfig/node12/-/node12-1.0.9.tgz", + "integrity": "sha512-/yBMcem+fbvhSREH+s14YJi18sp7J9jpuhYByADT2rypfajMZZN4WQ6zBGgBKp53NKmqI36wFYDb3yaMPurITw==", + "dev": true + }, + "@tsconfig/node14": { + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/@tsconfig/node14/-/node14-1.0.1.tgz", + "integrity": "sha512-509r2+yARFfHHE7T6Puu2jjkoycftovhXRqW328PDXTVGKihlb1P8Z9mMZH04ebyajfRY7dedfGynlrFHJUQCg==", + "dev": true + }, + "@tsconfig/node16": { + "version": "1.0.2", + "resolved": "https://registry.npmjs.org/@tsconfig/node16/-/node16-1.0.2.tgz", + "integrity": "sha512-eZxlbI8GZscaGS7kkc/trHTT5xgrjH3/1n2JDwusC9iahPKWMRvRjJSAN5mCXviuTGQ/lHnhvv8Q1YTpnfz9gA==", + "dev": true + }, "@types/body-parser": { "version": "1.19.1", "resolved": "https://registry.npmjs.org/@types/body-parser/-/body-parser-1.19.1.tgz", @@ -2399,6 +2485,12 @@ "integrity": "sha512-//oorEZjL6sbPcKUaCdIGlIUeH26mgzimjBB77G6XRgnDl/L5wOnpyBGRe/Mmf5CVW3PwEBE1NjiMZ/ssFh4wA==", "dev": true }, + "@types/q": { + "version": "0.0.32", + "resolved": "https://registry.npmjs.org/@types/q/-/q-0.0.32.tgz", + "integrity": "sha1-vShOV8hPEyXacCur/IKlMoGQwMU=", + "dev": true + }, "@types/qs": { "version": "6.9.7", "resolved": "https://registry.npmjs.org/@types/qs/-/qs-6.9.7.tgz", @@ -2411,6 +2503,12 @@ "integrity": "sha512-EEhsLsD6UsDM1yFhAvy0Cjr6VwmpMWqFBCb9w07wVugF7w9nfajxLuVmngTIpgS6svCnm6Vaw+MZhoDCKnOfsw==", "dev": true }, + "@types/selenium-webdriver": { + "version": "3.0.19", + "resolved": "https://registry.npmjs.org/@types/selenium-webdriver/-/selenium-webdriver-3.0.19.tgz", + "integrity": "sha512-OFUilxQg+rWL2FMxtmIgCkUDlJB6pskkpvmew7yeXfzzsOBb5rc+y2+DjHm+r3r1ZPPcJefK3DveNSYWGiy68g==", + "dev": true + }, "@types/serve-static": { "version": "1.13.10", "resolved": "https://registry.npmjs.org/@types/serve-static/-/serve-static-1.13.10.tgz", @@ -2823,6 +2921,12 @@ "regex-parser": "^2.2.11" } }, + "adm-zip": { + "version": "0.4.16", + "resolved": "https://registry.npmjs.org/adm-zip/-/adm-zip-0.4.16.tgz", + "integrity": "sha512-TFi4HBKSGfIKsK5YCkKaaFG2m4PEDyViZmEwof3MTIgzimHLto6muaHVpbrljdIvIrFZzEq/p4nafOeLcYegrg==", + "dev": true + }, "after": { "version": "0.8.2", "resolved": "https://registry.npmjs.org/after/-/after-0.8.2.tgz", @@ -2985,6 +3089,12 @@ } } }, + "arg": { + "version": "4.1.3", + "resolved": "https://registry.npmjs.org/arg/-/arg-4.1.3.tgz", + "integrity": "sha512-58S9QDqG0Xx27YwPSt9fJxivjYl432YCwfDMfZ+71RAqUrZef7LrKQZ3LHLOwCS4FLNBplP533Zx895SeOCHvA==", + "dev": true + }, "argparse": { "version": "1.0.10", "resolved": "https://registry.npmjs.org/argparse/-/argparse-1.0.10.tgz", @@ -3052,6 +3162,12 @@ "integrity": "sha512-wGUIVQXuehL5TCqQun8OW81jGzAWycqzFF8lFp+GOM5BXLYj3bKNsYC4daB7n6XjCqxQA/qgTJ+8ANR3acjrog==", "dev": true }, + "arrify": { + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/arrify/-/arrify-1.0.1.tgz", + "integrity": "sha1-iYUI2iIm84DfkEcoRWhJwVAaSw0=", + "dev": true + }, "asn1": { "version": "0.2.4", "resolved": "https://registry.npmjs.org/asn1/-/asn1-0.2.4.tgz", @@ -3409,6 +3525,15 @@ "integrity": "sha512-gaqbzQPqOoamawKg0LGVd7SzLgXS+JH61oWprSLH+P+abTczqJbhTR8CmJ2u9/bUYNmHTGJx/UEmn6doAvvuig==", "dev": true }, + "blocking-proxy": { + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/blocking-proxy/-/blocking-proxy-1.0.1.tgz", + "integrity": "sha512-KE8NFMZr3mN2E0HcvCgRtX7DjhiIQrwle+nSVJVC/yqFb9+xznHl2ZcoBp2L9qzkI4t4cBFJ1efXF8Dwi132RA==", + "dev": true, + "requires": { + "minimist": "^1.2.0" + } + }, "body-parser": { "version": "1.19.0", "resolved": "https://registry.npmjs.org/body-parser/-/body-parser-1.19.0.tgz", @@ -3973,6 +4098,45 @@ "picocolors": "^1.0.0" } }, + "browserstack": { + "version": "1.6.1", + "resolved": "https://registry.npmjs.org/browserstack/-/browserstack-1.6.1.tgz", + "integrity": "sha512-GxtFjpIaKdbAyzHfFDKixKO8IBT7wR3NjbzrGc78nNs/Ciys9wU3/nBtsqsWv5nDSrdI5tz0peKuzCPuNXNUiw==", + "dev": true, + "requires": { + "https-proxy-agent": "^2.2.1" + }, + "dependencies": { + "agent-base": { + "version": "4.3.0", + "resolved": "https://registry.npmjs.org/agent-base/-/agent-base-4.3.0.tgz", + "integrity": "sha512-salcGninV0nPrwpGNn4VTXBb1SOuXQBiqbrNXoeizJsHrsL6ERFM2Ne3JUSBWRE6aeNJI2ROP/WEEIDUiDe3cg==", + "dev": true, + "requires": { + "es6-promisify": "^5.0.0" + } + }, + "debug": { + "version": "3.2.7", + "resolved": "https://registry.npmjs.org/debug/-/debug-3.2.7.tgz", + "integrity": "sha512-CFjzYYAi4ThfiQvizrFQevTTXHtnCqWfe7x1AhgEscTz6ZbLbfoLRLPugTQyBth6f8ZERVUSyWHFD/7Wu4t1XQ==", + "dev": true, + "requires": { + "ms": "^2.1.1" + } + }, + "https-proxy-agent": { + "version": "2.2.4", + "resolved": "https://registry.npmjs.org/https-proxy-agent/-/https-proxy-agent-2.2.4.tgz", + "integrity": "sha512-OmvfoQ53WLjtA9HeYP9RNrWMJzzAz1JGaSFr1nijg0PVR1JaD/xbJq1mdEIIlxGpXp9eSe/O2LgU9DJmTPd0Eg==", + "dev": true, + "requires": { + "agent-base": "^4.3.0", + "debug": "^3.1.0" + } + } + } + }, "bs-recipes": { "version": "1.3.4", "resolved": "https://registry.npmjs.org/bs-recipes/-/bs-recipes-1.3.4.tgz", @@ -4629,6 +4793,12 @@ "yaml": "^1.10.0" } }, + "create-require": { + "version": "1.1.1", + "resolved": "https://registry.npmjs.org/create-require/-/create-require-1.1.1.tgz", + "integrity": "sha512-dcKFX3jn0MpIaXjisoRvexIJVEKzaq7z2rZKxf+MSr9TkdmHmsU4m2lcLojrj/FHl8mk5VxMmYA+ftRkP/3oKQ==", + "dev": true + }, "critters": { "version": "0.0.11", "resolved": "https://registry.npmjs.org/critters/-/critters-0.0.11.tgz", @@ -5111,6 +5281,11 @@ "whatwg-url": "^8.0.0" } }, + "date-fns": { + "version": "2.25.0", + "resolved": "https://registry.npmjs.org/date-fns/-/date-fns-2.25.0.tgz", + "integrity": "sha512-ovYRFnTrbGPD4nqaEqescPEv1mNwvt+UTqI3Ay9SzNtey9NZnYu6E2qCcBBgJ6/2VF1zGGygpyTDITqpQQ5e+w==" + }, "date-format": { "version": "3.0.0", "resolved": "https://registry.npmjs.org/date-format/-/date-format-3.0.0.tgz", @@ -5343,6 +5518,12 @@ "integrity": "sha1-gGZJMmzqp8qjMG112YXqJ0i6kTw=", "dev": true }, + "diff": { + "version": "4.0.2", + "resolved": "https://registry.npmjs.org/diff/-/diff-4.0.2.tgz", + "integrity": "sha512-58lmxKSA4BNyLz+HHMUzlOEpg09FV+ev6ZMe3vJihgdxzgcwZ8VoEEPmALCZG9LmqfVoNMMKpttIYTVG6uDY7A==", + "dev": true + }, "dir-glob": { "version": "3.0.1", "resolved": "https://registry.npmjs.org/dir-glob/-/dir-glob-3.0.1.tgz", @@ -5735,6 +5916,21 @@ "integrity": "sha512-MgtWFl5No+4S3TmhDmCz2ObFGm6lEpTnzbQi+Dd+pw4mlTIZTmM2iAs5gRlmx5zS9luzobCSBSI90JM/1/JgOw==", "dev": true }, + "es6-promise": { + "version": "4.2.8", + "resolved": "https://registry.npmjs.org/es6-promise/-/es6-promise-4.2.8.tgz", + "integrity": "sha512-HJDGx5daxeIvxdBxvG2cb9g4tEvwIk3i8+nhX0yGrYmZUzbkdg8QbDevheDB8gd0//uPj4c1EQua8Q+MViT0/w==", + "dev": true + }, + "es6-promisify": { + "version": "5.0.0", + "resolved": "https://registry.npmjs.org/es6-promisify/-/es6-promisify-5.0.0.tgz", + "integrity": "sha1-UQnWLz5W6pZ8S2NQWu8IKRyKUgM=", + "dev": true, + "requires": { + "es6-promise": "^4.0.3" + } + }, "esbuild-android-arm64": { "version": "0.13.8", "resolved": "https://registry.npmjs.org/esbuild-android-arm64/-/esbuild-android-arm64-0.13.8.tgz", @@ -6309,6 +6505,12 @@ "strip-eof": "^1.0.0" } }, + "exit": { + "version": "0.1.2", + "resolved": "https://registry.npmjs.org/exit/-/exit-0.1.2.tgz", + "integrity": "sha1-BjJjj42HfMghB9MKD/8aF8uhzQw=", + "dev": true + }, "expand-brackets": { "version": "2.1.4", "resolved": "https://registry.npmjs.org/expand-brackets/-/expand-brackets-2.1.4.tgz", @@ -7470,6 +7672,12 @@ "dev": true, "optional": true }, + "immediate": { + "version": "3.0.6", + "resolved": "https://registry.npmjs.org/immediate/-/immediate-3.0.6.tgz", + "integrity": "sha1-nbHb0Pr43m++D13V5Wu2BigN5ps=", + "dev": true + }, "immutable": { "version": "3.8.2", "resolved": "https://registry.npmjs.org/immutable/-/immutable-3.8.2.tgz", @@ -7691,11 +7899,6 @@ "ipaddr.js": "^1.9.0" } }, - "intersection-observer": { - "version": "0.7.0", - "resolved": "https://registry.npmjs.org/intersection-observer/-/intersection-observer-0.7.0.tgz", - "integrity": "sha512-Id0Fij0HsB/vKWGeBe9PxeY45ttRiBmhFyyt/geBdDHBYNctMRTE3dC1U3ujzz3lap+hVXlEcVaB56kZP/eEUg==" - }, "ip": { "version": "1.1.5", "resolved": "https://registry.npmjs.org/ip/-/ip-1.1.5.tgz", @@ -8119,12 +8322,46 @@ } } }, + "jasmine": { + "version": "2.8.0", + "resolved": "https://registry.npmjs.org/jasmine/-/jasmine-2.8.0.tgz", + "integrity": "sha1-awicChFXax8W3xG4AUbZHU6Lij4=", + "dev": true, + "requires": { + "exit": "^0.1.2", + "glob": "^7.0.6", + "jasmine-core": "~2.8.0" + }, + "dependencies": { + "jasmine-core": { + "version": "2.8.0", + "resolved": "https://registry.npmjs.org/jasmine-core/-/jasmine-core-2.8.0.tgz", + "integrity": "sha1-vMl5rh+f0FcB5F5S5l06XWPxok4=", + "dev": true + } + } + }, "jasmine-core": { "version": "3.8.0", "resolved": "https://registry.npmjs.org/jasmine-core/-/jasmine-core-3.8.0.tgz", "integrity": "sha512-zl0nZWDrmbCiKns0NcjkFGYkVTGCPUgoHypTaj+G2AzaWus7QGoXARSlYsSle2VRpSdfJmM+hzmFKzQNhF2kHg==", "dev": true }, + "jasmine-spec-reporter": { + "version": "5.0.2", + "resolved": "https://registry.npmjs.org/jasmine-spec-reporter/-/jasmine-spec-reporter-5.0.2.tgz", + "integrity": "sha512-6gP1LbVgJ+d7PKksQBc2H0oDGNRQI3gKUsWlswKaQ2fif9X5gzhQcgM5+kiJGCQVurOG09jqNhk7payggyp5+g==", + "dev": true, + "requires": { + "colors": "1.4.0" + } + }, + "jasminewd2": { + "version": "2.2.0", + "resolved": "https://registry.npmjs.org/jasminewd2/-/jasminewd2-2.2.0.tgz", + "integrity": "sha1-43zwsX8ZnM4jvqcbIDk5Uka07E4=", + "dev": true + }, "jest-worker": { "version": "27.3.1", "resolved": "https://registry.npmjs.org/jest-worker/-/jest-worker-27.3.1.tgz", @@ -8326,6 +8563,44 @@ "verror": "1.10.0" } }, + "jszip": { + "version": "3.7.1", + "resolved": "https://registry.npmjs.org/jszip/-/jszip-3.7.1.tgz", + "integrity": "sha512-ghL0tz1XG9ZEmRMcEN2vt7xabrDdqHHeykgARpmZ0BiIctWxM47Vt63ZO2dnp4QYt/xJVLLy5Zv1l/xRdh2byg==", + "dev": true, + "requires": { + "lie": "~3.3.0", + "pako": "~1.0.2", + "readable-stream": "~2.3.6", + "set-immediate-shim": "~1.0.1" + }, + "dependencies": { + "readable-stream": { + "version": "2.3.7", + "resolved": "https://registry.npmjs.org/readable-stream/-/readable-stream-2.3.7.tgz", + "integrity": "sha512-Ebho8K4jIbHAxnuxi7o42OrZgF/ZTNcsZj6nRKyUmkhLFq8CHItp/fy6hQZuZmP/n3yZ9VBUbp4zz/mX8hmYPw==", + "dev": true, + "requires": { + "core-util-is": "~1.0.0", + "inherits": "~2.0.3", + "isarray": "~1.0.0", + "process-nextick-args": "~2.0.0", + "safe-buffer": "~5.1.1", + "string_decoder": "~1.1.1", + "util-deprecate": "~1.0.1" + } + }, + "string_decoder": { + "version": "1.1.1", + "resolved": "https://registry.npmjs.org/string_decoder/-/string_decoder-1.1.1.tgz", + "integrity": "sha512-n/ShnvDi6FHbbVfviro+WojiFzv+s8MPMHBczVePfUpDJLwoLT0ht1l4YwBCbi8pJAveEEdnkHyPyTP/mzRfwg==", + "dev": true, + "requires": { + "safe-buffer": "~5.1.0" + } + } + } + }, "karma": { "version": "6.3.6", "resolved": "https://registry.npmjs.org/karma/-/karma-6.3.6.tgz", @@ -8598,6 +8873,15 @@ "webpack-sources": "^1.2.0" } }, + "lie": { + "version": "3.3.0", + "resolved": "https://registry.npmjs.org/lie/-/lie-3.3.0.tgz", + "integrity": "sha512-UaiMJzeWRlEujzAuw5LokY1L5ecNQYZKfmyZ9L7wDHb/p5etKaxXhohBcrw0EYby+G/NA52vRSN4N39dxHAIwQ==", + "dev": true, + "requires": { + "immediate": "~3.0.5" + } + }, "lilconfig": { "version": "2.0.3", "resolved": "https://registry.npmjs.org/lilconfig/-/lilconfig-2.0.3.tgz", @@ -8891,6 +9175,12 @@ } } }, + "make-error": { + "version": "1.3.6", + "resolved": "https://registry.npmjs.org/make-error/-/make-error-1.3.6.tgz", + "integrity": "sha512-s8UhlNe7vPKomQhC1qFelMokr/Sc3AgNbso3n74mVPA5LTZwkB9NlXf4XPamLxJE8h0gh73rM94xvwRT2CVInw==", + "dev": true + }, "make-fetch-happen": { "version": "9.1.0", "resolved": "https://registry.npmjs.org/make-fetch-happen/-/make-fetch-happen-9.1.0.tgz", @@ -11667,6 +11957,303 @@ "retry": "^0.12.0" } }, + "protractor": { + "version": "7.0.0", + "resolved": "https://registry.npmjs.org/protractor/-/protractor-7.0.0.tgz", + "integrity": "sha512-UqkFjivi4GcvUQYzqGYNe0mLzfn5jiLmO8w9nMhQoJRLhy2grJonpga2IWhI6yJO30LibWXJJtA4MOIZD2GgZw==", + "dev": true, + "requires": { + "@types/q": "^0.0.32", + "@types/selenium-webdriver": "^3.0.0", + "blocking-proxy": "^1.0.0", + "browserstack": "^1.5.1", + "chalk": "^1.1.3", + "glob": "^7.0.3", + "jasmine": "2.8.0", + "jasminewd2": "^2.1.0", + "q": "1.4.1", + "saucelabs": "^1.5.0", + "selenium-webdriver": "3.6.0", + "source-map-support": "~0.4.0", + "webdriver-js-extender": "2.1.0", + "webdriver-manager": "^12.1.7", + "yargs": "^15.3.1" + }, + "dependencies": { + "ansi-regex": { + "version": "2.1.1", + "resolved": "https://registry.npmjs.org/ansi-regex/-/ansi-regex-2.1.1.tgz", + "integrity": "sha1-w7M6te42DYbg5ijwRorn7yfWVN8=", + "dev": true + }, + "ansi-styles": { + "version": "2.2.1", + "resolved": "https://registry.npmjs.org/ansi-styles/-/ansi-styles-2.2.1.tgz", + "integrity": "sha1-tDLdM1i2NM914eRmQ2gkBTPB3b4=", + "dev": true + }, + "array-union": { + "version": "1.0.2", + "resolved": "https://registry.npmjs.org/array-union/-/array-union-1.0.2.tgz", + "integrity": "sha1-mjRBDk9OPaI96jdb5b5w8kd47Dk=", + "dev": true, + "requires": { + "array-uniq": "^1.0.1" + } + }, + "chalk": { + "version": "1.1.3", + "resolved": "https://registry.npmjs.org/chalk/-/chalk-1.1.3.tgz", + "integrity": "sha1-qBFcVeSnAv5NFQq9OHKCKn4J/Jg=", + "dev": true, + "requires": { + "ansi-styles": "^2.2.1", + "escape-string-regexp": "^1.0.2", + "has-ansi": "^2.0.0", + "strip-ansi": "^3.0.0", + "supports-color": "^2.0.0" + } + }, + "cliui": { + "version": "6.0.0", + "resolved": "https://registry.npmjs.org/cliui/-/cliui-6.0.0.tgz", + "integrity": "sha512-t6wbgtoCXvAzst7QgXxJYqPt0usEfbgQdftEPbLL/cvv6HPE5VgvqCuAIDR0NgU52ds6rFwqrgakNLrHEjCbrQ==", + "dev": true, + "requires": { + "string-width": "^4.2.0", + "strip-ansi": "^6.0.0", + "wrap-ansi": "^6.2.0" + }, + "dependencies": { + "ansi-regex": { + "version": "5.0.1", + "resolved": "https://registry.npmjs.org/ansi-regex/-/ansi-regex-5.0.1.tgz", + "integrity": "sha512-quJQXlTSUGL2LH9SUXo8VwsY4soanhgo6LNSm84E1LBcE8s3O0wpdiRzyR9z/ZZJMlMWv37qOOb9pdJlMUEKFQ==", + "dev": true + }, + "strip-ansi": { + "version": "6.0.1", + "resolved": "https://registry.npmjs.org/strip-ansi/-/strip-ansi-6.0.1.tgz", + "integrity": "sha512-Y38VPSHcqkFrCpFnQ9vuSXmquuv5oXOKpGeT6aGrr3o3Gc9AlVa6JBfUSOCnbxGGZF+/0ooI7KrPuUSztUdU5A==", + "dev": true, + "requires": { + "ansi-regex": "^5.0.1" + } + } + } + }, + "color-convert": { + "version": "2.0.1", + "resolved": "https://registry.npmjs.org/color-convert/-/color-convert-2.0.1.tgz", + "integrity": "sha512-RRECPsj7iu/xb5oKYcsFHSppFNnsj/52OVTRKb4zP5onXwVF3zVmmToNcOfGC+CRDpfK/U584fMg38ZHCaElKQ==", + "dev": true, + "requires": { + "color-name": "~1.1.4" + } + }, + "color-name": { + "version": "1.1.4", + "resolved": "https://registry.npmjs.org/color-name/-/color-name-1.1.4.tgz", + "integrity": "sha512-dOy+3AuW3a2wNbZHIuMZpTcgjGuLU/uBL/ubcZF9OXbDo8ff4O8yVp5Bf0efS8uEoYo5q4Fx7dY9OgQGXgAsQA==", + "dev": true + }, + "del": { + "version": "2.2.2", + "resolved": "https://registry.npmjs.org/del/-/del-2.2.2.tgz", + "integrity": "sha1-wSyYHQZ4RshLyvhiz/kw2Qf/0ag=", + "dev": true, + "requires": { + "globby": "^5.0.0", + "is-path-cwd": "^1.0.0", + "is-path-in-cwd": "^1.0.0", + "object-assign": "^4.0.1", + "pify": "^2.0.0", + "pinkie-promise": "^2.0.0", + "rimraf": "^2.2.8" + } + }, + "globby": { + "version": "5.0.0", + "resolved": "https://registry.npmjs.org/globby/-/globby-5.0.0.tgz", + "integrity": "sha1-69hGZ8oNuzMLmbz8aOrCvFQ3Dg0=", + "dev": true, + "requires": { + "array-union": "^1.0.1", + "arrify": "^1.0.0", + "glob": "^7.0.3", + "object-assign": "^4.0.1", + "pify": "^2.0.0", + "pinkie-promise": "^2.0.0" + } + }, + "ini": { + "version": "1.3.8", + "resolved": "https://registry.npmjs.org/ini/-/ini-1.3.8.tgz", + "integrity": "sha512-JV/yugV2uzW5iMRSiZAyDtQd+nxtUnjeLt0acNdw98kKLrvuRVyB80tsREOE7yvGVgalhZ6RNXCmEHkUKBKxew==", + "dev": true + }, + "is-path-cwd": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/is-path-cwd/-/is-path-cwd-1.0.0.tgz", + "integrity": "sha1-0iXsIxMuie3Tj9p2dHLmLmXxEG0=", + "dev": true + }, + "is-path-in-cwd": { + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/is-path-in-cwd/-/is-path-in-cwd-1.0.1.tgz", + "integrity": "sha512-FjV1RTW48E7CWM7eE/J2NJvAEEVektecDBVBE5Hh3nM1Jd0kvhHtX68Pr3xsDf857xt3Y4AkwVULK1Vku62aaQ==", + "dev": true, + "requires": { + "is-path-inside": "^1.0.0" + } + }, + "is-path-inside": { + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/is-path-inside/-/is-path-inside-1.0.1.tgz", + "integrity": "sha1-jvW33lBDej/cprToZe96pVy0gDY=", + "dev": true, + "requires": { + "path-is-inside": "^1.0.1" + } + }, + "pify": { + "version": "2.3.0", + "resolved": "https://registry.npmjs.org/pify/-/pify-2.3.0.tgz", + "integrity": "sha1-7RQaasBDqEnqWISY59yosVMw6Qw=", + "dev": true + }, + "rimraf": { + "version": "2.7.1", + "resolved": "https://registry.npmjs.org/rimraf/-/rimraf-2.7.1.tgz", + "integrity": "sha512-uWjbaKIK3T1OSVptzX7Nl6PvQ3qAGtKEtVRjRuazjfL3Bx5eI409VZSqgND+4UNnmzLVdPj9FqFJNPqBZFve4w==", + "dev": true, + "requires": { + "glob": "^7.1.3" + } + }, + "semver": { + "version": "5.7.1", + "resolved": "https://registry.npmjs.org/semver/-/semver-5.7.1.tgz", + "integrity": "sha512-sauaDf/PZdVgrLTNYHRtpXa1iRiKcaebiKQ1BJdpQlWH2lCvexQdX55snPFyK7QzpudqbCI0qXFfOasHdyNDGQ==", + "dev": true + }, + "source-map": { + "version": "0.5.7", + "resolved": "https://registry.npmjs.org/source-map/-/source-map-0.5.7.tgz", + "integrity": "sha1-igOdLRAh0i0eoUyA2OpGi6LvP8w=", + "dev": true + }, + "source-map-support": { + "version": "0.4.18", + "resolved": "https://registry.npmjs.org/source-map-support/-/source-map-support-0.4.18.tgz", + "integrity": "sha512-try0/JqxPLF9nOjvSta7tVondkP5dwgyLDjVoyMDlmjugT2lRZ1OfsrYTkCd2hkDnJTKRbO/Rl3orm8vlsUzbA==", + "dev": true, + "requires": { + "source-map": "^0.5.6" + } + }, + "strip-ansi": { + "version": "3.0.1", + "resolved": "https://registry.npmjs.org/strip-ansi/-/strip-ansi-3.0.1.tgz", + "integrity": "sha1-ajhfuIU9lS1f8F0Oiq+UJ43GPc8=", + "dev": true, + "requires": { + "ansi-regex": "^2.0.0" + } + }, + "supports-color": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/supports-color/-/supports-color-2.0.0.tgz", + "integrity": "sha1-U10EXOa2Nj+kARcIRimZXp3zJMc=", + "dev": true + }, + "webdriver-manager": { + "version": "12.1.8", + "resolved": "https://registry.npmjs.org/webdriver-manager/-/webdriver-manager-12.1.8.tgz", + "integrity": "sha512-qJR36SXG2VwKugPcdwhaqcLQOD7r8P2Xiv9sfNbfZrKBnX243iAkOueX1yAmeNgIKhJ3YAT/F2gq6IiEZzahsg==", + "dev": true, + "requires": { + "adm-zip": "^0.4.9", + "chalk": "^1.1.1", + "del": "^2.2.0", + "glob": "^7.0.3", + "ini": "^1.3.4", + "minimist": "^1.2.0", + "q": "^1.4.1", + "request": "^2.87.0", + "rimraf": "^2.5.2", + "semver": "^5.3.0", + "xml2js": "^0.4.17" + } + }, + "wrap-ansi": { + "version": "6.2.0", + "resolved": "https://registry.npmjs.org/wrap-ansi/-/wrap-ansi-6.2.0.tgz", + "integrity": "sha512-r6lPcBGxZXlIcymEu7InxDMhdW0KDxpLgoFLcguasxCaJ/SOIZwINatK9KY/tf+ZrlywOKU0UDj3ATXUBfxJXA==", + "dev": true, + "requires": { + "ansi-styles": "^4.0.0", + "string-width": "^4.1.0", + "strip-ansi": "^6.0.0" + }, + "dependencies": { + "ansi-regex": { + "version": "5.0.1", + "resolved": "https://registry.npmjs.org/ansi-regex/-/ansi-regex-5.0.1.tgz", + "integrity": "sha512-quJQXlTSUGL2LH9SUXo8VwsY4soanhgo6LNSm84E1LBcE8s3O0wpdiRzyR9z/ZZJMlMWv37qOOb9pdJlMUEKFQ==", + "dev": true + }, + "ansi-styles": { + "version": "4.3.0", + "resolved": "https://registry.npmjs.org/ansi-styles/-/ansi-styles-4.3.0.tgz", + "integrity": "sha512-zbB9rCJAT1rbjiVDb2hqKFHNYLxgtk8NURxZ3IZwD3F6NtxbXZQCnnSi1Lkx+IDohdPlFp222wVALIheZJQSEg==", + "dev": true, + "requires": { + "color-convert": "^2.0.1" + } + }, + "strip-ansi": { + "version": "6.0.1", + "resolved": "https://registry.npmjs.org/strip-ansi/-/strip-ansi-6.0.1.tgz", + "integrity": "sha512-Y38VPSHcqkFrCpFnQ9vuSXmquuv5oXOKpGeT6aGrr3o3Gc9AlVa6JBfUSOCnbxGGZF+/0ooI7KrPuUSztUdU5A==", + "dev": true, + "requires": { + "ansi-regex": "^5.0.1" + } + } + } + }, + "yargs": { + "version": "15.4.1", + "resolved": "https://registry.npmjs.org/yargs/-/yargs-15.4.1.tgz", + "integrity": "sha512-aePbxDmcYW++PaqBsJ+HYUFwCdv4LVvdnhBy78E57PIor8/OVvhMrADFFEDh8DHDFRv/O9i3lPhsENjO7QX0+A==", + "dev": true, + "requires": { + "cliui": "^6.0.0", + "decamelize": "^1.2.0", + "find-up": "^4.1.0", + "get-caller-file": "^2.0.1", + "require-directory": "^2.1.1", + "require-main-filename": "^2.0.0", + "set-blocking": "^2.0.0", + "string-width": "^4.2.0", + "which-module": "^2.0.0", + "y18n": "^4.0.0", + "yargs-parser": "^18.1.2" + } + }, + "yargs-parser": { + "version": "18.1.3", + "resolved": "https://registry.npmjs.org/yargs-parser/-/yargs-parser-18.1.3.tgz", + "integrity": "sha512-o50j0JeToy/4K6OZcaQmW6lyXXKhq7csREXcDwk2omFPJEwUNOVtJKvmDr9EI1fAJZUyZcRF7kxGBWmRXudrCQ==", + "dev": true, + "requires": { + "camelcase": "^5.0.0", + "decamelize": "^1.2.0" + } + } + } + }, "proxy-addr": { "version": "2.0.7", "resolved": "https://registry.npmjs.org/proxy-addr/-/proxy-addr-2.0.7.tgz", @@ -11702,6 +12289,12 @@ "resolved": "https://registry.npmjs.org/punycode/-/punycode-2.1.1.tgz", "integrity": "sha512-XRsRjdf+j5ml+y/6GKHPZbrF/8p2Yga0JPtdqTIY2Xe5ohJPD9saDJJLPvp9+NSBprVvevdXZybnj2cv8OEd0A==" }, + "q": { + "version": "1.4.1", + "resolved": "https://registry.npmjs.org/q/-/q-1.4.1.tgz", + "integrity": "sha1-VXBbzZPF82c1MMLCy8DCs63cKG4=", + "dev": true + }, "qjobs": { "version": "1.2.0", "resolved": "https://registry.npmjs.org/qjobs/-/qjobs-1.2.0.tgz", @@ -12219,6 +12812,45 @@ "neo-async": "^2.6.2" } }, + "saucelabs": { + "version": "1.5.0", + "resolved": "https://registry.npmjs.org/saucelabs/-/saucelabs-1.5.0.tgz", + "integrity": "sha512-jlX3FGdWvYf4Q3LFfFWS1QvPg3IGCGWxIc8QBFdPTbpTJnt/v17FHXYVAn7C8sHf1yUXo2c7yIM0isDryfYtHQ==", + "dev": true, + "requires": { + "https-proxy-agent": "^2.2.1" + }, + "dependencies": { + "agent-base": { + "version": "4.3.0", + "resolved": "https://registry.npmjs.org/agent-base/-/agent-base-4.3.0.tgz", + "integrity": "sha512-salcGninV0nPrwpGNn4VTXBb1SOuXQBiqbrNXoeizJsHrsL6ERFM2Ne3JUSBWRE6aeNJI2ROP/WEEIDUiDe3cg==", + "dev": true, + "requires": { + "es6-promisify": "^5.0.0" + } + }, + "debug": { + "version": "3.2.7", + "resolved": "https://registry.npmjs.org/debug/-/debug-3.2.7.tgz", + "integrity": "sha512-CFjzYYAi4ThfiQvizrFQevTTXHtnCqWfe7x1AhgEscTz6ZbLbfoLRLPugTQyBth6f8ZERVUSyWHFD/7Wu4t1XQ==", + "dev": true, + "requires": { + "ms": "^2.1.1" + } + }, + "https-proxy-agent": { + "version": "2.2.4", + "resolved": "https://registry.npmjs.org/https-proxy-agent/-/https-proxy-agent-2.2.4.tgz", + "integrity": "sha512-OmvfoQ53WLjtA9HeYP9RNrWMJzzAz1JGaSFr1nijg0PVR1JaD/xbJq1mdEIIlxGpXp9eSe/O2LgU9DJmTPd0Eg==", + "dev": true, + "requires": { + "agent-base": "^4.3.0", + "debug": "^3.1.0" + } + } + } + }, "sax": { "version": "1.2.4", "resolved": "https://registry.npmjs.org/sax/-/sax-1.2.4.tgz", @@ -12270,6 +12902,38 @@ "integrity": "sha1-Yl2GWPhlr0Psliv8N2o3NZpJlMo=", "dev": true }, + "selenium-webdriver": { + "version": "3.6.0", + "resolved": "https://registry.npmjs.org/selenium-webdriver/-/selenium-webdriver-3.6.0.tgz", + "integrity": "sha512-WH7Aldse+2P5bbFBO4Gle/nuQOdVwpHMTL6raL3uuBj/vPG07k6uzt3aiahu352ONBr5xXh0hDlM3LhtXPOC4Q==", + "dev": true, + "requires": { + "jszip": "^3.1.3", + "rimraf": "^2.5.4", + "tmp": "0.0.30", + "xml2js": "^0.4.17" + }, + "dependencies": { + "rimraf": { + "version": "2.7.1", + "resolved": "https://registry.npmjs.org/rimraf/-/rimraf-2.7.1.tgz", + "integrity": "sha512-uWjbaKIK3T1OSVptzX7Nl6PvQ3qAGtKEtVRjRuazjfL3Bx5eI409VZSqgND+4UNnmzLVdPj9FqFJNPqBZFve4w==", + "dev": true, + "requires": { + "glob": "^7.1.3" + } + }, + "tmp": { + "version": "0.0.30", + "resolved": "https://registry.npmjs.org/tmp/-/tmp-0.0.30.tgz", + "integrity": "sha1-ckGdSovn1s51FI/YsyTlk6cRwu0=", + "dev": true, + "requires": { + "os-tmpdir": "~1.0.1" + } + } + } + }, "selfsigned": { "version": "1.10.11", "resolved": "https://registry.npmjs.org/selfsigned/-/selfsigned-1.10.11.tgz", @@ -12418,6 +13082,12 @@ "integrity": "sha1-BF+XgtARrppoA93TgrJDkrPYkPc=", "dev": true }, + "set-immediate-shim": { + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/set-immediate-shim/-/set-immediate-shim-1.0.1.tgz", + "integrity": "sha1-SysbJ+uAip+NzEgaWOXlb1mfP2E=", + "dev": true + }, "set-value": { "version": "2.0.1", "resolved": "https://registry.npmjs.org/set-value/-/set-value-2.0.1.tgz", @@ -13501,6 +14171,34 @@ "integrity": "sha512-L0Orpi8qGpRG//Nd+H90vFB+3iHnue1zSSGmNOOCh1GLJ7rUKVwV2HvijphGQS2UmhUZewS9VgvxYIdgr+fG1A==", "dev": true }, + "ts-node": { + "version": "10.4.0", + "resolved": "https://registry.npmjs.org/ts-node/-/ts-node-10.4.0.tgz", + "integrity": "sha512-g0FlPvvCXSIO1JDF6S232P5jPYqBkRL9qly81ZgAOSU7rwI0stphCgd2kLiCrU9DjQCrJMWEqcNSjQL02s6d8A==", + "dev": true, + "requires": { + "@cspotcode/source-map-support": "0.7.0", + "@tsconfig/node10": "^1.0.7", + "@tsconfig/node12": "^1.0.7", + "@tsconfig/node14": "^1.0.0", + "@tsconfig/node16": "^1.0.2", + "acorn": "^8.4.1", + "acorn-walk": "^8.1.1", + "arg": "^4.1.0", + "create-require": "^1.1.0", + "diff": "^4.0.1", + "make-error": "^1.1.1", + "yn": "3.1.1" + }, + "dependencies": { + "acorn-walk": { + "version": "8.2.0", + "resolved": "https://registry.npmjs.org/acorn-walk/-/acorn-walk-8.2.0.tgz", + "integrity": "sha512-k+iyHEuPgSw6SbuDpGQM+06HQUa04DZ3o+F6CSzXMvvI5KMvnaEqXe+YVe555R9nn6GPt404fos4wcgpw12SDA==", + "dev": true + } + } + }, "tslib": { "version": "2.3.1", "resolved": "https://registry.npmjs.org/tslib/-/tslib-2.3.1.tgz", @@ -13861,6 +14559,16 @@ "defaults": "^1.0.3" } }, + "webdriver-js-extender": { + "version": "2.1.0", + "resolved": "https://registry.npmjs.org/webdriver-js-extender/-/webdriver-js-extender-2.1.0.tgz", + "integrity": "sha512-lcUKrjbBfCK6MNsh7xaY2UAUmZwe+/ib03AjVOpFobX4O7+83BUveSrLfU0Qsyb1DaKJdQRbuU+kM9aZ6QUhiQ==", + "dev": true, + "requires": { + "@types/selenium-webdriver": "^3.0.0", + "selenium-webdriver": "^3.0.1" + } + }, "webidl-conversions": { "version": "6.1.0", "resolved": "https://registry.npmjs.org/webidl-conversions/-/webidl-conversions-6.1.0.tgz", @@ -14542,6 +15250,22 @@ "resolved": "https://registry.npmjs.org/xml-name-validator/-/xml-name-validator-3.0.0.tgz", "integrity": "sha512-A5CUptxDsvxKJEU3yO6DuWBSJz/qizqzJKOMIfUJHETbBw/sFaDxgd6fxm1ewUaM0jZ444Fc5vC5ROYurg/4Pw==" }, + "xml2js": { + "version": "0.4.23", + "resolved": "https://registry.npmjs.org/xml2js/-/xml2js-0.4.23.tgz", + "integrity": "sha512-ySPiMjM0+pLDftHgXY4By0uswI3SPKLDw/i3UXbnO8M/p28zqexCUoPmQFrYD+/1BzhGJSs2i1ERWKJAtiLrug==", + "dev": true, + "requires": { + "sax": ">=0.6.0", + "xmlbuilder": "~11.0.0" + } + }, + "xmlbuilder": { + "version": "11.0.1", + "resolved": "https://registry.npmjs.org/xmlbuilder/-/xmlbuilder-11.0.1.tgz", + "integrity": "sha512-fDlsI/kFEx7gLvbecc0/ohLG50fugQp8ryHzMTuW9vSa1GJ0XYWKnhsUx7oie3G98+r56aTQIUB4kht42R3JvA==", + "dev": true + }, "xmlchars": { "version": "2.2.0", "resolved": "https://registry.npmjs.org/xmlchars/-/xmlchars-2.2.0.tgz", @@ -14679,6 +15403,12 @@ "integrity": "sha1-AI4G2AlDIMNy28L47XagymyKxBk=", "dev": true }, + "yn": { + "version": "3.1.1", + "resolved": "https://registry.npmjs.org/yn/-/yn-3.1.1.tgz", + "integrity": "sha512-Ux4ygGWsu2c7isFWe8Yu1YluJmqVhxqK2cLXNQA5AcC3QfbGNpM7fu0Y8b/z16pXLnFxZYvWhd3fhBY9DLmC6Q==", + "dev": true + }, "yocto-queue": { "version": "0.1.0", "resolved": "https://registry.npmjs.org/yocto-queue/-/yocto-queue-0.1.0.tgz", diff --git a/packages-smoke/package.json b/packages-smoke/package.json index 95024708d3..44548ea0d4 100644 --- a/packages-smoke/package.json +++ b/packages-smoke/package.json @@ -8,6 +8,7 @@ "watch": "ng build --watch --configuration development", "test": "ng test", "lint": "ng lint", + "e2e": "ng e2e", "dev:ssr": "ng run packages-smoke:serve-ssr", "serve:ssr": "node dist/packages-smoke/server/main.js", "build:ssr": "ng build --configuration=production && ng run packages-smoke:server --configuration=production", @@ -32,6 +33,7 @@ "@nebular/security": "file:.lib/security", "@nebular/theme": "file:.lib/theme", "@nguniversal/express-engine": "^12.1.2", + "date-fns": "^2.25.0", "eva-icons": "^1.1.2", "express": "^4.15.2", "moment": "^2.22.2", @@ -57,11 +59,14 @@ "@typescript-eslint/parser": "4.28.2", "eslint": "^7.26.0", "jasmine-core": "~3.8.0", + "jasmine-spec-reporter": "~5.0.0", "karma": "~6.3.0", "karma-chrome-launcher": "~3.1.0", "karma-coverage": "~2.0.3", "karma-jasmine": "~4.0.0", "karma-jasmine-html-reporter": "~1.7.0", + "protractor": "~7.0.0", + "ts-node": "^10.4.0", "typescript": "~4.3.5" } } diff --git a/protractor.conf.ci.js b/protractor.conf.ci.js deleted file mode 100644 index 8d8a5a427e..0000000000 --- a/protractor.conf.ci.js +++ /dev/null @@ -1,93 +0,0 @@ -// Protractor configuration file, see link for more information -// https://github.com/angular/protractor/blob/master/lib/config.ts -// TODO this config is redundant but we'll keep it for the future purposes - -const browserstack = require('browserstack-local'); -const { SpecReporter } = require('jasmine-spec-reporter'); - -exports.config = { - allScriptsTimeout: 11000, - - seleniumAddress: 'http://hub-cloud.browserstack.com/wd/hub', - - specs: [ - './e2e/**/*.e2e-spec.ts' - ], - - commonCapabilities: { - 'browserstack.user': process.env.BROWSERSTACK_USERNAME, - 'browserstack.key': process.env.BROWSERSTACK_ACCESS_KEY, - 'build': '@nebular/theme', - 'name': '@nebular/theme', - 'browserstack.local': true, - 'browserstack.debug': true, - 'browserName': 'chrome', - 'chromeOptions': { - 'args': ['show-fps-counter=true', '--no-sandbox'] - } - }, - - multiCapabilities: [ - { - browserName: 'IE', - browser_version: '11.0', - }, - { - browserName: 'Edge', - }, - { - browserName: 'Chrome' - }, - { - browserName: 'Safari', - }, - { - browserName: 'Firefox', - }, - ], - - baseUrl: 'http://localhost:4200/', - - framework: 'jasmine', - - jasmineNodeOpts: { - showColors: true, - defaultTimeoutInterval: 30000, - print: function () { } - }, - - // Code to start browserstack local before start of test - beforeLaunch: function() { - console.log("Connecting local"); - return new Promise(function(resolve, reject) { - exports.bs_local = new browserstack.Local(); - exports.bs_local.start({'key': exports.config.commonCapabilities['browserstack.key'] }, function(error) { - if (error) return reject(error); - console.log('Connected. Now testing...'); - - resolve(); - }); - }); - }, - - // Code to stop browserstack local after end of test - afterLaunch: function() { - return new Promise(function(resolve, reject) { - exports.bs_local.stop(resolve); - }); - }, - - onPrepare() { - require('ts-node').register({ - project: 'e2e/tsconfig.e2e.json' - }); - - jasmine.getEnv().addReporter(new SpecReporter({ spec: { displayStacktrace: true } })); - } - -}; - -// Code to support common capabilities -exports.config.multiCapabilities.forEach(function (caps) { - for (var i in exports.config.commonCapabilities) caps[i] = caps[i] || exports.config.commonCapabilities[i]; -}); diff --git a/protractor.conf.js b/protractor.conf.js index 05b3f4e963..de6debb3a0 100644 --- a/protractor.conf.js +++ b/protractor.conf.js @@ -9,14 +9,12 @@ const config = { useAllAngular2AppRoots: true, allScriptsTimeout: 120000, getPageTimeout: 120000, - specs: [ - './e2e/**/*.e2e-spec.ts' - ], + specs: ['./e2e/**/*.e2e-spec.ts'], capabilities: { - 'browserName': 'chrome', - 'chromeOptions': { - 'args': ['show-fps-counter=true', '--no-sandbox'] - } + browserName: 'chrome', + chromeOptions: { + args: ['show-fps-counter=true', '--no-sandbox'], + }, }, // directConnect: true, baseUrl: E2E_BASE_URL, @@ -25,60 +23,30 @@ const config = { jasmineNodeOpts: { showColors: true, defaultTimeoutInterval: 120000, - print: function() {} + print: function () {}, }, onPrepare() { require('ts-node').register({ - project: 'e2e/tsconfig.e2e.json' + project: 'e2e/tsconfig.e2e.json', }); const failFast = require('jasmine-fail-fast'); jasmine.getEnv().addReporter(failFast.init()); jasmine.getEnv().addReporter(new SpecReporter({ acspec: { displayStacktrace: true } })); - } + }, }; -if (process.env['TRAVIS']) { - - const [platform] = process.env.MODE.split('_'); - +if (process.env.CI) { config.directConnect = false; - - if (platform === 'sauce') { - const key = require('./scripts/ci/sauce/config'); - config.sauceUser = process.env['SAUCE_USERNAME']; - config.sauceKey = key; - config.capabilities = { - 'browserName': 'chrome', - 'version': 'latest', - 'tunnel-identifier': process.env['TRAVIS_JOB_ID'], - 'build': process.env['TRAVIS_JOB_ID'], - 'name': 'Nebular E2E Tests', - - // Enables concurrent testing in the Webdriver. Currently runs five e2e files in parallel. - 'maxInstances': 5, - 'shardTestFiles': true, - - // By default Saucelabs tries to record the whole e2e run. This can slow down the builds. - 'recordVideo': false, - 'recordScreenshots': false - }; - } else if (platform === 'browserstack') { - - const key = require('./scripts/ci/browserstack/config'); - - config.browserstackUser = process.env['BROWSER_STACK_USERNAME']; - config.browserstackKey = key; - - config.capabilities = { - 'browserstack.localIdentifier': process.env['TRAVIS_JOB_ID'], - 'browserstack.local': 'true', - 'build': process.env['TRAVIS_JOB_ID'], - 'name': 'Nebular E2E Tests', - 'browserName': 'chrome', - }; - } + config.browserstackUser = process.env.BROWSERSTACK_USERNAME; + config.browserstackKey = process.env.BROWSERSTACK_ACCESS_KEY; + config.capabilities = { + 'browserstack.localIdentifier': process.env.BROWSERSTACK_LOCAL_IDENTIFIER, + 'browserstack.local': 'true', + build: process.env.BROWSERSTACK_BUILD_NAME, + name: process.env.BROWSERSTACK_PROJECT_NAME, + browserName: 'chrome', + }; } - exports.config = config; diff --git a/scripts/ci/browserstack/config.js b/scripts/ci/browserstack/config.js deleted file mode 100644 index b7e9591695..0000000000 --- a/scripts/ci/browserstack/config.js +++ /dev/null @@ -1 +0,0 @@ -module.exports = process.env.BROWSER_STACK_KEY.split('').reverse().join(''); diff --git a/scripts/ci/browserstack/start-tunnel.sh b/scripts/ci/browserstack/start-tunnel.sh deleted file mode 100755 index ae4464cfae..0000000000 --- a/scripts/ci/browserstack/start-tunnel.sh +++ /dev/null @@ -1,69 +0,0 @@ -#!/bin/bash - -set -e -o pipefail - -# Workaround for Travis CI cookbook https://github.com/travis-ci/travis-ci/issues/4862, -# where $PATH will be extended with relative paths to the NPM binaries. -PATH=`echo ${PATH} | sed -e 's/:\.\/node_modules\/\.bin//'` - -TUNNEL_FILE="BrowserStackLocal-linux-x64.zip" -TUNNEL_URL="https://www.browserstack.com/browserstack-local/${TUNNEL_FILE}" -TUNNEL_DIR="/tmp/browserstack-tunnel" -TUNNEL_LOG="${LOGS_DIR}/browserstack-tunnel.log" - -BROWSER_STACK_KEY=`echo ${BROWSER_STACK_KEY} | rev` - -# Cleanup and create the folder structure for the tunnel connector. -rm -rf ${TUNNEL_DIR} ${BROWSER_PROVIDER_READY_FILE} -mkdir -p ${TUNNEL_DIR} -touch ${TUNNEL_LOG} - -cd ${TUNNEL_DIR} - -# Download the browserstack local binaries. -curl ${TUNNEL_URL} -o ${TUNNEL_FILE} 2> /dev/null 1> /dev/null - -# Extract the browserstack local binaries from the tarball. -mkdir -p browserstack-tunnel -unzip -q ${TUNNEL_FILE} -d browserstack-tunnel - -# Cleanup the download directory. -rm ${TUNNEL_FILE} - -ARGS="" - -# Set tunnel-id only on Travis, to make local testing easier. -if [ ! -z "${TRAVIS_JOB_ID}" ]; then - ARGS="${ARGS} --local-identifier ${TRAVIS_JOB_ID}" -fi - -echo "Starting Browserstack Local in the background, logging into: ${TUNNEL_LOG}" - -# Extension to the BrowserStackLocal binaries, because those can't create a readyfile. -function create_ready_file { - - # To be able to exit the tail properly we need to have a sub shell spawned, which is - # used to track the state of tail. - { sleep 120; touch ${BROWSER_PROVIDER_ERROR_FILE}; } & - - TIMER_PID=${!} - - # Disown the background process, because we don't want to show any messages when killing - # the timer. - disown - - # When the tail recognizes the `Ctrl-C` log message the BrowserStack Tunnel is up. - { - tail -n0 -f ${TUNNEL_LOG} --pid ${TIMER_PID} | { sed '/Ctrl/q' && kill -9 ${TIMER_PID}; }; - } &> /dev/null - - echo - echo "BrowserStack Tunnel ready" - - touch ${BROWSER_PROVIDER_READY_FILE} -} - -browserstack-tunnel/BrowserStackLocal -k ${BROWSER_STACK_KEY} ${ARGS} 2>&1 >> ${TUNNEL_LOG} & - -# Wait for the tunnel to be ready and create the readyfile with the Browserstack PID -create_ready_file & diff --git a/scripts/ci/browserstack/stop-tunnel.sh b/scripts/ci/browserstack/stop-tunnel.sh deleted file mode 100755 index 854a8d7e68..0000000000 --- a/scripts/ci/browserstack/stop-tunnel.sh +++ /dev/null @@ -1,16 +0,0 @@ -#!/bin/bash - -set -e -o pipefail - - -echo "Shutting down Browserstack tunnel" - -pkill BrowserStack - -while [[ -n `ps -ef | grep "BrowserStackLocal" | grep -v "grep"` ]]; do - printf "." - sleep .5 -done - -echo "" -echo "Browserstack tunnel has been shut down" diff --git a/scripts/ci/browserstack/wait-tunnel.sh b/scripts/ci/browserstack/wait-tunnel.sh deleted file mode 100755 index 6b1aaa112b..0000000000 --- a/scripts/ci/browserstack/wait-tunnel.sh +++ /dev/null @@ -1,42 +0,0 @@ -#!/bin/bash - -TUNNEL_LOG="$LOGS_DIR/browserstack-tunnel.log" -WAIT_DELAY=30 - -# Method that prints the logfile output of the browserstack tunnel. -printLog() { - echo "Logfile output of Browserstack tunnel (${TUNNEL_LOG}):" - echo "" - cat ${TUNNEL_LOG} -} - -# Wait for Connect to be ready before exiting -# Time out if we wait for more than 2 minutes, so the process won't run forever. -let "counter=0" - -# Exit the process if there are errors reported. Print the tunnel log to the console. -if [ -f $BROWSER_PROVIDER_ERROR_FILE ]; then - echo - echo "An error occurred while starting the tunnel. See error:" - printLog - exit 5 -fi - -while [ ! -f $BROWSER_PROVIDER_READY_FILE ]; do - let "counter++" - - # Counter needs to be multiplied by two because the while loop only sleeps a half second. - # This has been made in favor of better progress logging (printing dots every half second) - if [ $counter -gt $[${WAIT_DELAY} * 2] ]; then - echo - echo "Timed out after 2 minutes waiting for tunnel ready file" - printLog - exit 5 - fi - - printf "." - sleep 0.5 -done - -echo "" -echo "Connected to Browserstack" diff --git a/scripts/ci/deploy-docs.sh b/scripts/ci/deploy-docs.sh deleted file mode 100644 index cc88234e2e..0000000000 --- a/scripts/ci/deploy-docs.sh +++ /dev/null @@ -1,20 +0,0 @@ -deploy_docs() { - if [[ "$TRAVIS_PULL_REQUEST" = "false" ]]; then - npm run docs:gh-pages & - - # https://github.com/travis-ci/travis-ci/issues/4190#issuecomment-169987525 - minutes=0 - limit=30 - while kill -0 $! >/dev/null 2>&1; do - echo -n -e " \b" - - if [ $minutes == $limit ]; then - break; - fi - - minutes=$((minutes+1)) - - sleep 60 - done - fi -} diff --git a/scripts/ci/packages-smoke.sh b/scripts/ci/packages-smoke.sh deleted file mode 100755 index 1160ab709c..0000000000 --- a/scripts/ci/packages-smoke.sh +++ /dev/null @@ -1,30 +0,0 @@ -#!/usr/bin/env bash - -packages_smoke() { - echo "Starting framework build smoke testing" - PROJECT="packages-smoke" - - echo "Building packages" - npm run build:packages - - echo "Setting up playground application for testing" - rm -rf ../${PROJECT} - cp -r ./${PROJECT} ../${PROJECT} - cd ../${PROJECT} - mkdir -p .lib - cp -r ../nebular/dist/* ./.lib - - echo "Installing built packages" - npm install - - echo "Verifying application build" - npm run build -- --configuration=production - npm run e2e - - echo "Run with ssr" - npm run build:ssr - npm run serve:ssr - - echo "Clean" - cd ..; rm -rf -- ${PROJECT} -} diff --git a/scripts/ci/retry-call.sh b/scripts/ci/retry-call.sh deleted file mode 100644 index c40cff768d..0000000000 --- a/scripts/ci/retry-call.sh +++ /dev/null @@ -1,25 +0,0 @@ -#!/bin/bash - -# Function that can be used to re-call a specific command a specific amount of times if it fails. -# @param ${1} Amount of retry calls -# @param ${2} Code block that will be invoked -function retryCall() { - retries=0 - - until [ ${retries} -gt ${1} ]; do - # Call the command and break the loop if it exits without any errors. - (${2}) && return 0 - - # Increase the counter of the invoked retries. - retries=$[${retries} + 1] - - # Sleep a few seconds and log an info message if there are still remaining retries. - if [ ${retries} -le ${1} ]; then - echo "Script didn't exit without errors. Retrying $[${1} - retries + 1] times..." - sleep 1 - fi - done - - echo "Script exited with errors. Exiting process.." - exit 1 -} diff --git a/scripts/ci/sauce/config.js b/scripts/ci/sauce/config.js deleted file mode 100644 index 52d4df6a4b..0000000000 --- a/scripts/ci/sauce/config.js +++ /dev/null @@ -1 +0,0 @@ -module.exports = process.env.SAUCE_ACCESS_KEY.split('').reverse().join(''); diff --git a/scripts/ci/sauce/start-tunnel.sh b/scripts/ci/sauce/start-tunnel.sh deleted file mode 100755 index 06625b9583..0000000000 --- a/scripts/ci/sauce/start-tunnel.sh +++ /dev/null @@ -1,41 +0,0 @@ -#!/bin/bash - -set -e -o pipefail - -TUNNEL_FILE="sc-4.4.11-linux.tar.gz" -TUNNEL_URL="https://saucelabs.com/downloads/${TUNNEL_FILE}" -TUNNEL_DIR="/tmp/saucelabs-connect" - -TUNNEL_LOG="${LOGS_DIR}/saucelabs-tunnel.log" - -SAUCE_ACCESS_KEY=`echo ${SAUCE_ACCESS_KEY} | rev` - -# Cleanup and create the folder structure for the tunnel connector. -rm -rf ${TUNNEL_DIR} ${BROWSER_PROVIDER_READY_FILE} -mkdir -p ${TUNNEL_DIR} - -cd ${TUNNEL_DIR} - -# Download the saucelabs connect binaries. -curl ${TUNNEL_URL} -o ${TUNNEL_FILE} 2> /dev/null 1> /dev/null - -# Extract the saucelabs connect binaries from the tarball. -mkdir -p sauce-connect -tar --extract --file=${TUNNEL_FILE} --strip-components=1 --directory=sauce-connect > /dev/null - -# Cleanup the download directory. -rm ${TUNNEL_FILE} - -ARGS="" - -# Set tunnel-id only on Travis, to make local testing easier. -if [ ! -z "${TRAVIS_JOB_ID}" ]; then - ARGS="${ARGS} --tunnel-identifier ${TRAVIS_JOB_ID}" -fi -if [ ! -z "${BROWSER_PROVIDER_READY_FILE}" ]; then - ARGS="${ARGS} --readyfile ${BROWSER_PROVIDER_READY_FILE}" -fi - -echo "Starting Sauce Connect in the background, logging into: ${TUNNEL_LOG}" - -sauce-connect/bin/sc -u ${SAUCE_USERNAME} -k ${SAUCE_ACCESS_KEY} ${ARGS} 2>&1 >> ${TUNNEL_LOG} & diff --git a/scripts/ci/sauce/stop-tunnel.sh b/scripts/ci/sauce/stop-tunnel.sh deleted file mode 100755 index 91b918a485..0000000000 --- a/scripts/ci/sauce/stop-tunnel.sh +++ /dev/null @@ -1,16 +0,0 @@ -#!/bin/bash - -set -e -o pipefail - - -echo "Shutting down Sauce Connect tunnel" - -killall sc - -while [[ -n `ps -ef | grep "sauce-connect-" | grep -v "grep"` ]]; do - printf "." - sleep .5 -done - -echo "" -echo "Sauce Connect tunnel has been shut down" diff --git a/scripts/ci/sauce/wait-tunnel.sh b/scripts/ci/sauce/wait-tunnel.sh deleted file mode 100755 index 1c0aa0cdee..0000000000 --- a/scripts/ci/sauce/wait-tunnel.sh +++ /dev/null @@ -1,34 +0,0 @@ -#!/bin/bash - -TUNNEL_LOG="$LOGS_DIR/saucelabs-tunnel.log" -WAIT_DELAY=30 - -# Method that prints the logfile output of the saucelabs tunnel. -printLog() { - echo "Logfile output of Saucelabs tunnel (${TUNNEL_LOG}):" - echo "" - cat ${TUNNEL_LOG} -} - -# Wait for Saucelabs Connect to be ready before exiting -# Time out if we wait for more than 2 minutes, so the process won't run forever. -let "counter=0" - -while [ ! -f $BROWSER_PROVIDER_READY_FILE ]; do - let "counter++" - - # Counter needs to be multiplied by two because the while loop only sleeps a half second. - # This has been made in favor of better progress logging (printing dots every half second) - if [ $counter -gt $[${WAIT_DELAY} * 2] ]; then - echo "" - echo "Timed out after 2 minutes waiting for tunnel ready file" - printLog - exit 5 - fi - - printf "." - sleep 0.5 -done - -echo "" -echo "Connected to Saucelabs" diff --git a/scripts/ci/travis-script.sh b/scripts/ci/travis-script.sh deleted file mode 100755 index bdf4cd6084..0000000000 --- a/scripts/ci/travis-script.sh +++ /dev/null @@ -1,69 +0,0 @@ -#!/bin/bash - -# Script that runs in every Travis CI container. The script is responsible for delegating -# to the different scripts that should run for specific Travis jobs in a build stage. - -# The script should immediately exit if any command in the script fails. -set -e - -# Go to project directory -cd $(dirname $0)/../.. - -echo "" -echo "Building sources and running tests. Running mode: ${MODE}" -echo "" - -# Load utility function. -source ./scripts/ci/tunnel.sh -source ./scripts/ci/publish.sh -source ./scripts/ci/deploy.sh -source ./scripts/ci/packages-smoke.sh -source ./scripts/ci/deploy-docs.sh - -if [[ -z "$TRAVIS" ]]; then - echo "This script can only run inside of Travis build jobs." - exit 1 -fi - -if [[ "${MODE}" = docs ]]; then - npm run ci:docs -elif [[ "${MODE}" = deploy_docs ]]; then - deploy_docs - exit 0 -fi - -CURRENT_BRANCH=$(if [ "$TRAVIS_PULL_REQUEST" == "false" ]; then echo $TRAVIS_BRANCH; else echo $TRAVIS_PULL_REQUEST_BRANCH; fi) - -# Get commit diff -if [ "$TRAVIS_PULL_REQUEST" == "false" ]; then - fileDiff=$(git diff --name-only $TRAVIS_COMMIT_RANGE) -else - git remote set-branches --add origin $TRAVIS_BRANCH - git fetch origin $TRAVIS_BRANCH - fileDiff=$(git diff --name-only HEAD origin/${TRAVIS_BRANCH}) -fi - - # Check if tests can be skipped -if [[ ${fileDiff} =~ ^(.*\.md\s*)*$ ]]; then - echo "Skipping tests since only markdown files changed." - exit 0 -fi - -start_tunnel -wait_for_tunnel - -if [[ "${MODE}" = lint ]]; then - npm run ci:lint -elif [[ "${MODE}" = build ]]; then - npm run ci:build -elif [[ "${MODE}" =~ ^.*_(e2e)$ ]]; then - npm run ci:e2e -elif [[ "${MODE}" =~ ^.*_(unit_test)$ ]]; then - npm run ci:test - npm install codecov -g && codecov - npm run test:schematics -elif [[ "${MODE}" = packages_smoke ]]; then - packages_smoke -fi - -teardown_tunnel diff --git a/scripts/ci/tunnel.sh b/scripts/ci/tunnel.sh deleted file mode 100644 index 114a80cfd0..0000000000 --- a/scripts/ci/tunnel.sh +++ /dev/null @@ -1,47 +0,0 @@ -#!/usr/bin/env bash - -# Load the retry-call utility function. -source ./scripts/ci/retry-call.sh - -# Variable the specifies how often the wait script should be invoked if it fails. -WAIT_RETRIES=2 - -start_tunnel() { - case "$MODE" in - sauce*) - ./scripts/ci/sauce/start-tunnel.sh - ;; - browserstack*) - ./scripts/ci/browserstack/start-tunnel.sh - ;; - *) - ;; - esac -} - -wait_for_tunnel() { - case "$MODE" in - sauce*) - retryCall ${WAIT_RETRIES} ./scripts/ci/sauce/wait-tunnel.sh - ;; - browserstack*) - retryCall ${WAIT_RETRIES} ./scripts/ci/browserstack/wait-tunnel.sh - ;; - *) - ;; - esac -} - -teardown_tunnel() { - case "$MODE" in - sauce*) - ./scripts/ci/sauce/stop-tunnel.sh - ;; - browserstack*) - ./scripts/ci/browserstack/stop-tunnel.sh - ;; - *) - ;; - esac -} - diff --git a/src/framework/auth/services/token/token-parceler.spec.ts b/src/framework/auth/services/token/token-parceler.spec.ts index 0976b5c80b..c612398b5c 100644 --- a/src/framework/auth/services/token/token-parceler.spec.ts +++ b/src/framework/auth/services/token/token-parceler.spec.ts @@ -6,22 +6,39 @@ import { inject, TestBed, waitForAsync } from '@angular/core/testing'; -import { NbAuthSimpleToken, nbAuthCreateToken, NbAuthJWTToken } from './token'; -import { NB_AUTH_FALLBACK_TOKEN, NbAuthTokenParceler } from './token-parceler'; -import { NB_AUTH_TOKENS } from '../../auth.options'; +import { + NbAuthSimpleToken, + nbAuthCreateToken, + NbAuthJWTToken, + NB_AUTH_FALLBACK_TOKEN, + NbAuthTokenParceler, + NB_AUTH_TOKENS, +} from '@nebular/auth'; describe('token-parceler', () => { - let tokenParceler: NbAuthTokenParceler; const createdAt = new Date(1532350800000); const simpleToken = nbAuthCreateToken(NbAuthSimpleToken, 'test value', 'strategy', createdAt); // eslint-disable-next-line - const wrappedSimple = `{"name":"${NbAuthSimpleToken.NAME}","ownerStrategyName":"${simpleToken.getOwnerStrategyName()}","createdAt":${simpleToken.getCreatedAt().getTime()},"value":"${simpleToken.getValue()}"}`; + const wrappedSimple = `{"name":"${ + NbAuthSimpleToken.NAME + }","ownerStrategyName":"${simpleToken.getOwnerStrategyName()}","createdAt":${simpleToken + .getCreatedAt() + .getTime()},"value":"${simpleToken.getValue()}"}`; // eslint-disable-next-line - const jwtToken = nbAuthCreateToken(NbAuthJWTToken, 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJjZXJlbWEuZnIiLCJpYXQiOjE1MzIzNTA4MDAsImV4cCI6MTUzMjQzNzIwMCwic3ViIjoiQWxhaW4gQ0hBUkxFUyIsImFkbWluIjp0cnVlfQ.iICwNqhvg9KPv3_MSg3HCydyAgAYI9mL3ZejLkY11Ck', 'strategy', createdAt); + const jwtToken = nbAuthCreateToken( + NbAuthJWTToken, + 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJjZXJlbWEuZnIiLCJpYXQiOjE1MzIzNTA4MDAsImV4cCI6MTUzMjQzNzIwMCwic3ViIjoiQWxhaW4gQ0hBUkxFUyIsImFkbWluIjp0cnVlfQ.iICwNqhvg9KPv3_MSg3HCydyAgAYI9mL3ZejLkY11Ck', + 'strategy', + createdAt, + ); // eslint-disable-next-line - const wrappedJWT = `{"name":"${NbAuthJWTToken.NAME}","ownerStrategyName":"${jwtToken.getOwnerStrategyName()}","createdAt":${jwtToken.getCreatedAt().getTime()},"value":"${jwtToken.getValue()}"}`; + const wrappedJWT = `{"name":"${ + NbAuthJWTToken.NAME + }","ownerStrategyName":"${jwtToken.getOwnerStrategyName()}","createdAt":${jwtToken + .getCreatedAt() + .getTime()},"value":"${jwtToken.getValue()}"}`; // eslint-disable-next-line const wrappedNonExisting = `{"name":"non-existing","value":"${simpleToken.getValue()}","ownerStrategyName":"${simpleToken.getOwnerStrategyName()}","createdAt":"${createdAt.getTime()}"}`; const wrappedInvalid = `{"name":"non-existing"`; @@ -37,44 +54,38 @@ describe('token-parceler', () => { }); }); - beforeEach(waitForAsync(inject( - [NbAuthTokenParceler], - (_tokenParceler) => { - tokenParceler = _tokenParceler; - }, - ))); + beforeEach( + waitForAsync( + inject([NbAuthTokenParceler], (_tokenParceler) => { + tokenParceler = _tokenParceler; + }), + ), + ); it('wraps simple', () => { - expect(tokenParceler.wrap(simpleToken)) - .toEqual(wrappedSimple); + expect(tokenParceler.wrap(simpleToken)).toEqual(wrappedSimple); }); it('wraps jwt', () => { - expect(tokenParceler.wrap(jwtToken)) - .toEqual(wrappedJWT); + expect(tokenParceler.wrap(jwtToken)).toEqual(wrappedJWT); }); it('unwraps simple', () => { - expect(tokenParceler.unwrap(wrappedSimple)) - .toEqual(simpleToken); + expect(tokenParceler.unwrap(wrappedSimple)).toEqual(simpleToken); }); it('unwraps jwt', () => { - expect(tokenParceler.unwrap(wrappedJWT)) - .toEqual(jwtToken); + expect(tokenParceler.unwrap(wrappedJWT)).toEqual(jwtToken); }); it('unwraps non existing', () => { - expect(tokenParceler.unwrap(wrappedNonExisting)) - .toEqual(simpleToken); + expect(tokenParceler.unwrap(wrappedNonExisting)).toEqual(simpleToken); }); it('unwraps invalid', () => { const token = tokenParceler.unwrap(wrappedInvalid); - expect(token.getName()) - .toEqual(simpleToken.getName()); - expect(token.getValue()) - .toEqual(''); + expect(token.getName()).toEqual(simpleToken.getName()); + expect(token.getValue()).toEqual(''); }); }); @@ -89,22 +100,19 @@ describe('token-parceler', () => { }); }); - beforeEach(waitForAsync(inject( - [NbAuthTokenParceler], - (_tokenParceler) => { - tokenParceler = _tokenParceler; - }, - ))); + beforeEach( + waitForAsync( + inject([NbAuthTokenParceler], (_tokenParceler) => { + tokenParceler = _tokenParceler; + }), + ), + ); it('unwraps jwt to fallback simple as none provided', () => { - const token = tokenParceler.unwrap(wrappedJWT); - expect(token.getName()) - .toEqual(simpleToken.getName()); + expect(token.getName()).toEqual(simpleToken.getName()); - expect(token.getValue()) - .toEqual(jwtToken.getValue()); + expect(token.getValue()).toEqual(jwtToken.getValue()); }); - }); }); diff --git a/src/framework/auth/strategies/oauth2/oauth2-strategy.spec.ts b/src/framework/auth/strategies/oauth2/oauth2-strategy.spec.ts index 534cbdd8c5..d12da67ba3 100644 --- a/src/framework/auth/strategies/oauth2/oauth2-strategy.spec.ts +++ b/src/framework/auth/strategies/oauth2/oauth2-strategy.spec.ts @@ -9,26 +9,35 @@ import { HttpClientTestingModule, HttpTestingController } from '@angular/common/ import { RouterTestingModule } from '@angular/router/testing'; import { ActivatedRoute } from '@angular/router'; import { NB_WINDOW } from '@nebular/theme'; -import { NbOAuth2AuthStrategy } from './oauth2-strategy'; -import { NbOAuth2ClientAuthMethod, NbOAuth2GrantType, NbOAuth2ResponseType } from './oauth2-strategy.options'; -import { NbAuthResult } from '../../services/auth-result'; -import { nbAuthCreateToken, NbAuthOAuth2Token } from '../../services/token/token'; +import { + NbOAuth2AuthStrategy, + NbOAuth2ClientAuthMethod, + NbOAuth2GrantType, + NbOAuth2ResponseType, + NbAuthResult, + nbAuthCreateToken, + NbAuthOAuth2Token, +} from '@nebular/auth'; + function createURL(params: any) { - return Object.keys(params).map((k) => { - return `${encodeURIComponent(k)}=${encodeURIComponent(params[k])}`; - }).join('&'); + return Object.keys(params) + .map((k) => { + return `${encodeURIComponent(k)}=${encodeURIComponent(params[k])}`; + }) + .join('&'); } function parseQueryParams(params: string): { [key: string]: string } { - return params ? params.split('&').reduce((acc: any, part: string) => { - const item = part.split('='); - acc[item[0]] = decodeURIComponent(item[1]); - return acc; - }, {}) : {}; + return params + ? params.split('&').reduce((acc: any, part: string) => { + const item = part.split('='); + acc[item[0]] = decodeURIComponent(item[1]); + return acc; + }, {}) + : {}; } describe('oauth2-auth-strategy', () => { - let strategy: NbOAuth2AuthStrategy; let httpMock: HttpTestingController; let routeMock: any; @@ -49,21 +58,21 @@ describe('oauth2-auth-strategy', () => { access_token: '8uoloUIg765fHGF9jknjksdn9', expires_in: 3600, example_parameter: 'example_refresh_value', - } + }; - const refreshedTokenPayload = { + const refreshedTokenPayload = { access_token: '8uoloUIg765fHGF9jknjksdn9', expires_in: 3600, refresh_token: 'tGzv3JOkF0XG5Qx2TlKWIA', example_parameter: 'example_refresh_value', - } + }; - const refreshedTokenResponse = { + const refreshedTokenResponse = { access_token: '8uoloUIg765fHGF9jknjksdn9', expires_in: 3600, refresh_token: 'dfsjkgkdh989JHJHJDSHJns', example_parameter: 'example_refresh_value', - } + }; const tokenErrorResponse = { error: 'unauthorized_client', @@ -71,12 +80,13 @@ describe('oauth2-auth-strategy', () => { error_uri: 'some', }; - const successToken = nbAuthCreateToken(NbAuthOAuth2Token, tokenSuccessResponse, - 'strategy') as NbAuthOAuth2Token; - const refreshedToken = nbAuthCreateToken(NbAuthOAuth2Token, refreshedTokenPayload, - 'strategy') as NbAuthOAuth2Token; - const refreshedTokenWithRefreshToken = nbAuthCreateToken(NbAuthOAuth2Token, refreshedTokenResponse, - 'strategy') as NbAuthOAuth2Token; + const successToken = nbAuthCreateToken(NbAuthOAuth2Token, tokenSuccessResponse, 'strategy') as NbAuthOAuth2Token; + const refreshedToken = nbAuthCreateToken(NbAuthOAuth2Token, refreshedTokenPayload, 'strategy') as NbAuthOAuth2Token; + const refreshedTokenWithRefreshToken = nbAuthCreateToken( + NbAuthOAuth2Token, + refreshedTokenResponse, + 'strategy', + ) as NbAuthOAuth2Token; beforeEach(() => { windowMock = { location: { href: '' } }; @@ -92,33 +102,33 @@ describe('oauth2-auth-strategy', () => { }); }); - beforeEach(waitForAsync(inject( - [NbOAuth2AuthStrategy, HttpTestingController], - (_strategy, _httpMock) => { - strategy = _strategy; - httpMock = _httpMock; + beforeEach( + waitForAsync( + inject([NbOAuth2AuthStrategy, HttpTestingController], (_strategy, _httpMock) => { + strategy = _strategy; + httpMock = _httpMock; - strategy.setOptions({}); - }, - ))); + strategy.setOptions({}); + }), + ), + ); afterEach(() => { httpMock.verify(); }); describe('out of the box: type CODE', () => { - const basicOptions = { name: 'strategy', baseEndpoint: 'http://example.com/', clientId: 'clientId', - } + }; beforeEach(() => { strategy.setOptions(basicOptions); }); - it('redirect to auth server', (done: DoneFn) => { + it('redirect to auth server', (done: DoneFn) => { windowMock.location = { set href(value: string) { expect(value).toEqual('http://example.com/authorize?response_type=code&client_id=clientId'); @@ -126,264 +136,256 @@ describe('oauth2-auth-strategy', () => { }, }; - strategy.authenticate() - .subscribe(() => {}); + strategy.authenticate().subscribe(() => {}); }); it('handle success redirect and sends correct token request', (done: DoneFn) => { routeMock.snapshot.queryParams = { code: 'code' }; - strategy.authenticate() - .subscribe((result: NbAuthResult) => { - expect(result).toBeTruthy(); - expect(result.isSuccess()).toBe(true); - expect(result.isFailure()).toBe(false); - expect(result.getToken().getValue()).toEqual(successToken.getValue()); - expect(result.getToken().getOwnerStrategyName()).toEqual(successToken.getOwnerStrategyName()); - expect(result.getMessages()).toEqual(successMessages); - expect(result.getErrors()).toEqual([]); // no error message, response is success - expect(result.getRedirect()).toEqual('/'); - done(); - }); + strategy.authenticate().subscribe((result: NbAuthResult) => { + expect(result).toBeTruthy(); + expect(result.isSuccess()).toBe(true); + expect(result.isFailure()).toBe(false); + expect(result.getToken().getValue()).toEqual(successToken.getValue()); + expect(result.getToken().getOwnerStrategyName()).toEqual(successToken.getOwnerStrategyName()); + expect(result.getMessages()).toEqual(successMessages); + expect(result.getErrors()).toEqual([]); // no error message, response is success + expect(result.getRedirect()).toEqual('/'); + done(); + }); - httpMock.expectOne( - req => { + httpMock + .expectOne((req) => { const params = parseQueryParams(req.body); - return (req.url === 'http://example.com/token' - && req.headers.get('Content-Type') === 'application/x-www-form-urlencoded' - && decodeURIComponent(params['grant_type']) === NbOAuth2GrantType.AUTHORIZATION_CODE - && decodeURIComponent(params['code']) === 'code' - && decodeURIComponent(params['client_id']) === 'clientId' - && !params['redirect_uri']) - }, - ) - .flush(tokenSuccessResponse); + return ( + req.url === 'http://example.com/token' && + req.headers.get('Content-Type') === 'application/x-www-form-urlencoded' && + decodeURIComponent(params.grant_type) === NbOAuth2GrantType.AUTHORIZATION_CODE && + decodeURIComponent(params.code) === 'code' && + decodeURIComponent(params.client_id) === 'clientId' && + !params.redirect_uri + ); + }) + .flush(tokenSuccessResponse); }); it('handle error redirect back', (done: DoneFn) => { routeMock.snapshot.queryParams = tokenErrorResponse; - strategy.authenticate() - .subscribe((result: NbAuthResult) => { - expect(result).toBeTruthy(); - expect(result.isSuccess()).toBe(false); - expect(result.isFailure()).toBe(true); - expect(result.getToken()).toBeNull(); - expect(result.getResponse()).toEqual(tokenErrorResponse); - expect(result.getMessages()).toEqual([]); - expect(result.getErrors()).toEqual(errorMessages); - expect(result.getRedirect()).toEqual(null); - done(); - }); + strategy.authenticate().subscribe((result: NbAuthResult) => { + expect(result).toBeTruthy(); + expect(result.isSuccess()).toBe(false); + expect(result.isFailure()).toBe(true); + expect(result.getToken()).toBeNull(); + expect(result.getResponse()).toEqual(tokenErrorResponse); + expect(result.getMessages()).toEqual([]); + expect(result.getErrors()).toEqual(errorMessages); + expect(result.getRedirect()).toEqual(null); + done(); + }); }); it('handle error token response', (done: DoneFn) => { - routeMock.snapshot.queryParams = {code: 'code'}; - - strategy.authenticate() - .subscribe((result: NbAuthResult) => { - - expect(result).toBeTruthy(); - expect(result.isSuccess()).toBe(false); - expect(result.isFailure()).toBe(true); - expect(result.getToken()).toBeNull(); - expect(result.getResponse().error).toEqual(tokenErrorResponse); - expect(result.getMessages()).toEqual([]); - expect(result.getErrors()).toEqual([ tokenErrorResponse.error_description] ); - expect(result.getRedirect()).toEqual(null); - done(); - }); - - httpMock.expectOne( - req => { - return (req.url === 'http://example.com/token' - && req.headers.get('Content-Type') === 'application/x-www-form-urlencoded' - ) - }, - ) + routeMock.snapshot.queryParams = { code: 'code' }; + + strategy.authenticate().subscribe((result: NbAuthResult) => { + expect(result).toBeTruthy(); + expect(result.isSuccess()).toBe(false); + expect(result.isFailure()).toBe(true); + expect(result.getToken()).toBeNull(); + expect(result.getResponse().error).toEqual(tokenErrorResponse); + expect(result.getMessages()).toEqual([]); + expect(result.getErrors()).toEqual([tokenErrorResponse.error_description]); + expect(result.getRedirect()).toEqual(null); + done(); + }); + + httpMock + .expectOne((req) => { + return ( + req.url === 'http://example.com/token' && + req.headers.get('Content-Type') === 'application/x-www-form-urlencoded' + ); + }) .flush(tokenErrorResponse, { status: 400, statusText: 'Bad Request' }); }); it('handle refresh token with basic client auth', (done: DoneFn) => { strategy.setOptions({ - ... basicOptions, + ...basicOptions, clientSecret: 'clientSecret', clientAuthMethod: NbOAuth2ClientAuthMethod.BASIC, }); - strategy.refreshToken(successToken) - .subscribe((result: NbAuthResult) => { - expect(result).toBeTruthy(); - expect(result.isSuccess()).toBe(true); - expect(result.isFailure()).toBe(false); - expect(result.getToken().getValue()).toEqual(successToken.getValue()); - expect(result.getToken().getOwnerStrategyName()).toEqual(successToken.getOwnerStrategyName()); - expect(result.getMessages()).toEqual(successMessages); - expect(result.getErrors()).toEqual([]); // no error message, response is success - expect(result.getRedirect()).toEqual('/'); - done(); - }); + strategy.refreshToken(successToken).subscribe((result: NbAuthResult) => { + expect(result).toBeTruthy(); + expect(result.isSuccess()).toBe(true); + expect(result.isFailure()).toBe(false); + expect(result.getToken().getValue()).toEqual(successToken.getValue()); + expect(result.getToken().getOwnerStrategyName()).toEqual(successToken.getOwnerStrategyName()); + expect(result.getMessages()).toEqual(successMessages); + expect(result.getErrors()).toEqual([]); // no error message, response is success + expect(result.getRedirect()).toEqual('/'); + done(); + }); - httpMock.expectOne( - req => { + httpMock + .expectOne((req) => { const params = parseQueryParams(req.body); - return (req.url === 'http://example.com/token' - && req.headers.get('Authorization') === authHeader - && req.headers.get('Content-Type') === 'application/x-www-form-urlencoded' - && decodeURIComponent(params['grant_type']) === NbOAuth2GrantType.REFRESH_TOKEN - && decodeURIComponent(params['refresh_token']) === successToken.getRefreshToken() - && !params['scope']) - }, - ) - .flush(tokenSuccessResponse); + return ( + req.url === 'http://example.com/token' && + req.headers.get('Authorization') === authHeader && + req.headers.get('Content-Type') === 'application/x-www-form-urlencoded' && + decodeURIComponent(params.grant_type) === NbOAuth2GrantType.REFRESH_TOKEN && + decodeURIComponent(params.refresh_token) === successToken.getRefreshToken() && + !params.scope + ); + }) + .flush(tokenSuccessResponse); }); it('handle refresh token with requestBody client auth', (done: DoneFn) => { strategy.setOptions({ - ... basicOptions, + ...basicOptions, clientSecret: 'clientSecret', clientAuthMethod: NbOAuth2ClientAuthMethod.REQUEST_BODY, }); - strategy.refreshToken(successToken) - .subscribe((result: NbAuthResult) => { - expect(result).toBeTruthy(); - expect(result.isSuccess()).toBe(true); - expect(result.isFailure()).toBe(false); - expect(result.getToken().getValue()).toEqual(successToken.getValue()); - expect(result.getToken().getOwnerStrategyName()).toEqual(successToken.getOwnerStrategyName()); - expect(result.getMessages()).toEqual(successMessages); - expect(result.getErrors()).toEqual([]); // no error message, response is success - expect(result.getRedirect()).toEqual('/'); - done(); - }); + strategy.refreshToken(successToken).subscribe((result: NbAuthResult) => { + expect(result).toBeTruthy(); + expect(result.isSuccess()).toBe(true); + expect(result.isFailure()).toBe(false); + expect(result.getToken().getValue()).toEqual(successToken.getValue()); + expect(result.getToken().getOwnerStrategyName()).toEqual(successToken.getOwnerStrategyName()); + expect(result.getMessages()).toEqual(successMessages); + expect(result.getErrors()).toEqual([]); // no error message, response is success + expect(result.getRedirect()).toEqual('/'); + done(); + }); - httpMock.expectOne( - req => { + httpMock + .expectOne((req) => { const params = parseQueryParams(req.body); - return (req.url === 'http://example.com/token' - && req.headers.get('Content-Type') === 'application/x-www-form-urlencoded' - && decodeURIComponent(params['grant_type']) === NbOAuth2GrantType.REFRESH_TOKEN - && decodeURIComponent(params['refresh_token']) === successToken.getRefreshToken() - && decodeURIComponent(params['client_id']) === strategy.getOption('clientId') - && decodeURIComponent(params['client_secret']) === strategy.getOption('clientSecret') - && !params['scope']) - }, - ) - .flush(tokenSuccessResponse); + return ( + req.url === 'http://example.com/token' && + req.headers.get('Content-Type') === 'application/x-www-form-urlencoded' && + decodeURIComponent(params.grant_type) === NbOAuth2GrantType.REFRESH_TOKEN && + decodeURIComponent(params.refresh_token) === successToken.getRefreshToken() && + decodeURIComponent(params.client_id) === strategy.getOption('clientId') && + decodeURIComponent(params.client_secret) === strategy.getOption('clientSecret') && + !params.scope + ); + }) + .flush(tokenSuccessResponse); }); it('handle refresh token with NO client auth', (done: DoneFn) => { strategy.setOptions(basicOptions); - strategy.refreshToken(successToken) - .subscribe((result: NbAuthResult) => { - expect(result).toBeTruthy(); - expect(result.isSuccess()).toBe(true); - expect(result.isFailure()).toBe(false); - expect(result.getToken().getValue()).toEqual(successToken.getValue()); - expect(result.getToken().getOwnerStrategyName()).toEqual(successToken.getOwnerStrategyName()); - expect(result.getMessages()).toEqual(successMessages); - expect(result.getErrors()).toEqual([]); // no error message, response is success - expect(result.getRedirect()).toEqual('/'); - done(); - }); + strategy.refreshToken(successToken).subscribe((result: NbAuthResult) => { + expect(result).toBeTruthy(); + expect(result.isSuccess()).toBe(true); + expect(result.isFailure()).toBe(false); + expect(result.getToken().getValue()).toEqual(successToken.getValue()); + expect(result.getToken().getOwnerStrategyName()).toEqual(successToken.getOwnerStrategyName()); + expect(result.getMessages()).toEqual(successMessages); + expect(result.getErrors()).toEqual([]); // no error message, response is success + expect(result.getRedirect()).toEqual('/'); + done(); + }); - httpMock.expectOne( - req => { + httpMock + .expectOne((req) => { const params = parseQueryParams(req.body); - return (req.url === 'http://example.com/token' - && req.headers.get('Content-Type') === 'application/x-www-form-urlencoded' - && decodeURIComponent(params['grant_type']) === NbOAuth2GrantType.REFRESH_TOKEN - && decodeURIComponent(params['refresh_token']) === successToken.getRefreshToken() - && !params['scope']) - }, - ) - .flush(tokenSuccessResponse); + return ( + req.url === 'http://example.com/token' && + req.headers.get('Content-Type') === 'application/x-www-form-urlencoded' && + decodeURIComponent(params.grant_type) === NbOAuth2GrantType.REFRESH_TOKEN && + decodeURIComponent(params.refresh_token) === successToken.getRefreshToken() && + !params.scope + ); + }) + .flush(tokenSuccessResponse); }); it('handle refresh token and inserts existing refresh_token if needed', (done: DoneFn) => { strategy.setOptions(basicOptions); - strategy.refreshToken(successToken) - .subscribe((result: NbAuthResult) => { - expect(result).toBeTruthy(); - expect(result.isSuccess()).toBe(true); - expect(result.isFailure()).toBe(false); - expect(result.getToken().getValue()).toEqual(refreshedToken.getValue()); - expect(result.getToken().getOwnerStrategyName()).toEqual(refreshedToken.getOwnerStrategyName()); - expect(result.getMessages()).toEqual(successMessages); - expect(result.getErrors()).toEqual([]); // no error message, response is success - expect(result.getRedirect()).toEqual('/'); - done(); - }); + strategy.refreshToken(successToken).subscribe((result: NbAuthResult) => { + expect(result).toBeTruthy(); + expect(result.isSuccess()).toBe(true); + expect(result.isFailure()).toBe(false); + expect(result.getToken().getValue()).toEqual(refreshedToken.getValue()); + expect(result.getToken().getOwnerStrategyName()).toEqual(refreshedToken.getOwnerStrategyName()); + expect(result.getMessages()).toEqual(successMessages); + expect(result.getErrors()).toEqual([]); // no error message, response is success + expect(result.getRedirect()).toEqual('/'); + done(); + }); - httpMock.expectOne( - req => { + httpMock + .expectOne((req) => { const params = parseQueryParams(req.body); - return (req.url === 'http://example.com/token' - && req.headers.get('Content-Type') === 'application/x-www-form-urlencoded' - && decodeURIComponent(params['grant_type']) === NbOAuth2GrantType.REFRESH_TOKEN - && decodeURIComponent(params['refresh_token']) === successToken.getRefreshToken() - && !params['scope']) - }, - ) - .flush(tokenWithoutRefreshTokenResponse); + return ( + req.url === 'http://example.com/token' && + req.headers.get('Content-Type') === 'application/x-www-form-urlencoded' && + decodeURIComponent(params.grant_type) === NbOAuth2GrantType.REFRESH_TOKEN && + decodeURIComponent(params.refresh_token) === successToken.getRefreshToken() && + !params.scope + ); + }) + .flush(tokenWithoutRefreshTokenResponse); }); it('Handle refresh-token and leaves refresh_token unchanged if present', (done: DoneFn) => { strategy.setOptions(basicOptions); - strategy.refreshToken(successToken) - .subscribe((result: NbAuthResult) => { - expect(result).toBeTruthy(); - expect(result.isSuccess()).toBe(true); - expect(result.isFailure()).toBe(false); - expect(result.getToken().getValue()).toEqual(refreshedTokenWithRefreshToken.getValue()); - expect(result.getToken().getOwnerStrategyName()). - toEqual(refreshedTokenWithRefreshToken.getOwnerStrategyName()); - expect(result.getMessages()).toEqual(successMessages); - expect(result.getErrors()).toEqual([]); // no error message, response is success - expect(result.getRedirect()).toEqual('/'); - done(); - }); + strategy.refreshToken(successToken).subscribe((result: NbAuthResult) => { + expect(result).toBeTruthy(); + expect(result.isSuccess()).toBe(true); + expect(result.isFailure()).toBe(false); + expect(result.getToken().getValue()).toEqual(refreshedTokenWithRefreshToken.getValue()); + expect(result.getToken().getOwnerStrategyName()).toEqual(refreshedTokenWithRefreshToken.getOwnerStrategyName()); + expect(result.getMessages()).toEqual(successMessages); + expect(result.getErrors()).toEqual([]); // no error message, response is success + expect(result.getRedirect()).toEqual('/'); + done(); + }); - httpMock.expectOne( - req => { + httpMock + .expectOne((req) => { const params = parseQueryParams(req.body); - return (req.url === 'http://example.com/token' - && req.headers.get('Content-Type') === 'application/x-www-form-urlencoded' - && decodeURIComponent(params['grant_type']) === NbOAuth2GrantType.REFRESH_TOKEN - && decodeURIComponent(params['refresh_token']) === successToken.getRefreshToken() - && !params['scope']) - }, - ) - .flush(refreshedTokenResponse); + return ( + req.url === 'http://example.com/token' && + req.headers.get('Content-Type') === 'application/x-www-form-urlencoded' && + decodeURIComponent(params.grant_type) === NbOAuth2GrantType.REFRESH_TOKEN && + decodeURIComponent(params.refresh_token) === successToken.getRefreshToken() && + !params.scope + ); + }) + .flush(refreshedTokenResponse); }); it('handle error token refresh response', (done: DoneFn) => { + strategy.refreshToken(successToken).subscribe((result: NbAuthResult) => { + expect(result).toBeTruthy(); + expect(result.isSuccess()).toBe(false); + expect(result.isFailure()).toBe(true); + expect(result.getToken()).toBeNull(); // we don't have a token at this stage yet + expect(result.getResponse().error).toEqual(tokenErrorResponse); + expect(result.getMessages()).toEqual([]); + expect(result.getErrors()).toEqual([tokenErrorResponse.error_description]); + expect(result.getRedirect()).toEqual(null); + done(); + }); - strategy.refreshToken(successToken) - .subscribe((result: NbAuthResult) => { - expect(result).toBeTruthy(); - expect(result.isSuccess()).toBe(false); - expect(result.isFailure()).toBe(true); - expect(result.getToken()).toBeNull(); // we don't have a token at this stage yet - expect(result.getResponse().error).toEqual(tokenErrorResponse); - expect(result.getMessages()).toEqual([]); - expect(result.getErrors()).toEqual([ tokenErrorResponse.error_description] ); - expect(result.getRedirect()).toEqual(null); - done(); - }); - - httpMock.expectOne( - req => { - return (req.url === 'http://example.com/token' - && req.headers.get('Content-Type') === 'application/x-www-form-urlencoded' - ) - }, - ) + httpMock + .expectOne((req) => { + return ( + req.url === 'http://example.com/token' && + req.headers.get('Content-Type') === 'application/x-www-form-urlencoded' + ); + }) .flush(tokenErrorResponse, { status: 400, statusText: 'Bad Request' }); }); }); describe('configured: type TOKEN', () => { - const basicOptions = { name: 'strategy', baseEndpoint: 'http://example.com/', @@ -391,7 +393,7 @@ describe('oauth2-auth-strategy', () => { authorize: { responseType: NbOAuth2ResponseType.TOKEN, }, - } + }; beforeEach(() => { strategy.setOptions(basicOptions); @@ -405,8 +407,7 @@ describe('oauth2-auth-strategy', () => { }, }; - strategy.authenticate() - .subscribe(() => {}); + strategy.authenticate().subscribe(() => {}); }); it('handle success redirect back with token', (done: DoneFn) => { @@ -414,40 +415,39 @@ describe('oauth2-auth-strategy', () => { routeMock.snapshot.fragment = createURL(token); - strategy.authenticate() - .subscribe((result: NbAuthResult) => { - expect(result).toBeTruthy(); - expect(result.isSuccess()).toBe(true); - expect(result.isFailure()).toBe(false); - // eslint-disable-next-line - expect(result.getToken().getValue()).toEqual(nbAuthCreateToken(NbAuthOAuth2Token, token, 'strategy').getValue()); - expect(result.getMessages()).toEqual(successMessages); - expect(result.getErrors()).toEqual([]); // no error message, response is success - expect(result.getRedirect()).toEqual('/'); - done(); - }); + strategy.authenticate().subscribe((result: NbAuthResult) => { + expect(result).toBeTruthy(); + expect(result.isSuccess()).toBe(true); + expect(result.isFailure()).toBe(false); + // eslint-disable-next-line + expect(result.getToken().getValue()).toEqual( + nbAuthCreateToken(NbAuthOAuth2Token, token, 'strategy').getValue(), + ); + expect(result.getMessages()).toEqual(successMessages); + expect(result.getErrors()).toEqual([]); // no error message, response is success + expect(result.getRedirect()).toEqual('/'); + done(); + }); }); it('handle error redirect back', (done: DoneFn) => { routeMock.snapshot.fragment = createURL(tokenErrorResponse); - strategy.authenticate() - .subscribe((result: NbAuthResult) => { - expect(result).toBeTruthy(); - expect(result.isSuccess()).toBe(false); - expect(result.isFailure()).toBe(true); - expect(result.getToken()).toBeNull(); // we don't have a token at this stage yet - expect(result.getResponse()).toEqual(tokenErrorResponse); - expect(result.getMessages()).toEqual([]); - expect(result.getErrors()).toEqual(errorMessages); - expect(result.getRedirect()).toEqual(null); - done(); - }); + strategy.authenticate().subscribe((result: NbAuthResult) => { + expect(result).toBeTruthy(); + expect(result.isSuccess()).toBe(false); + expect(result.isFailure()).toBe(true); + expect(result.getToken()).toBeNull(); // we don't have a token at this stage yet + expect(result.getResponse()).toEqual(tokenErrorResponse); + expect(result.getMessages()).toEqual([]); + expect(result.getErrors()).toEqual(errorMessages); + expect(result.getRedirect()).toEqual(null); + done(); + }); }); }); describe('configured redirect, redirectUri, scope and additional params: type TOKEN', () => { - const basicOptions = { name: 'strategy', baseEndpoint: 'http://example.com/', @@ -473,7 +473,7 @@ describe('oauth2-auth-strategy', () => { endpoint: 'custom', scope: 'read', }, - } + }; beforeEach(() => { strategy.setOptions(basicOptions); @@ -491,260 +491,255 @@ describe('oauth2-auth-strategy', () => { }, }; - strategy.authenticate() - .subscribe(() => {}); + strategy.authenticate().subscribe(() => {}); }); it('handle success redirect and sends correct token request with NO client Auth', (done: DoneFn) => { routeMock.snapshot.queryParams = { code: 'code' }; - strategy.authenticate() - .subscribe((result: NbAuthResult) => { - expect(result).toBeTruthy(); - expect(result.isSuccess()).toBe(true); - expect(result.isFailure()).toBe(false); - expect(result.getToken().getValue()).toEqual(successToken.getValue()); - expect(result.getToken().getOwnerStrategyName()).toEqual(successToken.getOwnerStrategyName()); - expect(result.getMessages()).toEqual(successMessages); - expect(result.getErrors()).toEqual([]); // no error message, response is success - expect(result.getRedirect()).toEqual('/success'); - done(); - }); + strategy.authenticate().subscribe((result: NbAuthResult) => { + expect(result).toBeTruthy(); + expect(result.isSuccess()).toBe(true); + expect(result.isFailure()).toBe(false); + expect(result.getToken().getValue()).toEqual(successToken.getValue()); + expect(result.getToken().getOwnerStrategyName()).toEqual(successToken.getOwnerStrategyName()); + expect(result.getMessages()).toEqual(successMessages); + expect(result.getErrors()).toEqual([]); // no error message, response is success + expect(result.getRedirect()).toEqual('/success'); + done(); + }); - httpMock.expectOne( - req => { + httpMock + .expectOne((req) => { const params = parseQueryParams(req.body); - return (req.url === 'http://example.com/custom' - && req.headers.get('Content-Type') === 'application/x-www-form-urlencoded' - && decodeURIComponent(params['grant_type']) === NbOAuth2GrantType.AUTHORIZATION_CODE - && decodeURIComponent(params['code']) === 'code' - && decodeURIComponent(params['client_id']) === 'clientId' - && decodeURIComponent(params['redirect_uri']) === 'http://localhost:4200/callback') - }, - ) - .flush(tokenSuccessResponse); + return ( + req.url === 'http://example.com/custom' && + req.headers.get('Content-Type') === 'application/x-www-form-urlencoded' && + decodeURIComponent(params.grant_type) === NbOAuth2GrantType.AUTHORIZATION_CODE && + decodeURIComponent(params.code) === 'code' && + decodeURIComponent(params.client_id) === 'clientId' && + decodeURIComponent(params.redirect_uri) === 'http://localhost:4200/callback' + ); + }) + .flush(tokenSuccessResponse); }); it('handle success redirect and sends correct token request with BASIC client Auth', (done: DoneFn) => { routeMock.snapshot.queryParams = { code: 'code' }; strategy.setOptions({ - ... basicOptions, + ...basicOptions, clientSecret: 'clientSecret', clientAuthMethod: NbOAuth2ClientAuthMethod.BASIC, - }) - - strategy.authenticate() - .subscribe((result: NbAuthResult) => { - expect(result).toBeTruthy(); - expect(result.isSuccess()).toBe(true); - expect(result.isFailure()).toBe(false); - expect(result.getToken().getValue()).toEqual(successToken.getValue()); - expect(result.getToken().getOwnerStrategyName()).toEqual(successToken.getOwnerStrategyName()); - expect(result.getMessages()).toEqual(successMessages); - expect(result.getErrors()).toEqual([]); // no error message, response is success - expect(result.getRedirect()).toEqual('/success'); - done(); - }); + }); - httpMock.expectOne( - req => { + strategy.authenticate().subscribe((result: NbAuthResult) => { + expect(result).toBeTruthy(); + expect(result.isSuccess()).toBe(true); + expect(result.isFailure()).toBe(false); + expect(result.getToken().getValue()).toEqual(successToken.getValue()); + expect(result.getToken().getOwnerStrategyName()).toEqual(successToken.getOwnerStrategyName()); + expect(result.getMessages()).toEqual(successMessages); + expect(result.getErrors()).toEqual([]); // no error message, response is success + expect(result.getRedirect()).toEqual('/success'); + done(); + }); + + httpMock + .expectOne((req) => { const params = parseQueryParams(req.body); - return (req.url === 'http://example.com/custom' - && req.headers.get('Authorization') === authHeader - && req.headers.get('Content-Type') === 'application/x-www-form-urlencoded' - && decodeURIComponent(params['grant_type']) === NbOAuth2GrantType.AUTHORIZATION_CODE - && decodeURIComponent(params['code']) === 'code' - && decodeURIComponent(params['client_id']) === 'clientId' - && decodeURIComponent(params['redirect_uri']) === 'http://localhost:4200/callback') - }, - ) - .flush(tokenSuccessResponse); + return ( + req.url === 'http://example.com/custom' && + req.headers.get('Authorization') === authHeader && + req.headers.get('Content-Type') === 'application/x-www-form-urlencoded' && + decodeURIComponent(params.grant_type) === NbOAuth2GrantType.AUTHORIZATION_CODE && + decodeURIComponent(params.code) === 'code' && + decodeURIComponent(params.client_id) === 'clientId' && + decodeURIComponent(params.redirect_uri) === 'http://localhost:4200/callback' + ); + }) + .flush(tokenSuccessResponse); }); it('handle success redirect and sends correct token request with REQUEST_BODY client Auth', (done: DoneFn) => { routeMock.snapshot.queryParams = { code: 'code' }; strategy.setOptions({ - ... basicOptions, + ...basicOptions, clientSecret: 'clientSecret', clientAuthMethod: NbOAuth2ClientAuthMethod.REQUEST_BODY, - }) - - strategy.authenticate() - .subscribe((result: NbAuthResult) => { - expect(result).toBeTruthy(); - expect(result.isSuccess()).toBe(true); - expect(result.isFailure()).toBe(false); - expect(result.getToken().getValue()).toEqual(successToken.getValue()); - expect(result.getToken().getOwnerStrategyName()).toEqual(successToken.getOwnerStrategyName()); - expect(result.getMessages()).toEqual(successMessages); - expect(result.getErrors()).toEqual([]); // no error message, response is success - expect(result.getRedirect()).toEqual('/success'); - done(); - }); + }); + + strategy.authenticate().subscribe((result: NbAuthResult) => { + expect(result).toBeTruthy(); + expect(result.isSuccess()).toBe(true); + expect(result.isFailure()).toBe(false); + expect(result.getToken().getValue()).toEqual(successToken.getValue()); + expect(result.getToken().getOwnerStrategyName()).toEqual(successToken.getOwnerStrategyName()); + expect(result.getMessages()).toEqual(successMessages); + expect(result.getErrors()).toEqual([]); // no error message, response is success + expect(result.getRedirect()).toEqual('/success'); + done(); + }); - httpMock.expectOne( - req => { + httpMock + .expectOne((req) => { const params = parseQueryParams(req.body); - return (req.url === 'http://example.com/custom' - && req.headers.get('Content-Type') === 'application/x-www-form-urlencoded' - && decodeURIComponent(params['grant_type']) === NbOAuth2GrantType.AUTHORIZATION_CODE - && decodeURIComponent(params['code']) === 'code' - && decodeURIComponent(params['client_id']) === strategy.getOption('clientId') - && decodeURIComponent(params['client_secret']) === strategy.getOption('clientSecret') - && decodeURIComponent(params['redirect_uri']) === 'http://localhost:4200/callback') - }, - ) - .flush(tokenSuccessResponse); + return ( + req.url === 'http://example.com/custom' && + req.headers.get('Content-Type') === 'application/x-www-form-urlencoded' && + decodeURIComponent(params.grant_type) === NbOAuth2GrantType.AUTHORIZATION_CODE && + decodeURIComponent(params.code) === 'code' && + decodeURIComponent(params.client_id) === strategy.getOption('clientId') && + decodeURIComponent(params.client_secret) === strategy.getOption('clientSecret') && + decodeURIComponent(params.redirect_uri) === 'http://localhost:4200/callback' + ); + }) + .flush(tokenSuccessResponse); }); it('handle error redirect back', (done: DoneFn) => { routeMock.snapshot.queryParams = tokenErrorResponse; - strategy.authenticate() - .subscribe((result: NbAuthResult) => { - expect(result).toBeTruthy(); - expect(result.isSuccess()).toBe(false); - expect(result.isFailure()).toBe(true); - expect(result.getToken()).toBeNull(); - expect(result.getResponse()).toEqual(tokenErrorResponse); - expect(result.getMessages()).toEqual([]); - expect(result.getErrors()).toEqual(errorMessages); - expect(result.getRedirect()).toEqual('/failure'); - done(); - }); + strategy.authenticate().subscribe((result: NbAuthResult) => { + expect(result).toBeTruthy(); + expect(result.isSuccess()).toBe(false); + expect(result.isFailure()).toBe(true); + expect(result.getToken()).toBeNull(); + expect(result.getResponse()).toEqual(tokenErrorResponse); + expect(result.getMessages()).toEqual([]); + expect(result.getErrors()).toEqual(errorMessages); + expect(result.getRedirect()).toEqual('/failure'); + done(); + }); }); it('handle refresh token with NO client auth', (done: DoneFn) => { strategy.setOptions({ - ... basicOptions, + ...basicOptions, clientId: 'clientId', }); - strategy.refreshToken(successToken) - .subscribe((result: NbAuthResult) => { - expect(result).toBeTruthy(); - expect(result.isSuccess()).toBe(true); - expect(result.isFailure()).toBe(false); - expect(result.getToken().getValue()).toEqual(successToken.getValue()); - expect(result.getToken().getOwnerStrategyName()).toEqual(successToken.getOwnerStrategyName()); - expect(result.getMessages()).toEqual(successMessages); - expect(result.getErrors()).toEqual([]); // no error message, response is success - expect(result.getRedirect()).toEqual('/success'); - done(); - }); + strategy.refreshToken(successToken).subscribe((result: NbAuthResult) => { + expect(result).toBeTruthy(); + expect(result.isSuccess()).toBe(true); + expect(result.isFailure()).toBe(false); + expect(result.getToken().getValue()).toEqual(successToken.getValue()); + expect(result.getToken().getOwnerStrategyName()).toEqual(successToken.getOwnerStrategyName()); + expect(result.getMessages()).toEqual(successMessages); + expect(result.getErrors()).toEqual([]); // no error message, response is success + expect(result.getRedirect()).toEqual('/success'); + done(); + }); - httpMock.expectOne( - req => { + httpMock + .expectOne((req) => { const params = parseQueryParams(req.body); - return (req.url === 'http://example.com/custom' - && req.headers.get('Content-Type') === 'application/x-www-form-urlencoded' - && decodeURIComponent(params['grant_type']) === NbOAuth2GrantType.REFRESH_TOKEN - && decodeURIComponent(params['refresh_token']) === successToken.getRefreshToken() - && decodeURIComponent(params['scope']) === 'read' - && decodeURIComponent(params['client_id']) === 'clientId') - }, - ) - .flush(tokenSuccessResponse); + return ( + req.url === 'http://example.com/custom' && + req.headers.get('Content-Type') === 'application/x-www-form-urlencoded' && + decodeURIComponent(params.grant_type) === NbOAuth2GrantType.REFRESH_TOKEN && + decodeURIComponent(params.refresh_token) === successToken.getRefreshToken() && + decodeURIComponent(params.scope) === 'read' && + decodeURIComponent(params.client_id) === 'clientId' + ); + }) + .flush(tokenSuccessResponse); }); it('handle refresh token with BASIC client auth', (done: DoneFn) => { strategy.setOptions({ - ... basicOptions, + ...basicOptions, clientSecret: 'clientSecret', clientAuthMethod: NbOAuth2ClientAuthMethod.BASIC, }); - strategy.refreshToken(successToken) - .subscribe((result: NbAuthResult) => { - expect(result).toBeTruthy(); - expect(result.isSuccess()).toBe(true); - expect(result.isFailure()).toBe(false); - expect(result.getToken().getValue()).toEqual(successToken.getValue()); - expect(result.getToken().getOwnerStrategyName()).toEqual(successToken.getOwnerStrategyName()); - expect(result.getMessages()).toEqual(successMessages); - expect(result.getErrors()).toEqual([]); // no error message, response is success - expect(result.getRedirect()).toEqual('/success'); - done(); - }); + strategy.refreshToken(successToken).subscribe((result: NbAuthResult) => { + expect(result).toBeTruthy(); + expect(result.isSuccess()).toBe(true); + expect(result.isFailure()).toBe(false); + expect(result.getToken().getValue()).toEqual(successToken.getValue()); + expect(result.getToken().getOwnerStrategyName()).toEqual(successToken.getOwnerStrategyName()); + expect(result.getMessages()).toEqual(successMessages); + expect(result.getErrors()).toEqual([]); // no error message, response is success + expect(result.getRedirect()).toEqual('/success'); + done(); + }); - httpMock.expectOne( - req => { + httpMock + .expectOne((req) => { const params = parseQueryParams(req.body); - return (req.url === 'http://example.com/custom' - && req.headers.get('Authorization') === authHeader - && req.headers.get('Content-Type') === 'application/x-www-form-urlencoded' - && decodeURIComponent(params['grant_type']) === NbOAuth2GrantType.REFRESH_TOKEN - && decodeURIComponent(params['refresh_token']) === successToken.getRefreshToken() - && decodeURIComponent(params['scope']) === 'read') - }, - ) - .flush(tokenSuccessResponse); + return ( + req.url === 'http://example.com/custom' && + req.headers.get('Authorization') === authHeader && + req.headers.get('Content-Type') === 'application/x-www-form-urlencoded' && + decodeURIComponent(params.grant_type) === NbOAuth2GrantType.REFRESH_TOKEN && + decodeURIComponent(params.refresh_token) === successToken.getRefreshToken() && + decodeURIComponent(params.scope) === 'read' + ); + }) + .flush(tokenSuccessResponse); }); it('handle refresh token with REQUEST_BODY client auth', (done: DoneFn) => { strategy.setOptions({ - ... basicOptions, + ...basicOptions, clientSecret: 'clientSecret', clientAuthMethod: NbOAuth2ClientAuthMethod.REQUEST_BODY, }); - strategy.refreshToken(successToken) - .subscribe((result: NbAuthResult) => { - expect(result).toBeTruthy(); - expect(result.isSuccess()).toBe(true); - expect(result.isFailure()).toBe(false); - expect(result.getToken().getValue()).toEqual(successToken.getValue()); - expect(result.getToken().getOwnerStrategyName()).toEqual(successToken.getOwnerStrategyName()); - expect(result.getMessages()).toEqual(successMessages); - expect(result.getErrors()).toEqual([]); // no error message, response is success - expect(result.getRedirect()).toEqual('/success'); - done(); - }); + strategy.refreshToken(successToken).subscribe((result: NbAuthResult) => { + expect(result).toBeTruthy(); + expect(result.isSuccess()).toBe(true); + expect(result.isFailure()).toBe(false); + expect(result.getToken().getValue()).toEqual(successToken.getValue()); + expect(result.getToken().getOwnerStrategyName()).toEqual(successToken.getOwnerStrategyName()); + expect(result.getMessages()).toEqual(successMessages); + expect(result.getErrors()).toEqual([]); // no error message, response is success + expect(result.getRedirect()).toEqual('/success'); + done(); + }); - httpMock.expectOne( - req => { + httpMock + .expectOne((req) => { const params = parseQueryParams(req.body); - return (req.url === 'http://example.com/custom' - && req.headers.get('Content-Type') === 'application/x-www-form-urlencoded' - && decodeURIComponent(params['grant_type']) === NbOAuth2GrantType.REFRESH_TOKEN - && decodeURIComponent(params['refresh_token']) === successToken.getRefreshToken() - && decodeURIComponent(params['client_id']) === strategy.getOption('clientId') - && decodeURIComponent(params['client_secret']) === strategy.getOption('clientSecret') - && decodeURIComponent(params['scope']) === 'read') - }, - ) - .flush(tokenSuccessResponse); + return ( + req.url === 'http://example.com/custom' && + req.headers.get('Content-Type') === 'application/x-www-form-urlencoded' && + decodeURIComponent(params.grant_type) === NbOAuth2GrantType.REFRESH_TOKEN && + decodeURIComponent(params.refresh_token) === successToken.getRefreshToken() && + decodeURIComponent(params.client_id) === strategy.getOption('clientId') && + decodeURIComponent(params.client_secret) === strategy.getOption('clientSecret') && + decodeURIComponent(params.scope) === 'read' + ); + }) + .flush(tokenSuccessResponse); }); it('handle error token response', (done: DoneFn) => { routeMock.snapshot.queryParams = { code: 'code' }; - strategy.authenticate() - .subscribe((result: NbAuthResult) => { - - expect(result).toBeTruthy(); - expect(result.isSuccess()).toBe(false); - expect(result.isFailure()).toBe(true); - expect(result.getToken()).toBeNull(); - expect(result.getResponse().error).toEqual(tokenErrorResponse); - expect(result.getMessages()).toEqual([]); - expect(result.getErrors()).toEqual([ tokenErrorResponse.error_description] ); - expect(result.getRedirect()).toEqual('/failure'); - done(); - }); - - httpMock.expectOne( - req => { - return (req.url === 'http://example.com/custom' - && req.headers.get('Content-Type') === 'application/x-www-form-urlencoded' - ) - }, - ) + strategy.authenticate().subscribe((result: NbAuthResult) => { + expect(result).toBeTruthy(); + expect(result.isSuccess()).toBe(false); + expect(result.isFailure()).toBe(true); + expect(result.getToken()).toBeNull(); + expect(result.getResponse().error).toEqual(tokenErrorResponse); + expect(result.getMessages()).toEqual([]); + expect(result.getErrors()).toEqual([tokenErrorResponse.error_description]); + expect(result.getRedirect()).toEqual('/failure'); + done(); + }); + + httpMock + .expectOne((req) => { + return ( + req.url === 'http://example.com/custom' && + req.headers.get('Content-Type') === 'application/x-www-form-urlencoded' + ); + }) .flush(tokenErrorResponse, { status: 400, statusText: 'Bad Request' }); }); }); describe('configured: additionnal param: token, grant_type:password', () => { - const scope = 'theScope'; const basicOptions = { name: 'strategy', @@ -763,132 +758,135 @@ describe('oauth2-auth-strategy', () => { it('handle success login with NO client auth', (done: DoneFn) => { const credentials = { email: 'example@akveo.com', password: '123456' }; - strategy.authenticate(credentials) - .subscribe((result: NbAuthResult) => { - expect(result).toBeTruthy(); - expect(result.isSuccess()).toBe(true); - expect(result.isFailure()).toBe(false); - expect(result.getToken().getValue()).toEqual(successToken.getValue()); - expect(result.getToken().getOwnerStrategyName()).toEqual(successToken.getOwnerStrategyName()); - expect(result.getMessages()).toEqual(successMessages); - expect(result.getErrors()).toEqual([]); // no error message, response is success - expect(result.getRedirect()).toEqual('/'); - done(); - }); + strategy.authenticate(credentials).subscribe((result: NbAuthResult) => { + expect(result).toBeTruthy(); + expect(result.isSuccess()).toBe(true); + expect(result.isFailure()).toBe(false); + expect(result.getToken().getValue()).toEqual(successToken.getValue()); + expect(result.getToken().getOwnerStrategyName()).toEqual(successToken.getOwnerStrategyName()); + expect(result.getMessages()).toEqual(successMessages); + expect(result.getErrors()).toEqual([]); // no error message, response is success + expect(result.getRedirect()).toEqual('/'); + done(); + }); - httpMock.expectOne( - req => { + httpMock + .expectOne((req) => { const params = parseQueryParams(req.body); - return (req.url === 'http://example.com/token' - && req.headers.get('Content-Type') === 'application/x-www-form-urlencoded' - && decodeURIComponent(params['grant_type']) === NbOAuth2GrantType.PASSWORD - && decodeURIComponent(params['username']) === credentials.email - && decodeURIComponent(params['password']) === credentials.password - && decodeURIComponent(params['scope']) === scope) - }, - ) + return ( + req.url === 'http://example.com/token' && + req.headers.get('Content-Type') === 'application/x-www-form-urlencoded' && + decodeURIComponent(params.grant_type) === NbOAuth2GrantType.PASSWORD && + decodeURIComponent(params.username) === credentials.email && + decodeURIComponent(params.password) === credentials.password && + decodeURIComponent(params.scope) === scope + ); + }) .flush(tokenSuccessResponse); }); it('handle success login with BASIC client auth', (done: DoneFn) => { const credentials = { email: 'example@akveo.com', password: '123456' }; strategy.setOptions({ - ... basicOptions, + ...basicOptions, clientSecret: 'clientSecret', clientAuthMethod: NbOAuth2ClientAuthMethod.BASIC, - }) - - strategy.authenticate(credentials) - .subscribe((result: NbAuthResult) => { - expect(result).toBeTruthy(); - expect(result.isSuccess()).toBe(true); - expect(result.isFailure()).toBe(false); - expect(result.getToken().getValue()).toEqual(successToken.getValue()); - expect(result.getToken().getOwnerStrategyName()).toEqual(successToken.getOwnerStrategyName()); - expect(result.getMessages()).toEqual(successMessages); - expect(result.getErrors()).toEqual([]); // no error message, response is success - expect(result.getRedirect()).toEqual('/'); - done(); - }); + }); + + strategy.authenticate(credentials).subscribe((result: NbAuthResult) => { + expect(result).toBeTruthy(); + expect(result.isSuccess()).toBe(true); + expect(result.isFailure()).toBe(false); + expect(result.getToken().getValue()).toEqual(successToken.getValue()); + expect(result.getToken().getOwnerStrategyName()).toEqual(successToken.getOwnerStrategyName()); + expect(result.getMessages()).toEqual(successMessages); + expect(result.getErrors()).toEqual([]); // no error message, response is success + expect(result.getRedirect()).toEqual('/'); + done(); + }); - httpMock.expectOne( - req => { + httpMock + .expectOne((req) => { const params = parseQueryParams(req.body); - return (req.url === 'http://example.com/token' - && req.headers.get('Content-Type') === 'application/x-www-form-urlencoded' - && req.headers.get('Authorization') === authHeader - && decodeURIComponent(params['grant_type']) === NbOAuth2GrantType.PASSWORD - && decodeURIComponent(params['username']) === credentials.email - && decodeURIComponent(params['password']) === credentials.password - && decodeURIComponent(params['scope']) === scope) - }, - ).flush(tokenSuccessResponse); + return ( + req.url === 'http://example.com/token' && + req.headers.get('Content-Type') === 'application/x-www-form-urlencoded' && + req.headers.get('Authorization') === authHeader && + decodeURIComponent(params.grant_type) === NbOAuth2GrantType.PASSWORD && + decodeURIComponent(params.username) === credentials.email && + decodeURIComponent(params.password) === credentials.password && + decodeURIComponent(params.scope) === scope + ); + }) + .flush(tokenSuccessResponse); }); it('handle success login with REQUEST_BODY client auth', (done: DoneFn) => { const credentials = { email: 'example@akveo.com', password: '123456' }; strategy.setOptions({ - ... basicOptions, + ...basicOptions, clientSecret: 'clientSecret', clientAuthMethod: NbOAuth2ClientAuthMethod.REQUEST_BODY, - }) - - strategy.authenticate(credentials) - .subscribe((result: NbAuthResult) => { - expect(result).toBeTruthy(); - expect(result.isSuccess()).toBe(true); - expect(result.isFailure()).toBe(false); - expect(result.getToken().getValue()).toEqual(successToken.getValue()); - expect(result.getToken().getOwnerStrategyName()).toEqual(successToken.getOwnerStrategyName()); - expect(result.getMessages()).toEqual(successMessages); - expect(result.getErrors()).toEqual([]); // no error message, response is success - expect(result.getRedirect()).toEqual('/'); - done(); - }); + }); + + strategy.authenticate(credentials).subscribe((result: NbAuthResult) => { + expect(result).toBeTruthy(); + expect(result.isSuccess()).toBe(true); + expect(result.isFailure()).toBe(false); + expect(result.getToken().getValue()).toEqual(successToken.getValue()); + expect(result.getToken().getOwnerStrategyName()).toEqual(successToken.getOwnerStrategyName()); + expect(result.getMessages()).toEqual(successMessages); + expect(result.getErrors()).toEqual([]); // no error message, response is success + expect(result.getRedirect()).toEqual('/'); + done(); + }); - httpMock.expectOne( - req => { + httpMock + .expectOne((req) => { const params = parseQueryParams(req.body); - return (req.url === 'http://example.com/token' - && req.headers.get('Content-Type') === 'application/x-www-form-urlencoded' - && decodeURIComponent(params['grant_type']) === NbOAuth2GrantType.PASSWORD - && decodeURIComponent(params['username']) === credentials.email - && decodeURIComponent(params['password']) === credentials.password - && decodeURIComponent(params['scope']) === scope - && decodeURIComponent(params['client_id']) === strategy.getOption('clientId') - && decodeURIComponent(params['client_secret']) === strategy.getOption('clientSecret')) - }, - ).flush(tokenSuccessResponse); + return ( + req.url === 'http://example.com/token' && + req.headers.get('Content-Type') === 'application/x-www-form-urlencoded' && + decodeURIComponent(params.grant_type) === NbOAuth2GrantType.PASSWORD && + decodeURIComponent(params.username) === credentials.email && + decodeURIComponent(params.password) === credentials.password && + decodeURIComponent(params.scope) === scope && + decodeURIComponent(params.client_id) === strategy.getOption('clientId') && + decodeURIComponent(params.client_secret) === strategy.getOption('clientSecret') + ); + }) + .flush(tokenSuccessResponse); }); it('handle error login', (done: DoneFn) => { strategy.setOptions(basicOptions); const credentials = { email: 'example@akveo.com', password: '123456' }; - strategy.authenticate(credentials) - .subscribe((result: NbAuthResult) => { - expect(result).toBeTruthy(); - expect(result.isSuccess()).toBe(false); - expect(result.isFailure()).toBe(true); - expect(result.getToken()).toBeNull(); // we don't have a token at this stage yet - expect(result.getResponse().error).toEqual(tokenErrorResponse); - expect(result.getMessages()).toEqual([]); - expect(result.getErrors()).toEqual([tokenErrorResponse.error_description]); - expect(result.getRedirect()).toEqual(null); - done(); - }); - - httpMock.expectOne( - req => { - const params = parseQueryParams(req.body); - return (req.url === 'http://example.com/token' - && req.headers.get('Content-Type') === 'application/x-www-form-urlencoded' - && decodeURIComponent(params['grant_type']) === NbOAuth2GrantType.PASSWORD - && decodeURIComponent(params['username']) === credentials.email - && decodeURIComponent(params['password']) === credentials.password - && decodeURIComponent(params['scope']) === scope) - }, - ).flush(tokenErrorResponse, {status: 401, statusText: 'unauthorized'}); + strategy.authenticate(credentials).subscribe((result: NbAuthResult) => { + expect(result).toBeTruthy(); + expect(result.isSuccess()).toBe(false); + expect(result.isFailure()).toBe(true); + expect(result.getToken()).toBeNull(); // we don't have a token at this stage yet + expect(result.getResponse().error).toEqual(tokenErrorResponse); + expect(result.getMessages()).toEqual([]); + expect(result.getErrors()).toEqual([tokenErrorResponse.error_description]); + expect(result.getRedirect()).toEqual(null); + done(); + }); + + httpMock + .expectOne((req) => { + const params = parseQueryParams(req.body); + return ( + req.url === 'http://example.com/token' && + req.headers.get('Content-Type') === 'application/x-www-form-urlencoded' && + decodeURIComponent(params.grant_type) === NbOAuth2GrantType.PASSWORD && + decodeURIComponent(params.username) === credentials.email && + decodeURIComponent(params.password) === credentials.password && + decodeURIComponent(params.scope) === scope + ); + }) + .flush(tokenErrorResponse, { status: 401, statusText: 'unauthorized' }); }); }); }); diff --git a/src/framework/auth/strategies/password/password-strategy.spec.ts b/src/framework/auth/strategies/password/password-strategy.spec.ts index 3283497798..8127602265 100644 --- a/src/framework/auth/strategies/password/password-strategy.spec.ts +++ b/src/framework/auth/strategies/password/password-strategy.spec.ts @@ -5,26 +5,22 @@ */ import { inject, TestBed, waitForAsync } from '@angular/core/testing'; -import { NbPasswordAuthStrategy } from './password-strategy'; -import { NbAuthResult } from '../../services/auth-result'; - +import { HttpErrorResponse, HttpResponse } from '@angular/common/http'; import { HttpClientTestingModule, HttpTestingController } from '@angular/common/http/testing'; import { RouterTestingModule } from '@angular/router/testing'; -import { HttpErrorResponse, HttpResponse } from '@angular/common/http'; -import { nbAuthCreateToken, NbAuthSimpleToken } from '../../services/token/token'; +import { NbPasswordAuthStrategy, NbAuthResult, nbAuthCreateToken, NbAuthSimpleToken } from '@nebular/auth'; const ownerStrategyName = 'strategy'; describe('password-auth-strategy', () => { - let strategy: NbPasswordAuthStrategy; let httpMock: HttpTestingController; const successResponse: any = { data: { - 'token': 'token', - 'messages': ['Success message'], - 'errors': ['Error message'], + token: 'token', + messages: ['Success message'], + errors: ['Error message'], }, }; @@ -32,262 +28,239 @@ describe('password-auth-strategy', () => { const noMessageResponse: any = { data: { - 'token': 'token', + token: 'token', }, }; const customResponse: any = { - 'token': 'token', - 'messages': ['Success message'], - 'errors': ['Error message'], + token: 'token', + messages: ['Success message'], + errors: ['Error message'], }; const loginData: any = { email: 'test@test.com', password: '123456' }; beforeEach(() => { TestBed.configureTestingModule({ imports: [HttpClientTestingModule, RouterTestingModule], - providers: [ - { provide: NbPasswordAuthStrategy, useClass: NbPasswordAuthStrategy }, - ], + providers: [{ provide: NbPasswordAuthStrategy, useClass: NbPasswordAuthStrategy }], }); }); - beforeEach(waitForAsync(inject( - [NbPasswordAuthStrategy, HttpTestingController], - (_strategy, _httpMock) => { - strategy = _strategy; - httpMock = _httpMock; + beforeEach( + waitForAsync( + inject([NbPasswordAuthStrategy, HttpTestingController], (_strategy, _httpMock) => { + strategy = _strategy; + httpMock = _httpMock; - strategy.setOptions({name: ownerStrategyName}); - }, - ))); + strategy.setOptions({ name: ownerStrategyName }); + }), + ), + ); afterEach(() => { httpMock.verify(); }); describe('out of the box', () => { - beforeEach(() => { - strategy.setOptions({name: ownerStrategyName}); + strategy.setOptions({ name: ownerStrategyName }); }); it('authenticate success', (done: DoneFn) => { - strategy.authenticate(loginData) - .subscribe((result: NbAuthResult) => { - expect(result).toBeTruthy(); - expect(result.isSuccess()).toBe(true); - expect(result.isFailure()).toBe(false); - expect(result.getMessages()).toEqual(successResponse.data.messages); - expect(result.getErrors()).toEqual([]); // no error message, response is success - expect(result.getToken().getValue()).toEqual(successToken.getValue()); - expect(result.getToken().getOwnerStrategyName()).toEqual(successToken.getOwnerStrategyName()); - expect(result.getRedirect()).toEqual('/'); - - done(); - }); + strategy.authenticate(loginData).subscribe((result: NbAuthResult) => { + expect(result).toBeTruthy(); + expect(result.isSuccess()).toBe(true); + expect(result.isFailure()).toBe(false); + expect(result.getMessages()).toEqual(successResponse.data.messages); + expect(result.getErrors()).toEqual([]); // no error message, response is success + expect(result.getToken().getValue()).toEqual(successToken.getValue()); + expect(result.getToken().getOwnerStrategyName()).toEqual(successToken.getOwnerStrategyName()); + expect(result.getRedirect()).toEqual('/'); + + done(); + }); - httpMock.expectOne('/api/auth/login') - .flush(successResponse); + httpMock.expectOne('/api/auth/login').flush(successResponse); }); it('authenticate fail', (done: DoneFn) => { - strategy.authenticate(loginData) - .subscribe((result: NbAuthResult) => { - expect(result).toBeTruthy(); - expect(result.isSuccess()).toBe(false); - expect(result.isFailure()).toBe(true); - expect(result.getMessages()).toEqual([]); - expect(result.getErrors()).toEqual(successResponse.data.errors); // no error message, response is success - expect(result.getToken()).toBe(null); - expect(result.getRedirect()).toEqual(null); - - done(); - }); + strategy.authenticate(loginData).subscribe((result: NbAuthResult) => { + expect(result).toBeTruthy(); + expect(result.isSuccess()).toBe(false); + expect(result.isFailure()).toBe(true); + expect(result.getMessages()).toEqual([]); + expect(result.getErrors()).toEqual(successResponse.data.errors); // no error message, response is success + expect(result.getToken()).toBe(null); + expect(result.getRedirect()).toEqual(null); + + done(); + }); - httpMock.expectOne('/api/auth/login') - .flush(successResponse, { status: 401, statusText: 'Unauthorized' }); + httpMock.expectOne('/api/auth/login').flush(successResponse, { status: 401, statusText: 'Unauthorized' }); }); it('register success', (done: DoneFn) => { - strategy.register(loginData) - .subscribe((result: NbAuthResult) => { - expect(result).toBeTruthy(); - expect(result.isSuccess()).toBe(true); - expect(result.isFailure()).toBe(false); - expect(result.getMessages()).toEqual(successResponse.data.messages); - expect(result.getErrors()).toEqual([]); // no error message, response is success - expect(result.getToken().getValue()).toEqual(successToken.getValue()); - expect(result.getToken().getOwnerStrategyName()).toEqual(successToken.getOwnerStrategyName()); - expect(result.getRedirect()).toEqual('/'); - - done(); - }); + strategy.register(loginData).subscribe((result: NbAuthResult) => { + expect(result).toBeTruthy(); + expect(result.isSuccess()).toBe(true); + expect(result.isFailure()).toBe(false); + expect(result.getMessages()).toEqual(successResponse.data.messages); + expect(result.getErrors()).toEqual([]); // no error message, response is success + expect(result.getToken().getValue()).toEqual(successToken.getValue()); + expect(result.getToken().getOwnerStrategyName()).toEqual(successToken.getOwnerStrategyName()); + expect(result.getRedirect()).toEqual('/'); + + done(); + }); httpMock.expectOne('/api/auth/register').flush(successResponse); }); it('register fail', (done: DoneFn) => { - strategy.register(loginData) - .subscribe((result: NbAuthResult) => { - expect(result).toBeTruthy(); - expect(result.isSuccess()).toBe(false); - expect(result.isFailure()).toBe(true); - expect(result.getMessages()).toEqual([]); - expect(result.getErrors()).toEqual(successResponse.data.errors); // no error message, response is success - expect(result.getToken()).toBe(null); - expect(result.getRedirect()).toEqual(null); - - done(); - }); + strategy.register(loginData).subscribe((result: NbAuthResult) => { + expect(result).toBeTruthy(); + expect(result.isSuccess()).toBe(false); + expect(result.isFailure()).toBe(true); + expect(result.getMessages()).toEqual([]); + expect(result.getErrors()).toEqual(successResponse.data.errors); // no error message, response is success + expect(result.getToken()).toBe(null); + expect(result.getRedirect()).toEqual(null); + + done(); + }); - httpMock.expectOne('/api/auth/register') - .flush(successResponse, { status: 401, statusText: 'Unauthorized' }); + httpMock.expectOne('/api/auth/register').flush(successResponse, { status: 401, statusText: 'Unauthorized' }); }); it('requestPassword success', (done: DoneFn) => { - strategy.requestPassword(loginData) - .subscribe((result: NbAuthResult) => { - expect(result).toBeTruthy(); - expect(result.isSuccess()).toBe(true); - expect(result.isFailure()).toBe(false); - expect(result.getMessages()).toEqual(successResponse.data.messages); - expect(result.getErrors()).toEqual([]); // no error message, response is success - expect(result.getToken()).toBe(null); - expect(result.getRedirect()).toEqual('/'); - - done(); - }); + strategy.requestPassword(loginData).subscribe((result: NbAuthResult) => { + expect(result).toBeTruthy(); + expect(result.isSuccess()).toBe(true); + expect(result.isFailure()).toBe(false); + expect(result.getMessages()).toEqual(successResponse.data.messages); + expect(result.getErrors()).toEqual([]); // no error message, response is success + expect(result.getToken()).toBe(null); + expect(result.getRedirect()).toEqual('/'); + + done(); + }); httpMock.expectOne('/api/auth/request-pass').flush(successResponse); }); it('requestPassword fail', (done: DoneFn) => { - strategy.requestPassword(loginData) - .subscribe((result: NbAuthResult) => { - expect(result).toBeTruthy(); - expect(result.isSuccess()).toBe(false); - expect(result.isFailure()).toBe(true); - expect(result.getMessages()).toEqual([]); - expect(result.getErrors()).toEqual(successResponse.data.errors); // no error message, response is success - expect(result.getToken()).toBe(null); - expect(result.getRedirect()).toEqual(null); - - done(); - }); + strategy.requestPassword(loginData).subscribe((result: NbAuthResult) => { + expect(result).toBeTruthy(); + expect(result.isSuccess()).toBe(false); + expect(result.isFailure()).toBe(true); + expect(result.getMessages()).toEqual([]); + expect(result.getErrors()).toEqual(successResponse.data.errors); // no error message, response is success + expect(result.getToken()).toBe(null); + expect(result.getRedirect()).toEqual(null); + + done(); + }); - httpMock.expectOne('/api/auth/request-pass') - .flush(successResponse, { status: 401, statusText: 'Unauthorized' }); + httpMock.expectOne('/api/auth/request-pass').flush(successResponse, { status: 401, statusText: 'Unauthorized' }); }); it('resetPassword success', (done: DoneFn) => { - strategy.resetPassword(loginData) - .subscribe((result: NbAuthResult) => { - expect(result).toBeTruthy(); - expect(result.isSuccess()).toBe(true); - expect(result.isFailure()).toBe(false); - expect(result.getMessages()).toEqual(successResponse.data.messages); - expect(result.getErrors()).toEqual([]); // no error message, response is success - expect(result.getToken()).toBe(null); - expect(result.getRedirect()).toEqual('/'); - - done(); - }); + strategy.resetPassword(loginData).subscribe((result: NbAuthResult) => { + expect(result).toBeTruthy(); + expect(result.isSuccess()).toBe(true); + expect(result.isFailure()).toBe(false); + expect(result.getMessages()).toEqual(successResponse.data.messages); + expect(result.getErrors()).toEqual([]); // no error message, response is success + expect(result.getToken()).toBe(null); + expect(result.getRedirect()).toEqual('/'); + + done(); + }); httpMock.expectOne('/api/auth/reset-pass').flush(successResponse); }); it('resetPassword fail', (done: DoneFn) => { - strategy.resetPassword(loginData) - .subscribe((result: NbAuthResult) => { - expect(result).toBeTruthy(); - expect(result.isSuccess()).toBe(false); - expect(result.isFailure()).toBe(true); - expect(result.getMessages()).toEqual([]); - expect(result.getErrors()).toEqual(successResponse.data.errors); // no error message, response is success - expect(result.getToken()).toBe(null); - expect(result.getRedirect()).toEqual(null); - - done(); - }); - - httpMock.expectOne('/api/auth/reset-pass') - .flush(successResponse, { status: 401, statusText: 'Unauthorized' }); + strategy.resetPassword(loginData).subscribe((result: NbAuthResult) => { + expect(result).toBeTruthy(); + expect(result.isSuccess()).toBe(false); + expect(result.isFailure()).toBe(true); + expect(result.getMessages()).toEqual([]); + expect(result.getErrors()).toEqual(successResponse.data.errors); // no error message, response is success + expect(result.getToken()).toBe(null); + expect(result.getRedirect()).toEqual(null); + + done(); + }); + + httpMock.expectOne('/api/auth/reset-pass').flush(successResponse, { status: 401, statusText: 'Unauthorized' }); }); it('logout success', (done: DoneFn) => { - strategy.logout() - .subscribe((result: NbAuthResult) => { - expect(result).toBeTruthy(); - expect(result.isSuccess()).toBe(true); - expect(result.isFailure()).toBe(false); - expect(result.getMessages()).toEqual(successResponse.data.messages); - expect(result.getErrors()).toEqual([]); // no error message, response is success - expect(result.getToken()).toBe(null); - expect(result.getRedirect()).toEqual('/'); - - done(); - }); + strategy.logout().subscribe((result: NbAuthResult) => { + expect(result).toBeTruthy(); + expect(result.isSuccess()).toBe(true); + expect(result.isFailure()).toBe(false); + expect(result.getMessages()).toEqual(successResponse.data.messages); + expect(result.getErrors()).toEqual([]); // no error message, response is success + expect(result.getToken()).toBe(null); + expect(result.getRedirect()).toEqual('/'); + + done(); + }); httpMock.expectOne('/api/auth/logout').flush(successResponse); }); it('logout fail', (done: DoneFn) => { - strategy.logout() - .subscribe((result: NbAuthResult) => { - expect(result).toBeTruthy(); - expect(result.isSuccess()).toBe(false); - expect(result.isFailure()).toBe(true); - expect(result.getMessages()).toEqual([]); - expect(result.getErrors()).toEqual(successResponse.data.errors); // no error message, response is success - expect(result.getToken()).toBe(null); - expect(result.getRedirect()).toEqual(null); - - done(); - }); + strategy.logout().subscribe((result: NbAuthResult) => { + expect(result).toBeTruthy(); + expect(result.isSuccess()).toBe(false); + expect(result.isFailure()).toBe(true); + expect(result.getMessages()).toEqual([]); + expect(result.getErrors()).toEqual(successResponse.data.errors); // no error message, response is success + expect(result.getToken()).toBe(null); + expect(result.getRedirect()).toEqual(null); + + done(); + }); - httpMock.expectOne('/api/auth/logout') - .flush(successResponse, { status: 401, statusText: 'Unauthorized' }); + httpMock.expectOne('/api/auth/logout').flush(successResponse, { status: 401, statusText: 'Unauthorized' }); }); it('refreshToken success', (done: DoneFn) => { - strategy.refreshToken() - .subscribe((result: NbAuthResult) => { - expect(result).toBeTruthy(); - expect(result.isSuccess()).toBe(true); - expect(result.isFailure()).toBe(false); - expect(result.getToken().getValue()).toEqual(successToken.getValue()); - expect(result.getToken().getOwnerStrategyName()).toEqual(successToken.getOwnerStrategyName()); - expect(result.getMessages()).toEqual(successResponse.data.messages); - expect(result.getErrors()).toEqual([]); // no error message, response is success - expect(result.getRedirect()).toEqual(null); - - done(); - }); + strategy.refreshToken().subscribe((result: NbAuthResult) => { + expect(result).toBeTruthy(); + expect(result.isSuccess()).toBe(true); + expect(result.isFailure()).toBe(false); + expect(result.getToken().getValue()).toEqual(successToken.getValue()); + expect(result.getToken().getOwnerStrategyName()).toEqual(successToken.getOwnerStrategyName()); + expect(result.getMessages()).toEqual(successResponse.data.messages); + expect(result.getErrors()).toEqual([]); // no error message, response is success + expect(result.getRedirect()).toEqual(null); + + done(); + }); httpMock.expectOne('/api/auth/refresh-token').flush(successResponse); }); it('refreshToken fail', (done: DoneFn) => { - strategy.refreshToken() - .subscribe((result: NbAuthResult) => { - expect(result).toBeTruthy(); - expect(result.isSuccess()).toBe(false); - expect(result.isFailure()).toBe(true); - expect(result.getToken()).toBe(null); - expect(result.getMessages()).toEqual([]); - expect(result.getErrors()).toEqual(successResponse.data.errors); // no error message, response is success - expect(result.getRedirect()).toEqual(null); - - done(); - }); + strategy.refreshToken().subscribe((result: NbAuthResult) => { + expect(result).toBeTruthy(); + expect(result.isSuccess()).toBe(false); + expect(result.isFailure()).toBe(true); + expect(result.getToken()).toBe(null); + expect(result.getMessages()).toEqual([]); + expect(result.getErrors()).toEqual(successResponse.data.errors); // no error message, response is success + expect(result.getRedirect()).toEqual(null); + + done(); + }); - httpMock.expectOne('/api/auth/refresh-token') - .flush(successResponse, { status: 401, statusText: 'Unauthorized' }); + httpMock.expectOne('/api/auth/refresh-token').flush(successResponse, { status: 401, statusText: 'Unauthorized' }); }); - }); describe('always fail', () => { - beforeEach(() => { strategy.setOptions({ name: ownerStrategyName, @@ -313,93 +286,79 @@ describe('password-auth-strategy', () => { }); it('authenticate fail', (done: DoneFn) => { - strategy.authenticate(loginData) - .subscribe((result: NbAuthResult) => { - expect(result).toBeTruthy(); - expect(result.isFailure()).toBe(true); - expect(result.isSuccess()).toBe(false); + strategy.authenticate(loginData).subscribe((result: NbAuthResult) => { + expect(result).toBeTruthy(); + expect(result.isFailure()).toBe(true); + expect(result.isSuccess()).toBe(false); - done(); - }); + done(); + }); - httpMock.expectOne('/api/auth/login') - .flush(successResponse); + httpMock.expectOne('/api/auth/login').flush(successResponse); }); it('register fail', (done: DoneFn) => { - strategy.register(loginData) - .subscribe((result: NbAuthResult) => { - expect(result).toBeTruthy(); - expect(result.isFailure()).toBe(true); - expect(result.isSuccess()).toBe(false); + strategy.register(loginData).subscribe((result: NbAuthResult) => { + expect(result).toBeTruthy(); + expect(result.isFailure()).toBe(true); + expect(result.isSuccess()).toBe(false); - done(); - }); + done(); + }); - httpMock.expectOne('/api/auth/register') - .flush(successResponse); + httpMock.expectOne('/api/auth/register').flush(successResponse); }); it('requestPassword fail', (done: DoneFn) => { - strategy.requestPassword(loginData) - .subscribe((result: NbAuthResult) => { - expect(result).toBeTruthy(); - expect(result.isFailure()).toBe(true); - expect(result.isSuccess()).toBe(false); + strategy.requestPassword(loginData).subscribe((result: NbAuthResult) => { + expect(result).toBeTruthy(); + expect(result.isFailure()).toBe(true); + expect(result.isSuccess()).toBe(false); - done(); - }); + done(); + }); - httpMock.expectOne('/api/auth/request-pass') - .flush(successResponse); + httpMock.expectOne('/api/auth/request-pass').flush(successResponse); }); it('resetPassword fail', (done: DoneFn) => { - strategy.resetPassword(loginData) - .subscribe((result: NbAuthResult) => { - expect(result).toBeTruthy(); - expect(result.isFailure()).toBe(true); - expect(result.isSuccess()).toBe(false); + strategy.resetPassword(loginData).subscribe((result: NbAuthResult) => { + expect(result).toBeTruthy(); + expect(result.isFailure()).toBe(true); + expect(result.isSuccess()).toBe(false); - done(); - }); + done(); + }); - httpMock.expectOne('/api/auth/reset-pass') - .flush(successResponse); + httpMock.expectOne('/api/auth/reset-pass').flush(successResponse); }); it('logout fail', (done: DoneFn) => { - strategy.logout() - .subscribe((result: NbAuthResult) => { - expect(result).toBeTruthy(); - expect(result.isFailure()).toBe(true); - expect(result.isSuccess()).toBe(false); + strategy.logout().subscribe((result: NbAuthResult) => { + expect(result).toBeTruthy(); + expect(result.isFailure()).toBe(true); + expect(result.isSuccess()).toBe(false); - done(); - }); + done(); + }); - httpMock.expectOne('/api/auth/logout') - .flush(successResponse); + httpMock.expectOne('/api/auth/logout').flush(successResponse); }); it('refreshToken fail', (done: DoneFn) => { - strategy.refreshToken() - .subscribe((result: NbAuthResult) => { - expect(result).toBeTruthy(); - expect(result.isFailure()).toBe(true); - expect(result.isSuccess()).toBe(false); + strategy.refreshToken().subscribe((result: NbAuthResult) => { + expect(result).toBeTruthy(); + expect(result.isFailure()).toBe(true); + expect(result.isSuccess()).toBe(false); - done(); - }); + done(); + }); - httpMock.expectOne('/api/auth/refresh-token') - .flush(successResponse); + httpMock.expectOne('/api/auth/refresh-token').flush(successResponse); }); - }); describe('custom endpoint', () => { - beforeEach(() => { strategy.setOptions({ name: ownerStrategyName, @@ -425,93 +384,79 @@ describe('password-auth-strategy', () => { }); it('authenticate', (done: DoneFn) => { - strategy.authenticate(loginData) - .subscribe((result: NbAuthResult) => { - expect(result).toBeTruthy(); - expect(result.isFailure()).toBe(false); - expect(result.isSuccess()).toBe(true); + strategy.authenticate(loginData).subscribe((result: NbAuthResult) => { + expect(result).toBeTruthy(); + expect(result.isFailure()).toBe(false); + expect(result.isSuccess()).toBe(true); - done(); - }); + done(); + }); - httpMock.expectOne('/api/auth/new') - .flush(successResponse); + httpMock.expectOne('/api/auth/new').flush(successResponse); }); it('register', (done: DoneFn) => { - strategy.register(loginData) - .subscribe((result: NbAuthResult) => { - expect(result).toBeTruthy(); - expect(result.isFailure()).toBe(false); - expect(result.isSuccess()).toBe(true); + strategy.register(loginData).subscribe((result: NbAuthResult) => { + expect(result).toBeTruthy(); + expect(result.isFailure()).toBe(false); + expect(result.isSuccess()).toBe(true); - done(); - }); + done(); + }); - httpMock.expectOne('/api/auth/new') - .flush(successResponse); + httpMock.expectOne('/api/auth/new').flush(successResponse); }); it('requestPassword', (done: DoneFn) => { - strategy.requestPassword(loginData) - .subscribe((result: NbAuthResult) => { - expect(result).toBeTruthy(); - expect(result.isFailure()).toBe(false); - expect(result.isSuccess()).toBe(true); + strategy.requestPassword(loginData).subscribe((result: NbAuthResult) => { + expect(result).toBeTruthy(); + expect(result.isFailure()).toBe(false); + expect(result.isSuccess()).toBe(true); - done(); - }); + done(); + }); - httpMock.expectOne('/api/auth/new') - .flush(successResponse); + httpMock.expectOne('/api/auth/new').flush(successResponse); }); it('resetPassword', (done: DoneFn) => { - strategy.resetPassword(loginData) - .subscribe((result: NbAuthResult) => { - expect(result).toBeTruthy(); - expect(result.isFailure()).toBe(false); - expect(result.isSuccess()).toBe(true); + strategy.resetPassword(loginData).subscribe((result: NbAuthResult) => { + expect(result).toBeTruthy(); + expect(result.isFailure()).toBe(false); + expect(result.isSuccess()).toBe(true); - done(); - }); + done(); + }); - httpMock.expectOne('/api/auth/new') - .flush(successResponse); + httpMock.expectOne('/api/auth/new').flush(successResponse); }); it('logout', (done: DoneFn) => { - strategy.logout() - .subscribe((result: NbAuthResult) => { - expect(result).toBeTruthy(); - expect(result.isFailure()).toBe(false); - expect(result.isSuccess()).toBe(true); + strategy.logout().subscribe((result: NbAuthResult) => { + expect(result).toBeTruthy(); + expect(result.isFailure()).toBe(false); + expect(result.isSuccess()).toBe(true); - done(); - }); + done(); + }); - httpMock.expectOne('/api/auth/new') - .flush(successResponse); + httpMock.expectOne('/api/auth/new').flush(successResponse); }); it('refreshToken', (done: DoneFn) => { - strategy.refreshToken() - .subscribe((result: NbAuthResult) => { - expect(result).toBeTruthy(); - expect(result.isFailure()).toBe(false); - expect(result.isSuccess()).toBe(true); + strategy.refreshToken().subscribe((result: NbAuthResult) => { + expect(result).toBeTruthy(); + expect(result.isFailure()).toBe(false); + expect(result.isSuccess()).toBe(true); - done(); - }); + done(); + }); - httpMock.expectOne('/api/auth/new') - .flush(successResponse); + httpMock.expectOne('/api/auth/new').flush(successResponse); }); - }); describe('custom base endpoint', () => { - beforeEach(() => { strategy.setOptions({ name: ownerStrategyName, @@ -520,77 +465,66 @@ describe('password-auth-strategy', () => { }); it('authenticate', (done: DoneFn) => { - strategy.authenticate(loginData) - .subscribe((result: NbAuthResult) => { - expect(result).toBeTruthy(); - expect(result.isFailure()).toBe(false); - expect(result.isSuccess()).toBe(true); + strategy.authenticate(loginData).subscribe((result: NbAuthResult) => { + expect(result).toBeTruthy(); + expect(result.isFailure()).toBe(false); + expect(result.isSuccess()).toBe(true); - done(); - }); + done(); + }); - httpMock.expectOne('/api/auth/custom/login') - .flush(successResponse); + httpMock.expectOne('/api/auth/custom/login').flush(successResponse); }); it('register', (done: DoneFn) => { - strategy.register(loginData) - .subscribe((result: NbAuthResult) => { - expect(result).toBeTruthy(); - expect(result.isFailure()).toBe(false); - expect(result.isSuccess()).toBe(true); + strategy.register(loginData).subscribe((result: NbAuthResult) => { + expect(result).toBeTruthy(); + expect(result.isFailure()).toBe(false); + expect(result.isSuccess()).toBe(true); - done(); - }); + done(); + }); - httpMock.expectOne('/api/auth/custom/register') - .flush(successResponse); + httpMock.expectOne('/api/auth/custom/register').flush(successResponse); }); it('requestPassword', (done: DoneFn) => { - strategy.requestPassword(loginData) - .subscribe((result: NbAuthResult) => { - expect(result).toBeTruthy(); - expect(result.isFailure()).toBe(false); - expect(result.isSuccess()).toBe(true); + strategy.requestPassword(loginData).subscribe((result: NbAuthResult) => { + expect(result).toBeTruthy(); + expect(result.isFailure()).toBe(false); + expect(result.isSuccess()).toBe(true); - done(); - }); + done(); + }); - httpMock.expectOne('/api/auth/custom/request-pass') - .flush(successResponse); + httpMock.expectOne('/api/auth/custom/request-pass').flush(successResponse); }); it('resetPassword', (done: DoneFn) => { - strategy.resetPassword(loginData) - .subscribe((result: NbAuthResult) => { - expect(result).toBeTruthy(); - expect(result.isFailure()).toBe(false); - expect(result.isSuccess()).toBe(true); + strategy.resetPassword(loginData).subscribe((result: NbAuthResult) => { + expect(result).toBeTruthy(); + expect(result.isFailure()).toBe(false); + expect(result.isSuccess()).toBe(true); - done(); - }); + done(); + }); - httpMock.expectOne('/api/auth/custom/reset-pass') - .flush(successResponse); + httpMock.expectOne('/api/auth/custom/reset-pass').flush(successResponse); }); it('logout', (done: DoneFn) => { - strategy.logout() - .subscribe((result: NbAuthResult) => { - expect(result).toBeTruthy(); - expect(result.isFailure()).toBe(false); - expect(result.isSuccess()).toBe(true); + strategy.logout().subscribe((result: NbAuthResult) => { + expect(result).toBeTruthy(); + expect(result.isFailure()).toBe(false); + expect(result.isSuccess()).toBe(true); - done(); - }); + done(); + }); - httpMock.expectOne('/api/auth/custom/logout') - .flush(successResponse); + httpMock.expectOne('/api/auth/custom/logout').flush(successResponse); }); it('logout with no endpoint', (done: DoneFn) => { - strategy.setOptions({ name: ownerStrategyName, baseEndpoint: '/api/auth/custom/', @@ -599,36 +533,31 @@ describe('password-auth-strategy', () => { }, }); - strategy.logout() - .subscribe((result: NbAuthResult) => { - expect(result).toBeTruthy(); - expect(result.isFailure()).toBe(false); - expect(result.isSuccess()).toBe(true); + strategy.logout().subscribe((result: NbAuthResult) => { + expect(result).toBeTruthy(); + expect(result.isFailure()).toBe(false); + expect(result.isSuccess()).toBe(true); - done(); - }); + done(); + }); httpMock.expectNone('/api/auth/custom/'); }); it('refreshToken', (done: DoneFn) => { - strategy.refreshToken() - .subscribe((result: NbAuthResult) => { - expect(result).toBeTruthy(); - expect(result.isFailure()).toBe(false); - expect(result.isSuccess()).toBe(true); + strategy.refreshToken().subscribe((result: NbAuthResult) => { + expect(result).toBeTruthy(); + expect(result.isFailure()).toBe(false); + expect(result.isSuccess()).toBe(true); - done(); - }); + done(); + }); - httpMock.expectOne('/api/auth/custom/refresh-token') - .flush(successResponse); + httpMock.expectOne('/api/auth/custom/refresh-token').flush(successResponse); }); - }); describe('custom method', () => { - beforeEach(() => { strategy.setOptions({ name: ownerStrategyName, @@ -654,100 +583,85 @@ describe('password-auth-strategy', () => { }); it('authenticate', (done: DoneFn) => { - strategy.authenticate(loginData) - .subscribe((result: NbAuthResult) => { - expect(result).toBeTruthy(); - expect(result.isFailure()).toBe(false); - expect(result.isSuccess()).toBe(true); + strategy.authenticate(loginData).subscribe((result: NbAuthResult) => { + expect(result).toBeTruthy(); + expect(result.isFailure()).toBe(false); + expect(result.isSuccess()).toBe(true); - done(); - }); + done(); + }); - httpMock.expectOne({ method: 'get' }) - .flush(successResponse); + httpMock.expectOne({ method: 'get' }).flush(successResponse); }); it('register', (done: DoneFn) => { - strategy.register(loginData) - .subscribe((result: NbAuthResult) => { - expect(result).toBeTruthy(); - expect(result.isFailure()).toBe(false); - expect(result.isSuccess()).toBe(true); + strategy.register(loginData).subscribe((result: NbAuthResult) => { + expect(result).toBeTruthy(); + expect(result.isFailure()).toBe(false); + expect(result.isSuccess()).toBe(true); - done(); - }); + done(); + }); - httpMock.expectOne({ method: 'get' }) - .flush(successResponse); + httpMock.expectOne({ method: 'get' }).flush(successResponse); }); it('requestPassword', (done: DoneFn) => { - strategy.requestPassword(loginData) - .subscribe((result: NbAuthResult) => { - expect(result).toBeTruthy(); - expect(result.isFailure()).toBe(false); - expect(result.isSuccess()).toBe(true); + strategy.requestPassword(loginData).subscribe((result: NbAuthResult) => { + expect(result).toBeTruthy(); + expect(result.isFailure()).toBe(false); + expect(result.isSuccess()).toBe(true); - done(); - }); + done(); + }); - httpMock.expectOne({ method: 'get' }) - .flush(successResponse); + httpMock.expectOne({ method: 'get' }).flush(successResponse); }); it('resetPassword', (done: DoneFn) => { - strategy.resetPassword(loginData) - .subscribe((result: NbAuthResult) => { - expect(result).toBeTruthy(); - expect(result.isFailure()).toBe(false); - expect(result.isSuccess()).toBe(true); + strategy.resetPassword(loginData).subscribe((result: NbAuthResult) => { + expect(result).toBeTruthy(); + expect(result.isFailure()).toBe(false); + expect(result.isSuccess()).toBe(true); - done(); - }); + done(); + }); - httpMock.expectOne({ method: 'get' }) - .flush(successResponse); + httpMock.expectOne({ method: 'get' }).flush(successResponse); }); it('logout', (done: DoneFn) => { - strategy.logout() - .subscribe((result: NbAuthResult) => { - expect(result).toBeTruthy(); - expect(result.isFailure()).toBe(false); - expect(result.isSuccess()).toBe(true); + strategy.logout().subscribe((result: NbAuthResult) => { + expect(result).toBeTruthy(); + expect(result.isFailure()).toBe(false); + expect(result.isSuccess()).toBe(true); - done(); - }); + done(); + }); - httpMock.expectOne({ method: 'get' }) - .flush(successResponse); + httpMock.expectOne({ method: 'get' }).flush(successResponse); }); it('refreshToken', (done: DoneFn) => { - strategy.refreshToken() - .subscribe((result: NbAuthResult) => { - expect(result).toBeTruthy(); - expect(result.isFailure()).toBe(false); - expect(result.isSuccess()).toBe(true); + strategy.refreshToken().subscribe((result: NbAuthResult) => { + expect(result).toBeTruthy(); + expect(result.isFailure()).toBe(false); + expect(result.isSuccess()).toBe(true); - done(); - }); + done(); + }); - httpMock.expectOne({ method: 'get' }) - .flush(successResponse); + httpMock.expectOne({ method: 'get' }).flush(successResponse); }); - }); describe('custom redirect', () => { - const redirect = { success: '/success', failure: '/error', }; beforeEach(() => { - strategy.setOptions({ name: ownerStrategyName, login: { @@ -772,172 +686,145 @@ describe('password-auth-strategy', () => { }); it('authenticate success', (done: DoneFn) => { - strategy.authenticate(loginData) - .subscribe((result: NbAuthResult) => { - expect(result).toBeTruthy(); - expect(result.getRedirect()).toBe(redirect.success); + strategy.authenticate(loginData).subscribe((result: NbAuthResult) => { + expect(result).toBeTruthy(); + expect(result.getRedirect()).toBe(redirect.success); - done(); - }); + done(); + }); - httpMock.expectOne('/api/auth/login') - .flush(successResponse); + httpMock.expectOne('/api/auth/login').flush(successResponse); }); it('authenticate fail', (done: DoneFn) => { - strategy.authenticate(loginData) - .subscribe((result: NbAuthResult) => { - expect(result).toBeTruthy(); - expect(result.getRedirect()).toBe(redirect.failure); + strategy.authenticate(loginData).subscribe((result: NbAuthResult) => { + expect(result).toBeTruthy(); + expect(result.getRedirect()).toBe(redirect.failure); - done(); - }); + done(); + }); - httpMock.expectOne('/api/auth/login') - .flush(successResponse, { status: 401, statusText: 'Unauthorized' }); + httpMock.expectOne('/api/auth/login').flush(successResponse, { status: 401, statusText: 'Unauthorized' }); }); it('register success', (done: DoneFn) => { - strategy.register(loginData) - .subscribe((result: NbAuthResult) => { - expect(result).toBeTruthy(); - expect(result.getRedirect()).toBe(redirect.success); + strategy.register(loginData).subscribe((result: NbAuthResult) => { + expect(result).toBeTruthy(); + expect(result.getRedirect()).toBe(redirect.success); - done(); - }); + done(); + }); - httpMock.expectOne('/api/auth/register') - .flush(successResponse); + httpMock.expectOne('/api/auth/register').flush(successResponse); }); it('register fail', (done: DoneFn) => { - strategy.register(loginData) - .subscribe((result: NbAuthResult) => { - expect(result).toBeTruthy(); - expect(result.getRedirect()).toBe(redirect.failure); + strategy.register(loginData).subscribe((result: NbAuthResult) => { + expect(result).toBeTruthy(); + expect(result.getRedirect()).toBe(redirect.failure); - done(); - }); + done(); + }); - httpMock.expectOne('/api/auth/register') - .flush(successResponse, { status: 401, statusText: 'Unauthorized' }); + httpMock.expectOne('/api/auth/register').flush(successResponse, { status: 401, statusText: 'Unauthorized' }); }); it('requestPassword success', (done: DoneFn) => { - strategy.requestPassword(loginData) - .subscribe((result: NbAuthResult) => { - expect(result).toBeTruthy(); - expect(result.getRedirect()).toBe(redirect.success); + strategy.requestPassword(loginData).subscribe((result: NbAuthResult) => { + expect(result).toBeTruthy(); + expect(result.getRedirect()).toBe(redirect.success); - done(); - }); + done(); + }); - httpMock.expectOne('/api/auth/request-pass') - .flush(successResponse); + httpMock.expectOne('/api/auth/request-pass').flush(successResponse); }); it('requestPassword fail', (done: DoneFn) => { - strategy.requestPassword(loginData) - .subscribe((result: NbAuthResult) => { - expect(result).toBeTruthy(); - expect(result.getRedirect()).toBe(redirect.failure); + strategy.requestPassword(loginData).subscribe((result: NbAuthResult) => { + expect(result).toBeTruthy(); + expect(result.getRedirect()).toBe(redirect.failure); - done(); - }); + done(); + }); - httpMock.expectOne('/api/auth/request-pass') - .flush(successResponse, { status: 401, statusText: 'Unauthorized' }); + httpMock.expectOne('/api/auth/request-pass').flush(successResponse, { status: 401, statusText: 'Unauthorized' }); }); it('resetPassword success', (done: DoneFn) => { - strategy.resetPassword(loginData) - .subscribe((result: NbAuthResult) => { - expect(result).toBeTruthy(); - expect(result.getRedirect()).toBe(redirect.success); + strategy.resetPassword(loginData).subscribe((result: NbAuthResult) => { + expect(result).toBeTruthy(); + expect(result.getRedirect()).toBe(redirect.success); - done(); - }); + done(); + }); - httpMock.expectOne('/api/auth/reset-pass') - .flush(successResponse); + httpMock.expectOne('/api/auth/reset-pass').flush(successResponse); }); it('resetPassword fail', (done: DoneFn) => { - strategy.resetPassword(loginData) - .subscribe((result: NbAuthResult) => { - expect(result).toBeTruthy(); - expect(result.getRedirect()).toBe(redirect.failure); + strategy.resetPassword(loginData).subscribe((result: NbAuthResult) => { + expect(result).toBeTruthy(); + expect(result.getRedirect()).toBe(redirect.failure); - done(); - }); + done(); + }); - httpMock.expectOne('/api/auth/reset-pass') - .flush(successResponse, { status: 401, statusText: 'Unauthorized' }); + httpMock.expectOne('/api/auth/reset-pass').flush(successResponse, { status: 401, statusText: 'Unauthorized' }); }); it('logout success', (done: DoneFn) => { - strategy.logout() - .subscribe((result: NbAuthResult) => { - expect(result).toBeTruthy(); - expect(result.getRedirect()).toBe(redirect.success); + strategy.logout().subscribe((result: NbAuthResult) => { + expect(result).toBeTruthy(); + expect(result.getRedirect()).toBe(redirect.success); - done(); - }); + done(); + }); - httpMock.expectOne('/api/auth/logout') - .flush(successResponse); + httpMock.expectOne('/api/auth/logout').flush(successResponse); }); it('logout fail', (done: DoneFn) => { - strategy.logout() - .subscribe((result: NbAuthResult) => { - expect(result).toBeTruthy(); - expect(result.getRedirect()).toBe(redirect.failure); + strategy.logout().subscribe((result: NbAuthResult) => { + expect(result).toBeTruthy(); + expect(result.getRedirect()).toBe(redirect.failure); - done(); - }); + done(); + }); - httpMock.expectOne('/api/auth/logout') - .flush(successResponse, { status: 401, statusText: 'Unauthorized' }); + httpMock.expectOne('/api/auth/logout').flush(successResponse, { status: 401, statusText: 'Unauthorized' }); }); it('refreshToken success', (done: DoneFn) => { - strategy.refreshToken() - .subscribe((result: NbAuthResult) => { - expect(result).toBeTruthy(); - expect(result.getRedirect()).toBe(redirect.success); + strategy.refreshToken().subscribe((result: NbAuthResult) => { + expect(result).toBeTruthy(); + expect(result.getRedirect()).toBe(redirect.success); - done(); - }); + done(); + }); - httpMock.expectOne('/api/auth/refresh-token') - .flush(successResponse); + httpMock.expectOne('/api/auth/refresh-token').flush(successResponse); }); it('refreshToken fail', (done: DoneFn) => { - strategy.refreshToken() - .subscribe((result: NbAuthResult) => { - expect(result).toBeTruthy(); - expect(result.getRedirect()).toBe(redirect.failure); + strategy.refreshToken().subscribe((result: NbAuthResult) => { + expect(result).toBeTruthy(); + expect(result.getRedirect()).toBe(redirect.failure); - done(); - }); + done(); + }); - httpMock.expectOne('/api/auth/refresh-token') - .flush(successResponse, { status: 401, statusText: 'Unauthorized' }); + httpMock.expectOne('/api/auth/refresh-token').flush(successResponse, { status: 401, statusText: 'Unauthorized' }); }); - }); describe('custom message', () => { - const messages = { defaultErrors: ['this is error message'], defaultMessages: ['this is success message'], }; beforeEach(() => { - strategy.setOptions({ name: ownerStrategyName, login: { @@ -962,165 +849,141 @@ describe('password-auth-strategy', () => { }); it('authenticate success', (done: DoneFn) => { - strategy.authenticate(loginData) - .subscribe((result: NbAuthResult) => { - expect(result).toBeTruthy(); - expect(result.getMessages()).toEqual(messages.defaultMessages); + strategy.authenticate(loginData).subscribe((result: NbAuthResult) => { + expect(result).toBeTruthy(); + expect(result.getMessages()).toEqual(messages.defaultMessages); - done(); - }); + done(); + }); - httpMock.expectOne('/api/auth/login') - .flush(noMessageResponse); + httpMock.expectOne('/api/auth/login').flush(noMessageResponse); }); it('authenticate fail', (done: DoneFn) => { - strategy.authenticate(loginData) - .subscribe((result: NbAuthResult) => { - expect(result).toBeTruthy(); - expect(result.getErrors()).toEqual(messages.defaultErrors); + strategy.authenticate(loginData).subscribe((result: NbAuthResult) => { + expect(result).toBeTruthy(); + expect(result.getErrors()).toEqual(messages.defaultErrors); - done(); - }); + done(); + }); - httpMock.expectOne('/api/auth/login') - .flush(noMessageResponse, { status: 401, statusText: 'Unauthorized' }); + httpMock.expectOne('/api/auth/login').flush(noMessageResponse, { status: 401, statusText: 'Unauthorized' }); }); it('register success', (done: DoneFn) => { - strategy.register(loginData) - .subscribe((result: NbAuthResult) => { - expect(result).toBeTruthy(); - expect(result.getMessages()).toEqual(messages.defaultMessages); + strategy.register(loginData).subscribe((result: NbAuthResult) => { + expect(result).toBeTruthy(); + expect(result.getMessages()).toEqual(messages.defaultMessages); - done(); - }); + done(); + }); - httpMock.expectOne('/api/auth/register') - .flush(noMessageResponse); + httpMock.expectOne('/api/auth/register').flush(noMessageResponse); }); it('register fail', (done: DoneFn) => { - strategy.register(loginData) - .subscribe((result: NbAuthResult) => { - expect(result).toBeTruthy(); - expect(result.getErrors()).toEqual(messages.defaultErrors); + strategy.register(loginData).subscribe((result: NbAuthResult) => { + expect(result).toBeTruthy(); + expect(result.getErrors()).toEqual(messages.defaultErrors); - done(); - }); + done(); + }); - httpMock.expectOne('/api/auth/register') - .flush(noMessageResponse, { status: 401, statusText: 'Unauthorized' }); + httpMock.expectOne('/api/auth/register').flush(noMessageResponse, { status: 401, statusText: 'Unauthorized' }); }); it('requestPassword success', (done: DoneFn) => { - strategy.requestPassword(loginData) - .subscribe((result: NbAuthResult) => { - expect(result).toBeTruthy(); - expect(result.getMessages()).toEqual(messages.defaultMessages); + strategy.requestPassword(loginData).subscribe((result: NbAuthResult) => { + expect(result).toBeTruthy(); + expect(result.getMessages()).toEqual(messages.defaultMessages); - done(); - }); + done(); + }); - httpMock.expectOne('/api/auth/request-pass') - .flush(noMessageResponse); + httpMock.expectOne('/api/auth/request-pass').flush(noMessageResponse); }); it('requestPassword fail', (done: DoneFn) => { - strategy.requestPassword(loginData) - .subscribe((result: NbAuthResult) => { - expect(result).toBeTruthy(); - expect(result.getErrors()).toEqual(messages.defaultErrors); + strategy.requestPassword(loginData).subscribe((result: NbAuthResult) => { + expect(result).toBeTruthy(); + expect(result.getErrors()).toEqual(messages.defaultErrors); - done(); - }); + done(); + }); - httpMock.expectOne('/api/auth/request-pass') - .flush({}, { status: 401, statusText: 'Unauthorized' }); + httpMock.expectOne('/api/auth/request-pass').flush({}, { status: 401, statusText: 'Unauthorized' }); }); it('resetPassword success', (done: DoneFn) => { - strategy.resetPassword(loginData) - .subscribe((result: NbAuthResult) => { - expect(result).toBeTruthy(); - expect(result.getMessages()).toEqual(messages.defaultMessages); + strategy.resetPassword(loginData).subscribe((result: NbAuthResult) => { + expect(result).toBeTruthy(); + expect(result.getMessages()).toEqual(messages.defaultMessages); - done(); - }); + done(); + }); - httpMock.expectOne('/api/auth/reset-pass') - .flush(noMessageResponse); + httpMock.expectOne('/api/auth/reset-pass').flush(noMessageResponse); }); it('resetPassword fail', (done: DoneFn) => { - strategy.resetPassword(loginData) - .subscribe((result: NbAuthResult) => { - expect(result).toBeTruthy(); - expect(result.getErrors()).toEqual(messages.defaultErrors); + strategy.resetPassword(loginData).subscribe((result: NbAuthResult) => { + expect(result).toBeTruthy(); + expect(result.getErrors()).toEqual(messages.defaultErrors); - done(); - }); + done(); + }); - httpMock.expectOne('/api/auth/reset-pass') - .flush(noMessageResponse, { status: 401, statusText: 'Unauthorized' }); + httpMock.expectOne('/api/auth/reset-pass').flush(noMessageResponse, { status: 401, statusText: 'Unauthorized' }); }); it('logout success', (done: DoneFn) => { - strategy.logout() - .subscribe((result: NbAuthResult) => { - expect(result).toBeTruthy(); - expect(result.getMessages()).toEqual(messages.defaultMessages); + strategy.logout().subscribe((result: NbAuthResult) => { + expect(result).toBeTruthy(); + expect(result.getMessages()).toEqual(messages.defaultMessages); - done(); - }); + done(); + }); - httpMock.expectOne('/api/auth/logout') - .flush(noMessageResponse); + httpMock.expectOne('/api/auth/logout').flush(noMessageResponse); }); it('logout fail', (done: DoneFn) => { - strategy.logout() - .subscribe((result: NbAuthResult) => { - expect(result).toBeTruthy(); - expect(result.getErrors()).toEqual(messages.defaultErrors); + strategy.logout().subscribe((result: NbAuthResult) => { + expect(result).toBeTruthy(); + expect(result.getErrors()).toEqual(messages.defaultErrors); - done(); - }); + done(); + }); - httpMock.expectOne('/api/auth/logout') - .flush(noMessageResponse, { status: 401, statusText: 'Unauthorized' }); + httpMock.expectOne('/api/auth/logout').flush(noMessageResponse, { status: 401, statusText: 'Unauthorized' }); }); it('refreshToken success', (done: DoneFn) => { - strategy.refreshToken() - .subscribe((result: NbAuthResult) => { - expect(result).toBeTruthy(); - expect(result.getMessages()).toEqual(messages.defaultMessages); + strategy.refreshToken().subscribe((result: NbAuthResult) => { + expect(result).toBeTruthy(); + expect(result.getMessages()).toEqual(messages.defaultMessages); - done(); - }); + done(); + }); - httpMock.expectOne('/api/auth/refresh-token') - .flush(noMessageResponse); + httpMock.expectOne('/api/auth/refresh-token').flush(noMessageResponse); }); it('refreshToken fail', (done: DoneFn) => { - strategy.refreshToken() - .subscribe((result: NbAuthResult) => { - expect(result).toBeTruthy(); - expect(result.getErrors()).toEqual(messages.defaultErrors); + strategy.refreshToken().subscribe((result: NbAuthResult) => { + expect(result).toBeTruthy(); + expect(result.getErrors()).toEqual(messages.defaultErrors); - done(); - }); + done(); + }); - httpMock.expectOne('/api/auth/refresh-token') + httpMock + .expectOne('/api/auth/refresh-token') .flush(noMessageResponse, { status: 401, statusText: 'Unauthorized' }); }); - }); describe('custom token key', () => { - beforeEach(() => { strategy.setOptions({ name: ownerStrategyName, @@ -1131,112 +994,96 @@ describe('password-auth-strategy', () => { }); it('authenticate', (done: DoneFn) => { - strategy.authenticate(loginData) - .subscribe((result: NbAuthResult) => { - expect(result).toBeTruthy(); - expect(result.isFailure()).toBe(false); - expect(result.isSuccess()).toBe(true); - expect(result.getToken().getValue()).toEqual(successToken.getValue()); - expect(result.getToken().getOwnerStrategyName()).toEqual(successToken.getOwnerStrategyName()); - done(); - }); + strategy.authenticate(loginData).subscribe((result: NbAuthResult) => { + expect(result).toBeTruthy(); + expect(result.isFailure()).toBe(false); + expect(result.isSuccess()).toBe(true); + expect(result.getToken().getValue()).toEqual(successToken.getValue()); + expect(result.getToken().getOwnerStrategyName()).toEqual(successToken.getOwnerStrategyName()); + done(); + }); - httpMock.expectOne('/api/auth/login') - .flush(customResponse); + httpMock.expectOne('/api/auth/login').flush(customResponse); }); it('register', (done: DoneFn) => { - strategy.register(loginData) - .subscribe((result: NbAuthResult) => { - expect(result).toBeTruthy(); - expect(result.isFailure()).toBe(false); - expect(result.isSuccess()).toBe(true); - expect(result.getToken().getValue()).toEqual(successToken.getValue()); - expect(result.getToken().getOwnerStrategyName()).toEqual(successToken.getOwnerStrategyName()); - done(); - }); + strategy.register(loginData).subscribe((result: NbAuthResult) => { + expect(result).toBeTruthy(); + expect(result.isFailure()).toBe(false); + expect(result.isSuccess()).toBe(true); + expect(result.getToken().getValue()).toEqual(successToken.getValue()); + expect(result.getToken().getOwnerStrategyName()).toEqual(successToken.getOwnerStrategyName()); + done(); + }); - httpMock.expectOne('/api/auth/register') - .flush(customResponse); + httpMock.expectOne('/api/auth/register').flush(customResponse); }); it('refreshToken', (done: DoneFn) => { - strategy.refreshToken() - .subscribe((result: NbAuthResult) => { - expect(result).toBeTruthy(); - expect(result.isFailure()).toBe(false); - expect(result.isSuccess()).toBe(true); - expect(result.getToken().getValue()).toEqual(successToken.getValue()); - expect(result.getToken().getOwnerStrategyName()).toEqual(successToken.getOwnerStrategyName()); - done(); - }); + strategy.refreshToken().subscribe((result: NbAuthResult) => { + expect(result).toBeTruthy(); + expect(result.isFailure()).toBe(false); + expect(result.isSuccess()).toBe(true); + expect(result.getToken().getValue()).toEqual(successToken.getValue()); + expect(result.getToken().getOwnerStrategyName()).toEqual(successToken.getOwnerStrategyName()); + done(); + }); - httpMock.expectOne('/api/auth/refresh-token') - .flush(customResponse); + httpMock.expectOne('/api/auth/refresh-token').flush(customResponse); }); - }); describe('custom token extractor', () => { - beforeEach(() => { strategy.setOptions({ name: ownerStrategyName, token: { - getter: (module: string, res: HttpResponse) => res.body['token'], + getter: (module: string, res: HttpResponse<{ token: string }>) => res.body.token, }, }); }); it('authenticate', (done: DoneFn) => { - strategy.authenticate(loginData) - .subscribe((result: NbAuthResult) => { - expect(result).toBeTruthy(); - expect(result.isFailure()).toBe(false); - expect(result.isSuccess()).toBe(true); - expect(result.getToken().getValue()).toEqual(successToken.getValue()); - expect(result.getToken().getOwnerStrategyName()).toEqual(successToken.getOwnerStrategyName()); - done(); - }); + strategy.authenticate(loginData).subscribe((result: NbAuthResult) => { + expect(result).toBeTruthy(); + expect(result.isFailure()).toBe(false); + expect(result.isSuccess()).toBe(true); + expect(result.getToken().getValue()).toEqual(successToken.getValue()); + expect(result.getToken().getOwnerStrategyName()).toEqual(successToken.getOwnerStrategyName()); + done(); + }); - httpMock.expectOne('/api/auth/login') - .flush(customResponse); + httpMock.expectOne('/api/auth/login').flush(customResponse); }); it('register', (done: DoneFn) => { - strategy.register(loginData) - .subscribe((result: NbAuthResult) => { - expect(result).toBeTruthy(); - expect(result.isFailure()).toBe(false); - expect(result.isSuccess()).toBe(true); - expect(result.getToken().getValue()).toEqual(successToken.getValue()); - expect(result.getToken().getOwnerStrategyName()).toEqual(successToken.getOwnerStrategyName()); - done(); - }); + strategy.register(loginData).subscribe((result: NbAuthResult) => { + expect(result).toBeTruthy(); + expect(result.isFailure()).toBe(false); + expect(result.isSuccess()).toBe(true); + expect(result.getToken().getValue()).toEqual(successToken.getValue()); + expect(result.getToken().getOwnerStrategyName()).toEqual(successToken.getOwnerStrategyName()); + done(); + }); - httpMock.expectOne('/api/auth/register') - .flush(customResponse); + httpMock.expectOne('/api/auth/register').flush(customResponse); }); it('refreshToken', (done: DoneFn) => { - strategy.refreshToken() - .subscribe((result: NbAuthResult) => { - expect(result).toBeTruthy(); - expect(result.isFailure()).toBe(false); - expect(result.isSuccess()).toBe(true); - expect(result.getToken().getValue()).toEqual(successToken.getValue()); - expect(result.getToken().getOwnerStrategyName()).toEqual(successToken.getOwnerStrategyName()); - done(); - }); + strategy.refreshToken().subscribe((result: NbAuthResult) => { + expect(result).toBeTruthy(); + expect(result.isFailure()).toBe(false); + expect(result.isSuccess()).toBe(true); + expect(result.getToken().getValue()).toEqual(successToken.getValue()); + expect(result.getToken().getOwnerStrategyName()).toEqual(successToken.getOwnerStrategyName()); + done(); + }); - httpMock.expectOne('/api/auth/refresh-token') - .flush(customResponse); + httpMock.expectOne('/api/auth/refresh-token').flush(customResponse); }); - }); describe('custom message key', () => { - beforeEach(() => { strategy.setOptions({ name: ownerStrategyName, @@ -1253,99 +1100,85 @@ describe('password-auth-strategy', () => { }); it('authenticate success', (done: DoneFn) => { - strategy.authenticate(loginData) - .subscribe((result: NbAuthResult) => { - expect(result).toBeTruthy(); - expect(result.isFailure()).toBe(false); - expect(result.isSuccess()).toBe(true); - expect(result.getMessages()[0]).toBe('Success message'); + strategy.authenticate(loginData).subscribe((result: NbAuthResult) => { + expect(result).toBeTruthy(); + expect(result.isFailure()).toBe(false); + expect(result.isSuccess()).toBe(true); + expect(result.getMessages()[0]).toBe('Success message'); - done(); - }); + done(); + }); - httpMock.expectOne('/api/auth/login') - .flush(customResponse); + httpMock.expectOne('/api/auth/login').flush(customResponse); }); it('authenticate fail', (done: DoneFn) => { - strategy.authenticate(loginData) - .subscribe((result: NbAuthResult) => { - expect(result).toBeTruthy(); - expect(result.isFailure()).toBe(true); - expect(result.isSuccess()).toBe(false); - expect(result.getErrors()[0]).toBe('Error message'); + strategy.authenticate(loginData).subscribe((result: NbAuthResult) => { + expect(result).toBeTruthy(); + expect(result.isFailure()).toBe(true); + expect(result.isSuccess()).toBe(false); + expect(result.getErrors()[0]).toBe('Error message'); - done(); - }); + done(); + }); - httpMock.expectOne('/api/auth/login') - .flush(customResponse, { status: 401, statusText: 'Unauthorized' }); + httpMock.expectOne('/api/auth/login').flush(customResponse, { status: 401, statusText: 'Unauthorized' }); }); it('register success', (done: DoneFn) => { - strategy.register(loginData) - .subscribe((result: NbAuthResult) => { - expect(result).toBeTruthy(); - expect(result.isFailure()).toBe(false); - expect(result.isSuccess()).toBe(true); - expect(result.getMessages()[0]).toBe('Success message'); + strategy.register(loginData).subscribe((result: NbAuthResult) => { + expect(result).toBeTruthy(); + expect(result.isFailure()).toBe(false); + expect(result.isSuccess()).toBe(true); + expect(result.getMessages()[0]).toBe('Success message'); - done(); - }); + done(); + }); - httpMock.expectOne('/api/auth/register') - .flush(customResponse); + httpMock.expectOne('/api/auth/register').flush(customResponse); }); it('register fail', (done: DoneFn) => { - strategy.register(loginData) - .subscribe((result: NbAuthResult) => { - expect(result).toBeTruthy(); - expect(result.isFailure()).toBe(true); - expect(result.isSuccess()).toBe(false); - expect(result.getErrors()[0]).toBe('Error message'); + strategy.register(loginData).subscribe((result: NbAuthResult) => { + expect(result).toBeTruthy(); + expect(result.isFailure()).toBe(true); + expect(result.isSuccess()).toBe(false); + expect(result.getErrors()[0]).toBe('Error message'); - done(); - }); + done(); + }); - httpMock.expectOne('/api/auth/register') - .flush(customResponse, { status: 401, statusText: 'Unauthorized' }); + httpMock.expectOne('/api/auth/register').flush(customResponse, { status: 401, statusText: 'Unauthorized' }); }); it('refreshToken success', (done: DoneFn) => { - strategy.refreshToken() - .subscribe((result: NbAuthResult) => { - expect(result).toBeTruthy(); - expect(result.isFailure()).toBe(false); - expect(result.isSuccess()).toBe(true); - expect(result.getMessages()[0]).toBe('Success message'); + strategy.refreshToken().subscribe((result: NbAuthResult) => { + expect(result).toBeTruthy(); + expect(result.isFailure()).toBe(false); + expect(result.isSuccess()).toBe(true); + expect(result.getMessages()[0]).toBe('Success message'); - done(); - }); + done(); + }); - httpMock.expectOne('/api/auth/refresh-token') - .flush(customResponse); + httpMock.expectOne('/api/auth/refresh-token').flush(customResponse); }); it('refreshToken fail', (done: DoneFn) => { - strategy.refreshToken() - .subscribe((result: NbAuthResult) => { - expect(result).toBeTruthy(); - expect(result.isFailure()).toBe(true); - expect(result.isSuccess()).toBe(false); - expect(result.getErrors()[0]).toBe('Error message'); + strategy.refreshToken().subscribe((result: NbAuthResult) => { + expect(result).toBeTruthy(); + expect(result.isFailure()).toBe(true); + expect(result.isSuccess()).toBe(false); + expect(result.getErrors()[0]).toBe('Error message'); - done(); - }); + done(); + }); - httpMock.expectOne('/api/auth/refresh-token') - .flush(customResponse, { status: 401, statusText: 'Unauthorized' }); + httpMock.expectOne('/api/auth/refresh-token').flush(customResponse, { status: 401, statusText: 'Unauthorized' }); }); - }); describe('custom message extractor', () => { - beforeEach(() => { strategy.setOptions({ name: ownerStrategyName, @@ -1353,108 +1186,94 @@ describe('password-auth-strategy', () => { key: 'token', }, messages: { - getter: (module: string, res: HttpResponse) => res.body['messages'], + getter: (module: string, res: HttpResponse<{ messages: string[] }>) => res.body.messages, }, errors: { - getter: (module: string, res: HttpErrorResponse) => res.error['errors'], + getter: (module: string, res: HttpErrorResponse) => res.error.errors, }, }); }); it('authenticate success', (done: DoneFn) => { - strategy.authenticate(loginData) - .subscribe((result: NbAuthResult) => { - expect(result).toBeTruthy(); - expect(result.isFailure()).toBe(false); - expect(result.isSuccess()).toBe(true); - expect(result.getMessages()[0]).toBe('Success message'); + strategy.authenticate(loginData).subscribe((result: NbAuthResult) => { + expect(result).toBeTruthy(); + expect(result.isFailure()).toBe(false); + expect(result.isSuccess()).toBe(true); + expect(result.getMessages()[0]).toBe('Success message'); - done(); - }); + done(); + }); - httpMock.expectOne('/api/auth/login') - .flush(customResponse); + httpMock.expectOne('/api/auth/login').flush(customResponse); }); it('authenticate fail', (done: DoneFn) => { - strategy.authenticate(loginData) - .subscribe((result: NbAuthResult) => { - expect(result).toBeTruthy(); - expect(result.isFailure()).toBe(true); - expect(result.isSuccess()).toBe(false); - expect(result.getErrors()[0]).toBe('Error message'); + strategy.authenticate(loginData).subscribe((result: NbAuthResult) => { + expect(result).toBeTruthy(); + expect(result.isFailure()).toBe(true); + expect(result.isSuccess()).toBe(false); + expect(result.getErrors()[0]).toBe('Error message'); - done(); - }); + done(); + }); - httpMock.expectOne('/api/auth/login') - .flush(customResponse, { status: 401, statusText: 'Unauthorized' }); + httpMock.expectOne('/api/auth/login').flush(customResponse, { status: 401, statusText: 'Unauthorized' }); }); it('register success', (done: DoneFn) => { - strategy.register(loginData) - .subscribe((result: NbAuthResult) => { - expect(result).toBeTruthy(); - expect(result.isFailure()).toBe(false); - expect(result.isSuccess()).toBe(true); - expect(result.getMessages()[0]).toBe('Success message'); + strategy.register(loginData).subscribe((result: NbAuthResult) => { + expect(result).toBeTruthy(); + expect(result.isFailure()).toBe(false); + expect(result.isSuccess()).toBe(true); + expect(result.getMessages()[0]).toBe('Success message'); - done(); - }); + done(); + }); - httpMock.expectOne('/api/auth/register') - .flush(customResponse); + httpMock.expectOne('/api/auth/register').flush(customResponse); }); it('register fail', (done: DoneFn) => { - strategy.register(loginData) - .subscribe((result: NbAuthResult) => { - expect(result).toBeTruthy(); - expect(result.isFailure()).toBe(true); - expect(result.isSuccess()).toBe(false); - expect(result.getErrors()[0]).toBe('Error message'); + strategy.register(loginData).subscribe((result: NbAuthResult) => { + expect(result).toBeTruthy(); + expect(result.isFailure()).toBe(true); + expect(result.isSuccess()).toBe(false); + expect(result.getErrors()[0]).toBe('Error message'); - done(); - }); + done(); + }); - httpMock.expectOne('/api/auth/register') - .flush(customResponse, { status: 401, statusText: 'Unauthorized' }); + httpMock.expectOne('/api/auth/register').flush(customResponse, { status: 401, statusText: 'Unauthorized' }); }); it('refreshToken success', (done: DoneFn) => { - strategy.refreshToken() - .subscribe((result: NbAuthResult) => { - expect(result).toBeTruthy(); - expect(result.isFailure()).toBe(false); - expect(result.isSuccess()).toBe(true); - expect(result.getMessages()[0]).toBe('Success message'); + strategy.refreshToken().subscribe((result: NbAuthResult) => { + expect(result).toBeTruthy(); + expect(result.isFailure()).toBe(false); + expect(result.isSuccess()).toBe(true); + expect(result.getMessages()[0]).toBe('Success message'); - done(); - }); + done(); + }); - httpMock.expectOne('/api/auth/refresh-token') - .flush(customResponse); + httpMock.expectOne('/api/auth/refresh-token').flush(customResponse); }); it('refreshToken fail', (done: DoneFn) => { - strategy.refreshToken() - .subscribe((result: NbAuthResult) => { - expect(result).toBeTruthy(); - expect(result.isFailure()).toBe(true); - expect(result.isSuccess()).toBe(false); - expect(result.getErrors()[0]).toBe('Error message'); + strategy.refreshToken().subscribe((result: NbAuthResult) => { + expect(result).toBeTruthy(); + expect(result.isFailure()).toBe(true); + expect(result.isSuccess()).toBe(false); + expect(result.getErrors()[0]).toBe('Error message'); - done(); - }); + done(); + }); - httpMock.expectOne('/api/auth/refresh-token') - .flush(customResponse, { status: 401, statusText: 'Unauthorized' }); + httpMock.expectOne('/api/auth/refresh-token').flush(customResponse, { status: 401, statusText: 'Unauthorized' }); }); - }); describe('custom requireValidToken', () => { - it('authenticate fail as no token when requireValidToken is set', (done: DoneFn) => { strategy.setOptions({ name: ownerStrategyName, @@ -1462,24 +1281,23 @@ describe('password-auth-strategy', () => { requireValidToken: true, }, }); - strategy.authenticate(loginData) - .subscribe((result: NbAuthResult) => { - expect(result).toBeTruthy(); - expect(result.isFailure()).toBe(true); - expect(result.isSuccess()).toBe(false); - expect(result.getMessages()).toEqual([]); - expect(result.getErrors()[0]).toEqual('Token is empty or invalid.'); - done(); - }); - - httpMock.expectOne('/api/auth/login') - .flush({data: { + strategy.authenticate(loginData).subscribe((result: NbAuthResult) => { + expect(result).toBeTruthy(); + expect(result.isFailure()).toBe(true); + expect(result.isSuccess()).toBe(false); + expect(result.getMessages()).toEqual([]); + expect(result.getErrors()[0]).toEqual('Token is empty or invalid.'); + done(); + }); + + httpMock.expectOne('/api/auth/login').flush({ + data: { message: 'Successfully logged in!', - }}); + }, + }); }); it('authenticate does not fail even when no token', (done: DoneFn) => { - strategy.setOptions({ name: ownerStrategyName, login: { @@ -1487,19 +1305,17 @@ describe('password-auth-strategy', () => { }, }); - strategy.authenticate(loginData) - .subscribe((result: NbAuthResult) => { - expect(result).toBeTruthy(); - expect(result.isFailure()).toBe(false); - expect(result.isSuccess()).toBe(true); - expect(result.getMessages()[0]).toEqual('You have been successfully logged in.'); - expect(result.getErrors()).toEqual([]); + strategy.authenticate(loginData).subscribe((result: NbAuthResult) => { + expect(result).toBeTruthy(); + expect(result.isFailure()).toBe(false); + expect(result.isSuccess()).toBe(true); + expect(result.getMessages()[0]).toEqual('You have been successfully logged in.'); + expect(result.getErrors()).toEqual([]); - done(); - }); + done(); + }); - httpMock.expectOne('/api/auth/login') - .flush({}); + httpMock.expectOne('/api/auth/login').flush({}); }); it('register fail as no token and requireValidtoken is set', (done: DoneFn) => { @@ -1509,23 +1325,20 @@ describe('password-auth-strategy', () => { requireValidToken: true, }, }); - strategy.register(loginData) - .subscribe((result: NbAuthResult) => { - expect(result).toBeTruthy(); - expect(result.isFailure()).toBe(true); - expect(result.isSuccess()).toBe(false); - expect(result.getMessages()).toEqual([]); - expect(result.getErrors()[0]).toEqual('Token is empty or invalid.'); - - done(); - }); + strategy.register(loginData).subscribe((result: NbAuthResult) => { + expect(result).toBeTruthy(); + expect(result.isFailure()).toBe(true); + expect(result.isSuccess()).toBe(false); + expect(result.getMessages()).toEqual([]); + expect(result.getErrors()[0]).toEqual('Token is empty or invalid.'); + + done(); + }); - httpMock.expectOne('/api/auth/register') - .flush({}); + httpMock.expectOne('/api/auth/register').flush({}); }); it('register does not fail even when no token', (done: DoneFn) => { - strategy.setOptions({ name: ownerStrategyName, register: { @@ -1533,19 +1346,17 @@ describe('password-auth-strategy', () => { }, }); - strategy.register(loginData) - .subscribe((result: NbAuthResult) => { - expect(result).toBeTruthy(); - expect(result.isFailure()).toBe(false); - expect(result.isSuccess()).toBe(true); - expect(result.getMessages()[0]).toEqual('You have been successfully registered.'); - expect(result.getErrors()).toEqual([]); + strategy.register(loginData).subscribe((result: NbAuthResult) => { + expect(result).toBeTruthy(); + expect(result.isFailure()).toBe(false); + expect(result.isSuccess()).toBe(true); + expect(result.getMessages()[0]).toEqual('You have been successfully registered.'); + expect(result.getErrors()).toEqual([]); - done(); - }); + done(); + }); - httpMock.expectOne('/api/auth/register') - .flush({}); + httpMock.expectOne('/api/auth/register').flush({}); }); it('refreshToken fail as no token and requireValidToken is set', (done: DoneFn) => { @@ -1555,23 +1366,20 @@ describe('password-auth-strategy', () => { requireValidToken: true, }, }); - strategy.refreshToken(loginData) - .subscribe((result: NbAuthResult) => { - expect(result).toBeTruthy(); - expect(result.isFailure()).toBe(true); - expect(result.isSuccess()).toBe(false); - expect(result.getMessages()).toEqual([]); - expect(result.getErrors()[0]).toEqual('Token is empty or invalid.'); - - done(); - }); + strategy.refreshToken(loginData).subscribe((result: NbAuthResult) => { + expect(result).toBeTruthy(); + expect(result.isFailure()).toBe(true); + expect(result.isSuccess()).toBe(false); + expect(result.getMessages()).toEqual([]); + expect(result.getErrors()[0]).toEqual('Token is empty or invalid.'); + + done(); + }); - httpMock.expectOne('/api/auth/refresh-token') - .flush({}); + httpMock.expectOne('/api/auth/refresh-token').flush({}); }); it('refreshToken does not fail even when no token', (done: DoneFn) => { - strategy.setOptions({ name: ownerStrategyName, refreshToken: { @@ -1579,20 +1387,17 @@ describe('password-auth-strategy', () => { }, }); - strategy.refreshToken(loginData) - .subscribe((result: NbAuthResult) => { - expect(result).toBeTruthy(); - expect(result.isFailure()).toBe(false); - expect(result.isSuccess()).toBe(true); - expect(result.getMessages()[0]).toEqual('Your token has been successfully refreshed.'); - expect(result.getErrors()).toEqual([]); + strategy.refreshToken(loginData).subscribe((result: NbAuthResult) => { + expect(result).toBeTruthy(); + expect(result.isFailure()).toBe(false); + expect(result.isSuccess()).toBe(true); + expect(result.getMessages()[0]).toEqual('Your token has been successfully refreshed.'); + expect(result.getErrors()).toEqual([]); - done(); - }); + done(); + }); - httpMock.expectOne('/api/auth/refresh-token') - .flush({}); + httpMock.expectOne('/api/auth/refresh-token').flush({}); }); }); - }); diff --git a/src/framework/date-fns/services/date-fns-date.service.spec.ts b/src/framework/date-fns/services/date-fns-date.service.spec.ts index 78893e8b3d..818b64b74a 100644 --- a/src/framework/date-fns/services/date-fns-date.service.spec.ts +++ b/src/framework/date-fns/services/date-fns-date.service.spec.ts @@ -8,8 +8,7 @@ import { TestBed } from '@angular/core/testing'; import { LOCALE_ID } from '@angular/core'; import { NbDateService } from '@nebular/theme'; - -import { NbDateFnsDateService } from './date-fns-date.service'; +import { NbDateFnsDateService } from '@nebular/date-fns'; describe('date-fns-date-service', () => { let dateService: NbDateService; @@ -24,7 +23,7 @@ describe('date-fns-date-service', () => { expect(dateService.parse(date, 'MM.dd.yyyy')).toEqual(new Date(2018, 5, 15)); }); - it('should not format if date isn\'t passed', () => { + it("should not format if date isn't passed", () => { expect(() => dateService.format(undefined, 'DD.MM.YYYY')).not.toThrow(); expect(dateService.format(undefined, 'DD.MM.YYYY')).toEqual(''); }); @@ -40,23 +39,20 @@ describe('date-fns-date-service', () => { const formattedDate = `${month}${SEPARATOR}${day}${SEPARATOR}${year}`; beforeEach(() => { - dateService = new NbDateFnsDateService( - TestBed.inject(LOCALE_ID), - { - format: FORMAT, - parseOptions: { - useAdditionalWeekYearTokens: true, - useAdditionalDayOfYearTokens: true, - }, - formatOptions: { - useAdditionalWeekYearTokens: true, - useAdditionalDayOfYearTokens: true, - }, + dateService = new NbDateFnsDateService(TestBed.inject(LOCALE_ID), { + format: FORMAT, + parseOptions: { + useAdditionalWeekYearTokens: true, + useAdditionalDayOfYearTokens: true, + }, + formatOptions: { + useAdditionalWeekYearTokens: true, + useAdditionalDayOfYearTokens: true, }, - ); + }); }); - it('should use format from global config if isn\'t passed as parameter', () => { + it("should use format from global config if isn't passed as parameter", () => { expect(dateService.format(date, undefined)).toEqual(formattedDate); const parsedDate = dateService.parse(formattedDate, FORMAT); diff --git a/src/framework/moment/services/moment-date.service.spec.ts b/src/framework/moment/services/moment-date.service.spec.ts index 00a4324eb7..bcfd86859a 100644 --- a/src/framework/moment/services/moment-date.service.spec.ts +++ b/src/framework/moment/services/moment-date.service.spec.ts @@ -8,7 +8,7 @@ import { LOCALE_ID } from '@angular/core'; import { TestBed } from '@angular/core/testing'; import { NbDateService } from '@nebular/theme'; -import { NbMomentDateService } from './moment-date.service'; +import { NbMomentDateService } from '@nebular/moment'; import * as moment from 'moment'; type Moment = moment.Moment; @@ -41,8 +41,7 @@ describe('moment-date-service', () => { expect(isValid).toBeTruthy(); }); - it('should validate as correct if time string is valid according to the twelve hours format', - () => { + it('should validate as correct if time string is valid according to the twelve hours format', () => { const isValid = dateService.isValidTimeString('04:23:00 AM', 'hh:mm:ss A'); expect(isValid).toBeTruthy(); }); @@ -88,8 +87,7 @@ describe('moment-date-service', () => { }); it('should get milliseconds', () => { - const second = moment().year(2018).month(5).date(15).hour(12) - .minute(10).second(24).milliseconds(22); + const second = moment().year(2018).month(5).date(15).hour(12).minute(10).second(24).milliseconds(22); expect(dateService.getMilliseconds(second)).toBe(22); }); @@ -143,7 +141,7 @@ describe('moment-date-service', () => { expect(parsed.date()).toEqual(15); }); - it('should not format if date isn\'t passed', () => { + it("should not format if date isn't passed", () => { expect(() => dateService.format(undefined, 'DD.MM.YYYY')).not.toThrow(); expect(dateService.format(undefined, 'DD.MM.YYYY')).toEqual(''); }); @@ -281,21 +279,25 @@ describe('moment-date-service', () => { }); it('should compare days correctly', () => { - expect(dateService.isSameMonth(moment().year(2018).month(6).date(16), - moment().year(2018).month(6).date(16))).toBeTruthy(); - expect(dateService.isSameMonth(moment().year(2018).month(7).date(16), - moment().year(2018).month(6).date(16))).toBeFalsy(); + expect( + dateService.isSameMonth(moment().year(2018).month(6).date(16), moment().year(2018).month(6).date(16)), + ).toBeTruthy(); + expect( + dateService.isSameMonth(moment().year(2018).month(7).date(16), moment().year(2018).month(6).date(16)), + ).toBeFalsy(); }); it('should compare dates correctly', () => { - expect(dateService.compareDates(moment().year(2018).month(6).date(16), - moment().year(2017).month(2).date(14))).toBeGreaterThan(0); + expect( + dateService.compareDates(moment().year(2018).month(6).date(16), moment().year(2017).month(2).date(14)), + ).toBeGreaterThan(0); - expect(dateService.compareDates(moment().year(2018).month(6).date(16), - moment().year(2019).month(2).date(14))).toBeLessThan(0); + expect( + dateService.compareDates(moment().year(2018).month(6).date(16), moment().year(2019).month(2).date(14)), + ).toBeLessThan(0); - expect(dateService.compareDates(moment().year(2018).month(6).date(16), - moment().year(2018).month(6).date(16))).toBe(0); + expect(dateService.compareDates(moment().year(2018).month(6).date(16), moment().year(2018).month(6).date(16))).toBe( + 0, + ); }); }); - diff --git a/src/framework/security/services/access-checker.spec.ts b/src/framework/security/services/access-checker.spec.ts index 2bfe6a5d74..8fec3ed72e 100644 --- a/src/framework/security/services/access-checker.spec.ts +++ b/src/framework/security/services/access-checker.spec.ts @@ -5,14 +5,11 @@ */ import { TestBed, inject, waitForAsync } from '@angular/core/testing'; import { of as observableOf } from 'rxjs'; - -import { NbRoleProvider } from './role.provider'; -import { NbAclService } from './acl.service'; -import { NbAccessChecker } from './access-checker.service'; +import { NbRoleProvider, NbAclService, NbAccessChecker } from '@nebular/security'; let accessChecker: NbAccessChecker; -function setupAcl(can, roles: string|string[]) { +function setupAcl(can, roles: string | string[]) { beforeEach(() => { // Configure testbed to prepare services TestBed.configureTestingModule({ @@ -39,16 +36,16 @@ function setupAcl(can, roles: string|string[]) { }); // Single async inject to save references; which are used in all tests below - beforeEach(waitForAsync(inject( - [NbAccessChecker], - (_accessChecker) => { - accessChecker = _accessChecker - }, - ))); + beforeEach( + waitForAsync( + inject([NbAccessChecker], (_accessChecker) => { + accessChecker = _accessChecker; + }), + ), + ); } describe('authorization checker', () => { - describe('acl returns true', () => { setupAcl({ admin: true }, 'admin'); @@ -56,7 +53,7 @@ describe('authorization checker', () => { accessChecker.isGranted('delete', 'users').subscribe((result: boolean) => { expect(result).toBe(true); done(); - }) + }); }); }); @@ -67,7 +64,7 @@ describe('authorization checker', () => { accessChecker.isGranted('delete', 'users').subscribe((result: boolean) => { expect(result).toBe(false); done(); - }) + }); }); }); @@ -78,7 +75,7 @@ describe('authorization checker', () => { accessChecker.isGranted('delete', 'users').subscribe((result: boolean) => { expect(result).toBe(false); done(); - }) + }); }); }); @@ -89,7 +86,7 @@ describe('authorization checker', () => { accessChecker.isGranted('delete', 'users').subscribe((result: boolean) => { expect(result).toBe(true); done(); - }) + }); }); }); @@ -100,7 +97,7 @@ describe('authorization checker', () => { accessChecker.isGranted('delete', 'users').subscribe((result: boolean) => { expect(result).toBe(true); done(); - }) + }); }); }); }); diff --git a/src/framework/security/services/acl.spec.ts b/src/framework/security/services/acl.spec.ts index c7f8950699..455fee6ece 100644 --- a/src/framework/security/services/acl.spec.ts +++ b/src/framework/security/services/acl.spec.ts @@ -5,17 +5,15 @@ */ import { TestBed, inject, waitForAsync } from '@angular/core/testing'; -import { NbAclService } from './acl.service'; -import { NB_SECURITY_OPTIONS_TOKEN } from '../security.options'; +import { NbAclService, NB_SECURITY_OPTIONS_TOKEN } from '@nebular/security'; import { deepExtend } from '../../auth/helpers'; // TODO: common module? - let aclService: NbAclService; -function sharedAclTests (defaultSettings) { - +function sharedAclTests(defaultSettings) { it(`should store different object`, () => { - expect(defaultSettings.accessControl).not.toBe(aclService['state']); + // @ts-ignore + expect(defaultSettings.accessControl).not.toBe(aclService.state); }); it(`forbidden for any role - permission - resource`, () => { @@ -29,7 +27,8 @@ function sharedAclTests (defaultSettings) { }; aclService.register('guest', null, {}); - expect(aclService['state']).toEqual(modifiedRoles); + // @ts-ignore + expect(aclService.state).toEqual(modifiedRoles); }); it(`can register a role with default values`, () => { @@ -39,7 +38,8 @@ function sharedAclTests (defaultSettings) { }; aclService.register('guest'); - expect(aclService['state']).toEqual(modifiedRoles); + // @ts-ignore + expect(aclService.state).toEqual(modifiedRoles); }); it(`can register a role with custom values`, () => { @@ -50,7 +50,8 @@ function sharedAclTests (defaultSettings) { }; aclService.register('guest', null, { view: ['users'] }); - expect(aclService['state']).toEqual(modifiedRoles); + // @ts-ignore + expect(aclService.state).toEqual(modifiedRoles); }); it(`will rewrite newly registered role`, () => { @@ -62,7 +63,8 @@ function sharedAclTests (defaultSettings) { view: ['users'], }; aclService.register('guest', null, { view: ['users'] }); - expect(aclService['state']).toEqual(modifiedRoles); + // @ts-ignore + expect(aclService.state).toEqual(modifiedRoles); modifiedRoles = deepExtend({}, defaultSettings.accessControl); modifiedRoles.guest = { @@ -70,7 +72,8 @@ function sharedAclTests (defaultSettings) { edit: ['users'], }; aclService.register('guest', null, { edit: ['users'] }); - expect(aclService['state']).toEqual(modifiedRoles); + // @ts-ignore + expect(aclService.state).toEqual(modifiedRoles); }); it(`can register multiple roles`, () => { @@ -83,7 +86,8 @@ function sharedAclTests (defaultSettings) { }; aclService.register('guest', null, { view: ['users'] }); - expect(aclService['state']).toEqual(modifiedRoles); + // @ts-ignore + expect(aclService.state).toEqual(modifiedRoles); modifiedRoles = deepExtend({}, defaultSettings.accessControl); modifiedRoles.guest = { @@ -95,17 +99,20 @@ function sharedAclTests (defaultSettings) { edit: ['users'], }; aclService.register('user', 'guest', { edit: ['users'] }); - expect(aclService['state']).toEqual(modifiedRoles); + // @ts-ignore + expect(aclService.state).toEqual(modifiedRoles); }); it(`cannot register a role with an empty name`, () => { - expect(() => aclService.register('', null, { view: ['users'] })) - .toThrow(new Error('NbAclService: role name cannot be empty')); + expect(() => aclService.register('', null, { view: ['users'] })).toThrow( + new Error('NbAclService: role name cannot be empty'), + ); }); it(`cannot check bulk resource`, () => { - expect(() => aclService.can('guest', 'edit', '*')) - .toThrow(new Error(`NbAclService: cannot use empty or bulk '*' resource placeholder with 'can' method`)); + expect(() => aclService.can('guest', 'edit', '*')).toThrow( + new Error(`NbAclService: cannot use empty or bulk '*' resource placeholder with 'can' method`), + ); }); it(`can handle permissions`, () => { @@ -209,8 +216,7 @@ function sharedAclTests (defaultSettings) { }); it(`cannot allow empty role for 'allow' method`, () => { - expect(() => aclService.allow('', null, 'users' )) - .toThrow(new Error('NbAclService: role name cannot be empty')); + expect(() => aclService.allow('', null, 'users')).toThrow(new Error('NbAclService: role name cannot be empty')); }); it(`should allow new role`, () => { @@ -228,7 +234,6 @@ function sharedAclTests (defaultSettings) { expect(aclService.can('guest', 'edit', 'users')).toBe(true); }); - it(`should allow new permissions on parent role`, () => { aclService.register('guest', null, { view: ['users'] }); aclService.register('user', 'guest', { remove: ['users'] }); @@ -253,7 +258,6 @@ function sharedAclTests (defaultSettings) { }); it(`cannot be changed by reference through module options`, () => { - const settings = { accessControl: { guest: { @@ -274,13 +278,15 @@ function sharedAclTests (defaultSettings) { expect(aclService.can('super_user', 'view', 'users')).toBe(false); expect(aclService.can('super_user', 'edit', 'users')).toBe(false); - settings.accessControl['admin'] = { + // @ts-ignore + settings.accessControl.admin = { parent: 'guest', manage: ['all'], view: ['users'], }; - settings.accessControl['admin'] = { + // @ts-ignore + settings.accessControl.admin = { parent: 'guest', manage: ['all'], edit: ['users'], @@ -293,7 +299,6 @@ function sharedAclTests (defaultSettings) { }); it(`cannot be changed by reference through allow`, () => { - const resources = ['dashboard']; aclService.allow('super_user', 'view', resources); @@ -304,22 +309,21 @@ function sharedAclTests (defaultSettings) { }); it(`cannot be changed by reference through register`, () => { - const abilities = { view: ['users'] }; aclService.register('moderator', null, abilities); expect(aclService.can('moderator', 'view', 'users')).toBe(true); - abilities['view'] = ['users', 'dashboard']; - abilities['edit'] = ['users']; + abilities.view = ['users', 'dashboard']; + // @ts-ignore + abilities.edit = ['users']; expect(aclService.can('moderator', 'view', 'users')).toBe(true); expect(aclService.can('moderator', 'view', 'dashboard')).toBe(false); expect(aclService.can('moderator', 'edit', 'users')).toBe(false); }); it(`can accept roles as string`, () => { - aclService.register('role', null, { view: 'all', edit: '*' }); expect(aclService.can('role', 'view', 'all')).toBe(true); @@ -329,39 +333,34 @@ function sharedAclTests (defaultSettings) { }); } - describe('acl-service', () => { - describe('with default settings', () => { - beforeEach(() => { // Configure testbed to prepare services TestBed.configureTestingModule({ - providers: [ - { provide: NB_SECURITY_OPTIONS_TOKEN, useValue: {} }, - NbAclService, - ], + providers: [{ provide: NB_SECURITY_OPTIONS_TOKEN, useValue: {} }, NbAclService], }); }); // Single async inject to save references; which are used in all tests below - beforeEach(waitForAsync(inject( - [NbAclService], - (_aclService) => { - aclService = _aclService - }, - ))); + beforeEach( + waitForAsync( + inject([NbAclService], (_aclService) => { + aclService = _aclService; + }), + ), + ); it(`has empty default state`, () => { - expect(aclService['state']).toEqual({}); + // @ts-ignore + expect(aclService.state).toEqual({}); }); sharedAclTests({ accessControl: {} }); }); describe('with some roles settings', () => { - - const defaultSettings = { + const defaultSettings = { accessControl: { guest: { parent: null, @@ -385,15 +384,17 @@ describe('acl-service', () => { }); // Single async inject to save references; which are used in all tests below - beforeEach(waitForAsync(inject( - [NbAclService], - (_aclService) => { - aclService = _aclService - }, - ))); + beforeEach( + waitForAsync( + inject([NbAclService], (_aclService) => { + aclService = _aclService; + }), + ), + ); it(`has predefined default state`, () => { - expect(aclService['state']).toEqual(defaultSettings.accessControl); + // @ts-ignore + expect(aclService.state).toEqual(defaultSettings.accessControl); }); sharedAclTests(defaultSettings); @@ -406,7 +407,6 @@ describe('acl-service', () => { }); describe('with some roles settings (not cloned)', () => { - const defaultSettings = { accessControl: { guest: { @@ -423,23 +423,22 @@ describe('acl-service', () => { beforeEach(() => { // Configure testbed to prepare services TestBed.configureTestingModule({ - providers: [ - { provide: NB_SECURITY_OPTIONS_TOKEN, useFactory: () => defaultSettings }, - NbAclService, - ], + providers: [{ provide: NB_SECURITY_OPTIONS_TOKEN, useFactory: () => defaultSettings }, NbAclService], }); }); // Single async inject to save references; which are used in all tests below - beforeEach(waitForAsync(inject( - [NbAclService], - (_aclService) => { - aclService = _aclService - }, - ))); + beforeEach( + waitForAsync( + inject([NbAclService], (_aclService) => { + aclService = _aclService; + }), + ), + ); it(`has predefined default state`, () => { - expect(aclService['state']).toEqual(defaultSettings.accessControl); + // @ts-ignore + expect(aclService.state).toEqual(defaultSettings.accessControl); }); sharedAclTests(defaultSettings); @@ -452,7 +451,6 @@ describe('acl-service', () => { }); describe('with bulk resources', () => { - const defaultSettings = { accessControl: { guest: { @@ -482,15 +480,17 @@ describe('acl-service', () => { }); // Single async inject to save references; which are used in all tests below - beforeEach(waitForAsync(inject( - [NbAclService], - (_aclService) => { - aclService = _aclService - }, - ))); + beforeEach( + waitForAsync( + inject([NbAclService], (_aclService) => { + aclService = _aclService; + }), + ), + ); it(`has predefined default state`, () => { - expect(aclService['state']).toEqual(defaultSettings.accessControl); + // @ts-ignore + expect(aclService.state).toEqual(defaultSettings.accessControl); }); sharedAclTests(defaultSettings); diff --git a/src/framework/theme/components/calendar-kit/components/calendar-day-picker/calendar-day-cell.component.spec.ts b/src/framework/theme/components/calendar-kit/components/calendar-day-picker/calendar-day-cell.component.spec.ts index d59768c4e5..183b8e1bfe 100644 --- a/src/framework/theme/components/calendar-kit/components/calendar-day-picker/calendar-day-cell.component.spec.ts +++ b/src/framework/theme/components/calendar-kit/components/calendar-day-picker/calendar-day-cell.component.spec.ts @@ -7,10 +7,7 @@ import { ComponentFixture, TestBed } from '@angular/core/testing'; import { DatePipe } from '@angular/common'; -import { NbCalendarDayCellComponent } from './calendar-day-cell.component'; -import { NbDateService } from '../../services/date.service'; -import { NbNativeDateService } from '../../services/native-date.service'; -import { NbCalendarKitModule } from '../../calendar-kit.module'; +import { NbCalendarDayCellComponent, NbDateService, NbNativeDateService, NbCalendarKitModule } from '@nebular/theme'; describe('Component: NbCalendarDayCell', () => { let component: NbCalendarDayCellComponent; diff --git a/src/framework/theme/components/calendar-kit/components/calendar-days-names/calendar-days-names.component.spec.ts b/src/framework/theme/components/calendar-kit/components/calendar-days-names/calendar-days-names.component.spec.ts index bb1360914c..78cbeb6555 100644 --- a/src/framework/theme/components/calendar-kit/components/calendar-days-names/calendar-days-names.component.spec.ts +++ b/src/framework/theme/components/calendar-kit/components/calendar-days-names/calendar-days-names.component.spec.ts @@ -5,11 +5,8 @@ */ import { ComponentFixture, TestBed } from '@angular/core/testing'; - -import { NbCalendarDaysNamesComponent } from './calendar-days-names.component'; -import { NbDateService } from '../../services/date.service'; -import { NbNativeDateService } from '../../services/native-date.service'; import { DatePipe } from '@angular/common'; +import { NbCalendarDaysNamesComponent, NbDateService, NbNativeDateService } from '@nebular/theme'; describe('Component: NbCalendarDaysNames', () => { let fixture: ComponentFixture>; diff --git a/src/framework/theme/components/calendar-kit/components/calendar-month-picker/calendar-month-cell.component.spec.ts b/src/framework/theme/components/calendar-kit/components/calendar-month-picker/calendar-month-cell.component.spec.ts index 20873d8496..8b032d95fd 100644 --- a/src/framework/theme/components/calendar-kit/components/calendar-month-picker/calendar-month-cell.component.spec.ts +++ b/src/framework/theme/components/calendar-kit/components/calendar-month-picker/calendar-month-cell.component.spec.ts @@ -5,12 +5,8 @@ */ import { ComponentFixture, TestBed } from '@angular/core/testing'; - -import { NbCalendarMonthCellComponent } from './calendar-month-cell.component'; -import { NbDateService } from '../../services/date.service'; -import { NbNativeDateService } from '../../services/native-date.service'; import { DatePipe } from '@angular/common'; - +import { NbCalendarMonthCellComponent, NbDateService, NbNativeDateService } from '@nebular/theme'; describe('Component: NbCalendarMonthCell', () => { let component: NbCalendarMonthCellComponent; @@ -52,7 +48,7 @@ describe('Component: NbCalendarMonthCell', () => { component.date = date; component.selectedValue = new Date(); fixture.detectChanges(); - component.select.subscribe(e => expect(e).toBe(date)); + component.select.subscribe((e) => expect(e).toBe(date)); componentEl.dispatchEvent(new Event('click')); expect(componentEl.classList).toContain('selected'); }); diff --git a/src/framework/theme/components/calendar-kit/components/calendar-picker/calendar-picker-row.component.spec.ts b/src/framework/theme/components/calendar-kit/components/calendar-picker/calendar-picker-row.component.spec.ts index da30341437..bb854a6792 100644 --- a/src/framework/theme/components/calendar-kit/components/calendar-picker/calendar-picker-row.component.spec.ts +++ b/src/framework/theme/components/calendar-kit/components/calendar-picker/calendar-picker-row.component.spec.ts @@ -9,11 +9,13 @@ import { By } from '@angular/platform-browser'; import { NO_ERRORS_SCHEMA } from '@angular/core'; import { DatePipe } from '@angular/common'; -import { NbCalendarPickerRowComponent } from './calendar-picker-row.component'; -import { NbCalendarDayCellComponent } from '../calendar-day-picker/calendar-day-cell.component'; -import { NbDateService } from '../../services/date.service'; -import { NbNativeDateService } from '../../services/native-date.service'; -import { NbCalendarKitModule } from '../../calendar-kit.module'; +import { + NbCalendarPickerRowComponent, + NbCalendarDayCellComponent, + NbDateService, + NbNativeDateService, + NbCalendarKitModule, +} from '@nebular/theme'; describe('Component: NbCalendarPickerRow', () => { let fixture: ComponentFixture>; diff --git a/src/framework/theme/components/calendar-kit/components/calendar-year-picker/calendar-year-cell.component.spec.ts b/src/framework/theme/components/calendar-kit/components/calendar-year-picker/calendar-year-cell.component.spec.ts index 640cba3169..83509e0093 100644 --- a/src/framework/theme/components/calendar-kit/components/calendar-year-picker/calendar-year-cell.component.spec.ts +++ b/src/framework/theme/components/calendar-kit/components/calendar-year-picker/calendar-year-cell.component.spec.ts @@ -5,12 +5,8 @@ */ import { ComponentFixture, TestBed } from '@angular/core/testing'; - -import { NbDateService } from '../../services/date.service'; -import { NbNativeDateService } from '../../services/native-date.service'; -import { NbCalendarYearCellComponent } from './calendar-year-cell.component'; import { DatePipe } from '@angular/common'; - +import { NbDateService, NbNativeDateService, NbCalendarYearCellComponent } from '@nebular/theme'; describe('Component: NbCalendarYearCell', () => { let component: NbCalendarYearCellComponent; @@ -52,7 +48,7 @@ describe('Component: NbCalendarYearCell', () => { component.date = date; component.selectedValue = new Date(); fixture.detectChanges(); - component.select.subscribe(e => expect(e).toBe(date)); + component.select.subscribe((e) => expect(e).toBe(date)); componentEl.dispatchEvent(new Event('click')); expect(componentEl.classList).toContain('selected'); }); diff --git a/src/framework/theme/components/calendar-kit/components/calendar-year-picker/calendar-year-picker.component.spec.ts b/src/framework/theme/components/calendar-kit/components/calendar-year-picker/calendar-year-picker.component.spec.ts index 3406de47f7..2c7759bffd 100644 --- a/src/framework/theme/components/calendar-kit/components/calendar-year-picker/calendar-year-picker.component.spec.ts +++ b/src/framework/theme/components/calendar-kit/components/calendar-year-picker/calendar-year-picker.component.spec.ts @@ -5,9 +5,7 @@ */ import { ComponentFixture, TestBed } from '@angular/core/testing'; - -import { NbCalendarYearPickerComponent } from './calendar-year-picker.component'; -import { NbCalendarKitModule } from '../../calendar-kit.module'; +import { NbCalendarYearPickerComponent, NbCalendarKitModule } from '@nebular/theme'; describe('Component: NbCalendarYearPicker', () => { let fixture: ComponentFixture>; diff --git a/src/framework/theme/components/calendar-kit/services/calendar-month-model.spec.ts b/src/framework/theme/components/calendar-kit/services/calendar-month-model.spec.ts index 7eef61e516..169450042f 100644 --- a/src/framework/theme/components/calendar-kit/services/calendar-month-model.spec.ts +++ b/src/framework/theme/components/calendar-kit/services/calendar-month-model.spec.ts @@ -7,10 +7,7 @@ import { inject, TestBed, waitForAsync } from '@angular/core/testing'; import { DatePipe } from '@angular/common'; -import { NbCalendarMonthModelService } from './calendar-month-model.service'; -import { NbDateService } from './date.service'; -import { NbNativeDateService } from './native-date.service'; - +import { NbCalendarMonthModelService, NbDateService, NbNativeDateService } from '@nebular/theme'; describe('month-model-service', () => { let monthModel: NbCalendarMonthModelService; @@ -21,12 +18,13 @@ describe('month-model-service', () => { }); }); - beforeEach(waitForAsync(inject( - [NbCalendarMonthModelService], - (_monthModel) => { - monthModel = _monthModel; - }, - ))); + beforeEach( + waitForAsync( + inject([NbCalendarMonthModelService], (_monthModel) => { + monthModel = _monthModel; + }), + ), + ); it('should create days grid with active month', () => { const date = new Date(2018, 7, 1); @@ -42,10 +40,10 @@ describe('month-model-service', () => { const grid: Date[][] = monthModel.createDaysGrid(date, false); const firstTwoEmpty = grid.shift().slice(0, 3); const lastTwoEmpty = grid.pop().slice(6); - firstTwoEmpty.forEach(cell => { + firstTwoEmpty.forEach((cell) => { expect(cell).toBeNull(); }); - lastTwoEmpty.forEach(cell => { + lastTwoEmpty.forEach((cell) => { expect(cell).toBeNull(); }); }); diff --git a/src/framework/theme/components/calendar-kit/services/calendar-time-model.service.spec.ts b/src/framework/theme/components/calendar-kit/services/calendar-time-model.service.spec.ts index 31d64d2ba2..3cdf5e6bc3 100644 --- a/src/framework/theme/components/calendar-kit/services/calendar-time-model.service.spec.ts +++ b/src/framework/theme/components/calendar-kit/services/calendar-time-model.service.spec.ts @@ -1,13 +1,11 @@ - /** +/** * @license * Copyright Akveo. All Rights Reserved. * Licensed under the MIT License. See License.txt in the project root for license information. */ import { inject, TestBed, waitForAsync } from '@angular/core/testing'; -import { NbDateService } from './date.service'; -import { NbNativeDateService } from './native-date.service'; -import { NbCalendarTimeModelService } from '@nebular/theme'; +import { NbDateService, NbNativeDateService, NbCalendarTimeModelService } from '@nebular/theme'; describe('time-model-service', () => { let timeModel: NbCalendarTimeModelService; @@ -18,12 +16,13 @@ describe('time-model-service', () => { }); }); - beforeEach(waitForAsync(inject( - [NbCalendarTimeModelService], - (_monthModel) => { - timeModel = _monthModel; - }, - ))); + beforeEach( + waitForAsync( + inject([NbCalendarTimeModelService], (_monthModel) => { + timeModel = _monthModel; + }), + ), + ); it('should format number', () => { const token = timeModel.paddToTwoSymbols(5); diff --git a/src/framework/theme/components/cdk/overlay/dynamic/dynamic-overlay.spec.ts b/src/framework/theme/components/cdk/overlay/dynamic/dynamic-overlay.spec.ts index 21b05e7a1b..b4759adcd2 100644 --- a/src/framework/theme/components/cdk/overlay/dynamic/dynamic-overlay.spec.ts +++ b/src/framework/theme/components/cdk/overlay/dynamic/dynamic-overlay.spec.ts @@ -2,11 +2,14 @@ import { TestBed } from '@angular/core/testing'; import { Component, ComponentFactoryResolver, EventEmitter, Input, NgZone } from '@angular/core'; import { Subject } from 'rxjs'; import { ScrollStrategy } from '@angular/cdk/overlay'; - -import { NbDynamicOverlay } from './dynamic-overlay'; -import { NbOverlayService } from '../overlay-service'; -import { NbRenderableContainer } from '../overlay-container'; -import { NbComponentPortal, NbOverlayConfig, NbOverlayContainer } from '../mapping'; +import { + NbDynamicOverlay, + NbOverlayService, + NbRenderableContainer, + NbComponentPortal, + NbOverlayConfig, + NbOverlayContainer, +} from '@nebular/theme'; @Component({ template: '' }) export class NbDynamicOverlayMockComponent implements NbRenderableContainer { diff --git a/src/framework/theme/components/cdk/overlay/overlay-trigger.spec.ts b/src/framework/theme/components/cdk/overlay/overlay-trigger.spec.ts index 5bc4302d52..8310a3abbf 100644 --- a/src/framework/theme/components/cdk/overlay/overlay-trigger.spec.ts +++ b/src/framework/theme/components/cdk/overlay/overlay-trigger.spec.ts @@ -1,9 +1,7 @@ import { DOCUMENT } from '@angular/common'; -import { fakeAsync, flush, TestBed, tick } from '@angular/core/testing'; +import { fakeAsync, TestBed, tick } from '@angular/core/testing'; import { ComponentRef } from '@angular/core'; - -import { NbTrigger, NbTriggerStrategyBuilderService } from './overlay-trigger'; -import { NB_DOCUMENT } from '../../../theme.options'; +import { NbTrigger, NbTriggerStrategyBuilderService, NB_DOCUMENT } from '@nebular/theme'; import createSpy = jasmine.createSpy; // TODO: move into a separate file diff --git a/src/framework/theme/components/chat/chat-custom-message.directive.spec.ts b/src/framework/theme/components/chat/chat-custom-message.directive.spec.ts index 562b3ea53e..88889f923e 100644 --- a/src/framework/theme/components/chat/chat-custom-message.directive.spec.ts +++ b/src/framework/theme/components/chat/chat-custom-message.directive.spec.ts @@ -1,15 +1,14 @@ import { Component } from '@angular/core'; import { ComponentFixture, TestBed } from '@angular/core/testing'; -import { NbChatModule, NbThemeModule } from '@nebular/theme'; -import { NbCustomMessageService } from './custom-message.service'; +import { NbChatModule, NbThemeModule, NbChatCustomMessageService } from '@nebular/theme'; @Component({ selector: 'nb-custom-message-directive-test', template: `
-

Hello world

+

Hello world

- `, + `, }) export class NbCustomMessageTestComponent { customMessageType: string = 'simpleMessageType'; @@ -23,7 +22,7 @@ describe('Directive chat-custom-message-directive: NbCustomMessageTestComponent' TestBed.configureTestingModule({ imports: [NbThemeModule.forRoot(), NbChatModule], declarations: [NbCustomMessageTestComponent], - providers: [NbCustomMessageService], + providers: [NbChatCustomMessageService], }); fixture = TestBed.createComponent(NbCustomMessageTestComponent); diff --git a/src/framework/theme/components/chat/chat-custom-message.directive.ts b/src/framework/theme/components/chat/chat-custom-message.directive.ts index c9154dbb8a..ede2967625 100644 --- a/src/framework/theme/components/chat/chat-custom-message.directive.ts +++ b/src/framework/theme/components/chat/chat-custom-message.directive.ts @@ -1,7 +1,7 @@ import { Directive, Input, OnDestroy, OnInit, TemplateRef } from '@angular/core'; import { convertToBoolProperty, NbBooleanInput } from '../helpers'; -import { NbCustomMessageService } from './custom-message.service'; +import { NbChatCustomMessageService } from './chat-custom-message.service'; function throwCustomMessageTypeIsRequired(): void { throw new Error('[nbCustomMessage]: custom message type is required.'); @@ -26,7 +26,6 @@ function throwCustomMessageTypeIsRequired(): void { selector: `[nbCustomMessage]`, }) export class NbChatCustomMessageDirective implements OnInit, OnDestroy { - /** * Defines a message type which should rendered with the custom message template. * @type {string} @@ -41,7 +40,7 @@ export class NbChatCustomMessageDirective implements OnInit, OnDestroy { protected _type: string; get type(): string { - return this._type + return this._type; } /** @@ -64,7 +63,7 @@ export class NbChatCustomMessageDirective implements OnInit, OnDestroy { return this.nbCustomMessageNoStyles; } - constructor(public templateRef: TemplateRef, protected customMessageService: NbCustomMessageService) { } + constructor(public templateRef: TemplateRef, protected customMessageService: NbChatCustomMessageService) {} ngOnInit() { if (!this._type) { diff --git a/src/framework/theme/components/chat/custom-message.service.ts b/src/framework/theme/components/chat/chat-custom-message.service.ts similarity index 77% rename from src/framework/theme/components/chat/custom-message.service.ts rename to src/framework/theme/components/chat/chat-custom-message.service.ts index 37ffe73809..76de59c9bb 100644 --- a/src/framework/theme/components/chat/custom-message.service.ts +++ b/src/framework/theme/components/chat/chat-custom-message.service.ts @@ -1,3 +1,9 @@ +/** + * @license + * Copyright Akveo. All Rights Reserved. + * Licensed under the MIT License. See License.txt in the project root for license information. + */ + import { Injectable } from '@angular/core'; import { NbChatCustomMessageDirective } from './chat-custom-message.directive'; @@ -7,8 +13,7 @@ import { NbChatCustomMessageDirective } from './chat-custom-message.directive'; * were provided in the chat component. */ @Injectable() -export class NbCustomMessageService { - +export class NbChatCustomMessageService { protected readonly customMessages = new Map(); register(type: string, instance: NbChatCustomMessageDirective): void { diff --git a/src/framework/theme/components/chat/chat-message.component.spec.ts b/src/framework/theme/components/chat/chat-message.component.spec.ts index 7f13871251..9af988f98d 100644 --- a/src/framework/theme/components/chat/chat-message.component.spec.ts +++ b/src/framework/theme/components/chat/chat-message.component.spec.ts @@ -1,58 +1,59 @@ import { Component } from '@angular/core'; import { ComponentFixture, TestBed } from '@angular/core/testing'; import { BrowserAnimationsModule } from '@angular/platform-browser/animations'; -import { NbChatMessageComponent, NbChatModule, NbThemeModule } from '@nebular/theme'; -import { NbCustomMessageService } from './custom-message.service'; +import { NbChatMessageComponent, NbChatModule, NbThemeModule, NbChatCustomMessageService } from '@nebular/theme'; @Component({ selector: 'nb-chat-message-test', template: ` - - - - - - + + + + - `, + `, }) export class NbChatMessageTestComponent { messages = []; loadMessages(): void { - this.messages = [{ - reply: false, - type: 'link', - optionalData: { - href: 'https://akveo.github.io/ngx-admin/', - label: 'Visit Akveo Nebular', + this.messages = [ + { + reply: false, + type: 'link', + optionalData: { + href: 'https://akveo.github.io/ngx-admin/', + label: 'Visit Akveo Nebular', + }, + date: new Date(), + user: { + name: 'Frodo Baggins', + avatar: 'https://i.gifer.com/no.gif', + }, }, - date: new Date(), - user: { - name: 'Frodo Baggins', - avatar: 'https://i.gifer.com/no.gif', + { + text: 'Hello, how are you?', + reply: true, + type: 'text', + date: new Date(), + user: { + name: 'Bilbo Baggins', + avatar: '', + }, }, - }, - { - text: 'Hello, how are you?', - reply: true, - type: 'text', - date: new Date(), - user: { - name: 'Bilbo Baggins', - avatar: '', - }, - }]; + ]; } } @@ -88,8 +89,6 @@ describe('Chat-message component: NbChatMessageTestComponent', () => { const linkLabel = customMessageElement.textContent; expect(linkLabel).toBe('Visit Akveo Nebular'); }); - - }); describe('Component: NbChatMessageComponent', () => { @@ -99,7 +98,7 @@ describe('Component: NbChatMessageComponent', () => { beforeEach(() => { TestBed.configureTestingModule({ imports: [BrowserAnimationsModule, NbThemeModule.forRoot(), NbChatModule], - providers: [NbCustomMessageService], + providers: [NbChatCustomMessageService], }); fixture = TestBed.createComponent(NbChatMessageComponent); diff --git a/src/framework/theme/components/chat/chat-message.component.ts b/src/framework/theme/components/chat/chat-message.component.ts index daa0ae6047..990f824d76 100644 --- a/src/framework/theme/components/chat/chat-message.component.ts +++ b/src/framework/theme/components/chat/chat-message.component.ts @@ -10,7 +10,7 @@ import { animate, state, style, transition, trigger } from '@angular/animations' import { convertToBoolProperty, NbBooleanInput } from '../helpers'; import { NbChatMessageFile } from './chat-message-file.component'; -import { NbCustomMessageService } from './custom-message.service'; +import { NbChatCustomMessageService } from './chat-custom-message.service'; import { NbChatCustomMessageDirective } from './chat-custom-message.directive'; /** @@ -60,59 +60,62 @@ import { NbChatCustomMessageDirective } from './chat-custom-message.directive'; @Component({ selector: 'nb-chat-message', template: ` - - +
- + - + - + - +
- + -
- +
+
@@ -120,19 +123,13 @@ import { NbChatCustomMessageDirective } from './chat-custom-message.directive'; animations: [ trigger('flyInOut', [ state('in', style({ transform: 'translateX(0)' })), - transition('void => *', [ - style({ transform: 'translateX(-100%)' }), - animate(80), - ]), - transition('* => void', [ - animate(80, style({ transform: 'translateX(100%)' })), - ]), + transition('void => *', [style({ transform: 'translateX(-100%)' }), animate(80)]), + transition('* => void', [animate(80, style({ transform: 'translateX(100%)' }))]), ]), ], changeDetection: ChangeDetectionStrategy.OnPush, }) export class NbChatMessageComponent { - protected readonly builtInMessageTypes: string[] = ['text', 'file', 'map', 'quote']; avatarStyle: SafeStyle; @@ -241,12 +238,16 @@ export class NbChatMessageComponent { */ @Input() customMessageData: any; - constructor(protected domSanitizer: DomSanitizer, protected customMessageService: NbCustomMessageService) { } + constructor(protected domSanitizer: DomSanitizer, protected customMessageService: NbChatCustomMessageService) {} getInitials(): string { if (this.sender) { const names = this.sender.split(' '); - return names.map(n => n.charAt(0)).splice(0, 2).join('').toUpperCase(); + return names + .map((n) => n.charAt(0)) + .splice(0, 2) + .join('') + .toUpperCase(); } return ''; } @@ -261,7 +262,7 @@ export class NbChatMessageComponent { return customMessage.templateRef; } - _getTemplateContext(): { $implicit: any, isReply: boolean } { + _getTemplateContext(): { $implicit: any; isReply: boolean } { return { $implicit: this.customMessageData, isReply: this.reply }; } @@ -273,8 +274,10 @@ export class NbChatMessageComponent { protected getCustomMessage(type: string): NbChatCustomMessageDirective { const customMessageDirective = this.customMessageService.getInstance(type); if (!customMessageDirective) { - throw new Error(`nb-chat: Can't find template for custom type '${type}'. ` + - `Make sure you provide it in the chat component with *nbCustomMessage='${type}'.`); + throw new Error( + `nb-chat: Can't find template for custom type '${type}'. ` + + `Make sure you provide it in the chat component with *nbCustomMessage='${type}'.`, + ); } return customMessageDirective; } diff --git a/src/framework/theme/components/chat/chat.component.ts b/src/framework/theme/components/chat/chat.component.ts index ca4c5b96c7..4d674c49ba 100644 --- a/src/framework/theme/components/chat/chat.component.ts +++ b/src/framework/theme/components/chat/chat.component.ts @@ -25,7 +25,7 @@ import { NbComponentOrCustomStatus } from '../component-status'; import { convertToBoolProperty, NbBooleanInput } from '../helpers'; import { NbChatFormComponent } from './chat-form.component'; import { NbChatMessageComponent } from './chat-message.component'; -import { NbCustomMessageService } from './custom-message.service'; +import { NbChatCustomMessageService } from './chat-custom-message.service'; /** * Conversational UI collection - a set of components for chat-like UI construction. @@ -248,12 +248,9 @@ import { NbCustomMessageService } from './custom-message.service';
`, - providers: [ - NbCustomMessageService, - ], + providers: [NbChatCustomMessageService], }) export class NbChatComponent implements OnChanges, AfterContentInit, AfterViewInit { - @Input() title: string; /** @@ -275,7 +272,7 @@ export class NbChatComponent implements OnChanges, AfterContentInit, AfterViewIn */ @Input() get scrollBottom(): boolean { - return this._scrollBottom + return this._scrollBottom; } set scrollBottom(value: boolean) { this._scrollBottom = convertToBoolProperty(value); @@ -287,8 +284,7 @@ export class NbChatComponent implements OnChanges, AfterContentInit, AfterViewIn @ContentChildren(NbChatMessageComponent) messages: QueryList; @ContentChild(NbChatFormComponent) chatForm: NbChatFormComponent; - constructor(protected statusService: NbStatusService) { - } + constructor(protected statusService: NbStatusService) {} ngOnChanges(changes: SimpleChanges) { if ('status' in changes) { @@ -301,11 +297,10 @@ export class NbChatComponent implements OnChanges, AfterContentInit, AfterViewIn } ngAfterViewInit() { - this.messages.changes - .subscribe((messages) => { - this.messages = messages; - this.updateView(); - }); + this.messages.changes.subscribe((messages) => { + this.messages = messages; + this.updateView(); + }); this.updateView(); } diff --git a/src/framework/theme/components/datepicker/datepicker-adapter.spec.ts b/src/framework/theme/components/datepicker/datepicker-adapter.spec.ts index a1b44f4eb1..6e5d296669 100644 --- a/src/framework/theme/components/datepicker/datepicker-adapter.spec.ts +++ b/src/framework/theme/components/datepicker/datepicker-adapter.spec.ts @@ -1,7 +1,11 @@ import { TestBed } from '@angular/core/testing'; -import { NbCalendarRange, NbDateService, NbDateTimeAdapterService } from '@nebular/theme'; - -import { NbDateAdapterService, NbRangeAdapterService } from './datepicker-adapter'; +import { + NbCalendarRange, + NbDateService, + NbDateTimeAdapterService, + NbDateAdapterService, + NbRangeAdapterService, +} from '@nebular/theme'; describe('Date Adapters', () => { beforeEach(() => { @@ -95,8 +99,8 @@ describe('Date Adapters', () => { expect(actualStart).toEqual(expectedStart); expect(actualEnd).toEqual(expectedEnd); expect(spy).toHaveBeenCalledTimes(2); - expect(spy.calls.argsFor(0)).toEqual([ startDate, format ]); - expect(spy.calls.argsFor(1)).toEqual([ endDate, format ]); + expect(spy.calls.argsFor(0)).toEqual([startDate, format]); + expect(spy.calls.argsFor(1)).toEqual([endDate, format]); }); it('should format valid date range', () => { @@ -108,7 +112,7 @@ describe('Date Adapters', () => { expect(spy).toHaveBeenCalledTimes(2); }); - it('should not format if range isn\'t passed', () => { + it("should not format if range isn't passed", () => { const spy = spyOn(dateService, 'isValidDateString').and.returnValues(false, false); expect(adapterService.format(null, '')).toEqual(''); @@ -136,7 +140,7 @@ describe('Date Adapters', () => { const endDate = '12/11/11'; const date = `${startDate}-${endDate}`; const format = 'mm/dd/yy'; - const results = [ true, false, true, true ]; + const results = [true, false, true, true]; const spy = spyOn(dateService, 'isValidDateString').and.returnValues(...results); for (let i = 0, callsCount = 0; i < results.length - 1; i += 2) { @@ -144,8 +148,8 @@ describe('Date Adapters', () => { callsCount += 2; expect(spy).toHaveBeenCalledTimes(callsCount); - expect(spy.calls.argsFor(i)).toEqual([ startDate, format ]); - expect(spy.calls.argsFor(i + 1)).toEqual([ endDate, format ]); + expect(spy.calls.argsFor(i)).toEqual([startDate, format]); + expect(spy.calls.argsFor(i + 1)).toEqual([endDate, format]); } }); }); @@ -185,4 +189,3 @@ describe('Date Adapters', () => { }); }); }); - diff --git a/src/framework/theme/components/dialog/dialog.service.spec.ts b/src/framework/theme/components/dialog/dialog.service.spec.ts index 9eae8e1d96..2d3beb5633 100644 --- a/src/framework/theme/components/dialog/dialog.service.spec.ts +++ b/src/framework/theme/components/dialog/dialog.service.spec.ts @@ -1,32 +1,34 @@ import { Component, NgModule, Injectable } from '@angular/core'; import { fakeAsync, TestBed, tick } from '@angular/core/testing'; -import { NbOverlayContainerAdapter } from '../cdk/adapter/overlay-container-adapter'; -import { NbViewportRulerAdapter } from '../cdk/adapter/viewport-ruler-adapter'; -import { NbOverlayService } from '../cdk/overlay/overlay-service'; -import { NbDialogService } from './dialog.service'; -import { NbDialogModule } from './dialog.module'; -import { NbThemeModule } from '../../theme.module'; -import { NB_DOCUMENT } from '../../theme.options'; +import { + NbOverlayContainerAdapter, + NbViewportRulerAdapter, + NbOverlayService, + NbDialogService, + NbDialogModule, + NbThemeModule, + NB_DOCUMENT, +} from '@nebular/theme'; @Injectable() export class NbViewportRulerMockAdapter extends NbViewportRulerAdapter { - getViewportSize(): Readonly<{ width: number; height: number; }> { + getViewportSize(): Readonly<{ width: number; height: number }> { return { width: 1600, height: 900 }; } + getViewportScrollPosition(): { left: number; top: number } { + return { left: 0, top: 0 }; + } } @Component({ selector: 'nb-test-dialog', template: '' }) -class NbTestDialogComponent { -} +class NbTestDialogComponent {} @NgModule({ declarations: [NbTestDialogComponent], entryComponents: [NbTestDialogComponent], }) -class NbTestDialogModule { -} - +class NbTestDialogModule {} describe('dialog-service', () => { let dialog: NbDialogService; @@ -39,11 +41,7 @@ describe('dialog-service', () => { beforeEach(() => { TestBed.configureTestingModule({ - imports: [ - NbTestDialogModule, - NbThemeModule.forRoot(), - NbDialogModule.forRoot(), - ], + imports: [NbTestDialogModule, NbThemeModule.forRoot(), NbDialogModule.forRoot()], providers: [{ provide: NbViewportRulerAdapter, useClass: NbViewportRulerMockAdapter }], }); @@ -83,7 +81,6 @@ describe('dialog-service', () => { expect(overlayContainer.querySelector('.nb-overlay-test-dialog-class')).toBeTruthy(); }); - it('should render with backdrop if hasBackdrop is true', () => { dialog.open(NbTestDialogComponent, { hasBackdrop: true }); expect(queryBackdrop()).toBeTruthy(); @@ -114,11 +111,11 @@ describe('dialog-service', () => { expect(blockSpy).toHaveBeenCalledTimes(1); }); - it('should fire onBackdropClick if backdrop was clicked', done => { + it('should fire onBackdropClick if backdrop was clicked', (done) => { const ref = dialog.open(NbTestDialogComponent, { closeOnBackdropClick: false }); const backdrop = queryBackdrop(); - ref.onBackdropClick.subscribe(e => { + ref.onBackdropClick.subscribe((e) => { expect(e.target).toBe(backdrop); done(); }); @@ -126,7 +123,7 @@ describe('dialog-service', () => { backdrop.dispatchEvent(new Event('click')); }); - it('should not fire onBackdropClick if backdrop wasn\'t clicked', () => { + it("should not fire onBackdropClick if backdrop wasn't clicked", () => { const ref = dialog.open(NbTestDialogComponent, { closeOnBackdropClick: false }); const spy = jasmine.createSpy(); ref.onBackdropClick.subscribe(spy); @@ -149,16 +146,15 @@ describe('dialog-service', () => { it('should close on escape press if closeOnEsc is true', fakeAsync(() => { dialog.open(NbTestDialogComponent, { closeOnEsc: true }); - document.dispatchEvent(new KeyboardEvent('keyup', { keyCode: 27 })); + document.dispatchEvent(new KeyboardEvent('keyup', { keyCode: 27 })); tick(500); expect(queryBackdrop()).toBeFalsy(); })); it('should not close on escape press if closeOnEsc is false', fakeAsync(() => { dialog.open(NbTestDialogComponent, { closeOnEsc: false }); - document.dispatchEvent(new KeyboardEvent('keyup', { keyCode: 27 })); + document.dispatchEvent(new KeyboardEvent('keyup', { keyCode: 27 })); tick(500); expect(queryBackdrop()).toBeTruthy(); })); }); - diff --git a/src/framework/theme/components/icon/icons-libraries.spec.ts b/src/framework/theme/components/icon/icons-libraries.spec.ts index 09444b7120..aca5616a5f 100644 --- a/src/framework/theme/components/icon/icons-libraries.spec.ts +++ b/src/framework/theme/components/icon/icons-libraries.spec.ts @@ -1,8 +1,5 @@ import { TestBed } from '@angular/core/testing'; - -import { NbIconLibraries } from './icon-libraries'; -import { NbSvgIcon } from './icon'; - +import { NbIconLibraries, NbSvgIcon } from '@nebular/theme'; describe('icons-library', () => { let iconsLibrary: NbIconLibraries; @@ -10,16 +7,13 @@ describe('icons-library', () => { beforeEach(() => { TestBed.resetTestingModule(); const bed = TestBed.configureTestingModule({ - providers: [ - NbIconLibraries, - ], + providers: [NbIconLibraries], }); iconsLibrary = bed.inject(NbIconLibraries); }); it('should register raw svg icon', () => { - - iconsLibrary.registerSvgPack('super-pack', { home: '', gear: '' }); + iconsLibrary.registerSvgPack('super-pack', { home: '', gear: '' }); iconsLibrary.setDefaultPack('super-pack'); const icon = iconsLibrary.getSvgIcon('home'); @@ -31,7 +25,6 @@ describe('icons-library', () => { }); it('should register NbSvgIcon svg icon', () => { - iconsLibrary.registerSvgPack('super-pack', { home: new NbSvgIcon('home', '', { packClass: 'sp' }), }); @@ -47,10 +40,9 @@ describe('icons-library', () => { }); it('should register custom svg icon', () => { - class CustomSvgIcon extends NbSvgIcon { getContent() { - return 'custom'; + return 'custom'; } } @@ -69,11 +61,9 @@ describe('icons-library', () => { }); it('should return null for unknown svg icon', () => { - - iconsLibrary.registerSvgPack('super-pack', { home: '', gear: '' }); + iconsLibrary.registerSvgPack('super-pack', { home: '', gear: '' }); iconsLibrary.setDefaultPack('super-pack'); - expect(iconsLibrary.getSvgIcon('unknown')).toBeNull(); }); @@ -82,19 +72,17 @@ describe('icons-library', () => { }); it('should throw for wrong pack type', () => { - - iconsLibrary.registerSvgPack('super-pack', { home: '', gear: '' }); + iconsLibrary.registerSvgPack('super-pack', { home: '', gear: '' }); iconsLibrary.registerFontPack('font-pack'); iconsLibrary.setDefaultPack('font-pack'); - - expect(() => iconsLibrary.getSvgIcon('unknown')) - .toThrowError(`Pack 'font-pack' is not an 'SVG' Pack and its type is 'font'`); + expect(() => iconsLibrary.getSvgIcon('unknown')).toThrowError( + `Pack 'font-pack' is not an 'SVG' Pack and its type is 'font'`, + ); }); it('should return null for wrong pack', () => { - - iconsLibrary.registerSvgPack('super-pack', { home: '', gear: '' }); + iconsLibrary.registerSvgPack('super-pack', { home: '', gear: '' }); iconsLibrary.registerFontPack('font-pack'); iconsLibrary.setDefaultPack('super-pack'); @@ -102,15 +90,12 @@ describe('icons-library', () => { }); it('should throw for wrong pack when setting default', () => { - iconsLibrary.registerFontPack('font-pack'); - expect(() => iconsLibrary.setDefaultPack('super-pack')) - .toThrowError(`Icon Pack 'super-pack' is not registered`); + expect(() => iconsLibrary.setDefaultPack('super-pack')).toThrowError(`Icon Pack 'super-pack' is not registered`); }); it('should register font icon', () => { - iconsLibrary.registerFontPack('font-pack', { packClass: 'font', iconClassPrefix: 'fp' }); iconsLibrary.setDefaultPack('font-pack'); @@ -123,10 +108,8 @@ describe('icons-library', () => { expect(icon.type).toEqual('font'); }); - it('should return icon', () => { - - iconsLibrary.registerSvgPack('super-pack', { home: '', gear: '' }); + iconsLibrary.registerSvgPack('super-pack', { home: '', gear: '' }); iconsLibrary.registerFontPack('font-pack', { packClass: 'font', iconClassPrefix: 'fp' }); iconsLibrary.setDefaultPack('font-pack'); @@ -145,5 +128,4 @@ describe('icons-library', () => { expect(svgIcon.pack).toEqual('super-pack'); expect(svgIcon.type).toEqual('svg'); }); - }); diff --git a/src/framework/theme/components/input/input.spec.ts b/src/framework/theme/components/input/input.spec.ts index 16ed0df52d..f0e2aa4ab4 100644 --- a/src/framework/theme/components/input/input.spec.ts +++ b/src/framework/theme/components/input/input.spec.ts @@ -4,18 +4,15 @@ * Licensed under the MIT License. See License.txt in the project root for license information. */ -import { Component, Input } from '@angular/core' +import { Component, Input } from '@angular/core'; import { ComponentFixture, TestBed } from '@angular/core/testing'; import { NbInputDirective, NbThemeModule } from '@nebular/theme'; import { By } from '@angular/platform-browser'; -import { NbComponentStatus } from '../component-status'; -import { NbComponentSize } from '../component-size'; -import { NbComponentShape } from '../component-shape'; -import { NbInputModule } from './input.module'; +import { NbComponentStatus, NbComponentSize, NbComponentShape, NbInputModule } from '@nebular/theme'; @Component({ template: ` - + `, @@ -28,7 +25,6 @@ class InputTestComponent { } describe('Directive: NbInput', () => { - let inputTestComponent: InputTestComponent; let fixture: ComponentFixture; let inputElement: Element; @@ -36,12 +32,10 @@ describe('Directive: NbInput', () => { let inputDirective: NbInputDirective; beforeEach(() => { - fixture = TestBed.configureTestingModule({ - imports: [ NbThemeModule.forRoot(), NbInputModule ], - declarations: [ InputTestComponent ], - }) - .createComponent(InputTestComponent); + imports: [NbThemeModule.forRoot(), NbInputModule], + declarations: [InputTestComponent], + }).createComponent(InputTestComponent); inputTestComponent = fixture.componentInstance; @@ -81,5 +75,4 @@ describe('Directive: NbInput', () => { expect(inputElement.classList).toContain('input-full-width'); expect(textareaElement.classList).toContain('input-full-width'); }); - }); diff --git a/src/framework/theme/components/layout/restore-scroll-top.service.spec.ts b/src/framework/theme/components/layout/restore-scroll-top.service.spec.ts index 6c0b096aff..86530d1d1b 100644 --- a/src/framework/theme/components/layout/restore-scroll-top.service.spec.ts +++ b/src/framework/theme/components/layout/restore-scroll-top.service.spec.ts @@ -2,63 +2,60 @@ import { ComponentFixture, fakeAsync, inject, TestBed, tick, waitForAsync } from import { RouterTestingModule } from '@angular/router/testing'; import { Component } from '@angular/core'; import { Router } from '@angular/router'; -import { NbRestoreScrollTopHelper } from './restore-scroll-top.service'; +import { NbRestoreScrollTopHelper } from '@nebular/theme'; let restoreHelper: NbRestoreScrollTopHelper; let router: Router; let fixture: ComponentFixture; -@Component({template: ''}) -class TestBootstrapComponent { -} +@Component({ template: '' }) +class TestBootstrapComponent {} -@Component({template: ''}) -class TestComponent { -} +@Component({ template: '' }) +class TestComponent {} describe('NbRestoreScrollTopHelper', () => { - beforeEach(() => { - TestBed.resetTestingModule(); fixture = TestBed.configureTestingModule({ - imports: [RouterTestingModule.withRoutes([ - { - path: '', - children: [ - { - path: '', - component: TestComponent, - }, - { - path: 'about', - component: TestComponent, - }, - ], - }, - { - path: '**', - redirectTo: '', - pathMatch: 'full', - }, - ]), + imports: [ + RouterTestingModule.withRoutes([ + { + path: '', + children: [ + { + path: '', + component: TestComponent, + }, + { + path: 'about', + component: TestComponent, + }, + ], + }, + { + path: '**', + redirectTo: '', + pathMatch: 'full', + }, + ]), ], providers: [NbRestoreScrollTopHelper], declarations: [TestComponent, TestBootstrapComponent], - }) - .createComponent(TestBootstrapComponent); + }).createComponent(TestBootstrapComponent); fixture.detectChanges(); }); - beforeEach(waitForAsync(inject( - [NbRestoreScrollTopHelper, Router], - (_restoreHelper, _router) => { - restoreHelper = _restoreHelper; - router = _router; - }, - ))); + beforeEach( + waitForAsync( + inject([NbRestoreScrollTopHelper, Router], (_restoreHelper, _router) => { + restoreHelper = _restoreHelper; + router = _router; + }), + ), + ); afterEach(fakeAsync(() => { fixture.destroy(); @@ -67,14 +64,12 @@ describe('NbRestoreScrollTopHelper', () => { })); it('should trigger when url is changed', (done) => { - const spy = jasmine.createSpy('scrolltop subscriber'); - restoreHelper.shouldRestore() - .subscribe(spy); + restoreHelper.shouldRestore().subscribe(spy); router.navigate(['/']); - setTimeout(_ => router.navigate(['about'])); - setTimeout(_ => router.navigate(['/'])); + setTimeout((_) => router.navigate(['about'])); + setTimeout((_) => router.navigate(['/'])); setTimeout(() => { expect(spy).toHaveBeenCalledTimes(3); @@ -83,13 +78,11 @@ describe('NbRestoreScrollTopHelper', () => { }); it('should not trigger when url query param is changed', (done) => { - const spy = jasmine.createSpy('scrolltop subscriber'); - restoreHelper.shouldRestore() - .subscribe(spy); + restoreHelper.shouldRestore().subscribe(spy); router.navigate(['/']); - setTimeout(_ => router.navigate(['/'], { queryParams: { test: 1 } })); + setTimeout((_) => router.navigate(['/'], { queryParams: { test: 1 } })); setTimeout(() => { expect(spy).toHaveBeenCalledTimes(1); @@ -98,13 +91,11 @@ describe('NbRestoreScrollTopHelper', () => { }); it('should not trigger when url fragment is changed', (done) => { - const spy = jasmine.createSpy('scrolltop subscriber'); - restoreHelper.shouldRestore() - .subscribe(spy); + restoreHelper.shouldRestore().subscribe(spy); router.navigate(['/']); - setTimeout(_ => router.navigate(['/'], { fragment: 'some' })); + setTimeout((_) => router.navigate(['/'], { fragment: 'some' })); setTimeout(() => { expect(spy).toHaveBeenCalledTimes(1); @@ -113,13 +104,11 @@ describe('NbRestoreScrollTopHelper', () => { }); it('should not trigger when url query param & fragment are changed', (done) => { - const spy = jasmine.createSpy('scrolltop subscriber'); - restoreHelper.shouldRestore() - .subscribe(spy); + restoreHelper.shouldRestore().subscribe(spy); router.navigate(['/']); - setTimeout(_ => router.navigate(['/'], { fragment: 'some', queryParams: { test: 1 } })); + setTimeout((_) => router.navigate(['/'], { fragment: 'some', queryParams: { test: 1 } })); setTimeout(() => { expect(spy).toHaveBeenCalledTimes(1); diff --git a/src/framework/theme/components/list/infinite-list.directive.spec.ts b/src/framework/theme/components/list/infinite-list.directive.spec.ts index 8564678400..54121e4b31 100644 --- a/src/framework/theme/components/list/infinite-list.directive.spec.ts +++ b/src/framework/theme/components/list/infinite-list.directive.spec.ts @@ -3,13 +3,15 @@ import { APP_BASE_HREF } from '@angular/common'; import { RouterModule } from '@angular/router'; import { By } from '@angular/platform-browser'; import { TestBed, ComponentFixture, fakeAsync, tick } from '@angular/core/testing'; -import { NbThemeModule } from '../../theme.module'; -import { NbLayoutModule } from '../layout/layout.module'; -import { NbLayoutComponent } from '../layout/layout.component'; -import { NbLayoutScrollService } from '../../services/scroll.service'; -import { NbListModule } from './list.module'; -import { NbListComponent } from './list.component'; -import { NbInfiniteListDirective } from './infinite-list.directive'; +import { + NbThemeModule, + NbLayoutModule, + NbLayoutComponent, + NbLayoutScrollService, + NbListModule, + NbListComponent, + NbInfiniteListDirective, +} from '@nebular/theme'; const CONTENT_PADDING = 20; const CONTENT_HEIGHT = 10000 + CONTENT_PADDING; @@ -34,30 +36,33 @@ let infiniteListDirective: NbInfiniteListDirective; [threshold]="threshold" [listenWindowScroll]="listenWindowScroll" (bottomThreshold)="bottomThreshold()" - (topThreshold)="topThreshold()"> + (topThreshold)="topThreshold()" + > `, - styles: [` - ::ng-deep nb-layout.with-scroll .scrollable-container { - overflow: auto; - height: 100vh; - } - .scroller { - background: lightgray; - padding: ${CONTENT_PADDING}px; - } - .element-scroll { - height: ${ELEMENT_HEIGHT}px; - overflow-y: auto; - } - .inner { - background: lightgoldenrodyellow; - height: ${CONTENT_HEIGHT}px; - } - `], + styles: [ + ` + ::ng-deep nb-layout.with-scroll .scrollable-container { + overflow: auto; + height: 100vh; + } + .scroller { + background: lightgray; + padding: ${CONTENT_PADDING}px; + } + .element-scroll { + height: ${ELEMENT_HEIGHT}px; + overflow-y: auto; + } + .inner { + background: lightgoldenrodyellow; + height: ${CONTENT_HEIGHT}px; + } + `, + ], }) class ScrollTestComponent { listenWindowScroll = false; @@ -69,23 +74,20 @@ class ScrollTestComponent { } describe('Directive: NbScrollDirective', () => { - beforeEach(() => { fixture = TestBed.configureTestingModule({ - imports: [ - RouterModule.forRoot([], { relativeLinkResolution: 'legacy' }), - NbThemeModule.forRoot(), - NbLayoutModule, - NbListModule, - ], - providers: [ NbLayoutScrollService, { provide: APP_BASE_HREF, useValue: '/' } ], - declarations: [ ScrollTestComponent ], - }) - .createComponent(ScrollTestComponent); + imports: [ + RouterModule.forRoot([], { relativeLinkResolution: 'legacy' }), + NbThemeModule.forRoot(), + NbLayoutModule, + NbListModule, + ], + providers: [NbLayoutScrollService, { provide: APP_BASE_HREF, useValue: '/' }], + declarations: [ScrollTestComponent], + }).createComponent(ScrollTestComponent); fixture.detectChanges(); - listElementRef = fixture.debugElement.query(By.directive(NbListComponent)); layoutComponent = fixture.debugElement.query(By.directive(NbLayoutComponent)).componentInstance; infiniteListDirective = listElementRef.injector.get(NbInfiniteListDirective); @@ -171,7 +173,7 @@ describe('Directive: NbScrollDirective', () => { tick(); expect(tresholdSpy).toHaveBeenCalledTimes(0); - const positionBelowThreshold = CONTENT_HEIGHT - (THRESHOLD / 2); + const positionBelowThreshold = CONTENT_HEIGHT - THRESHOLD / 2; scrollingNativeElement.scrollTop = positionBelowThreshold; scrollingNativeElement.dispatchEvent(new Event('scroll')); tick(); @@ -193,7 +195,7 @@ describe('Directive: NbScrollDirective', () => { tick(); expect(tresholdSpy).toHaveBeenCalledTimes(0); - const positionBelowThreshold = CONTENT_HEIGHT - (THRESHOLD / 2); + const positionBelowThreshold = CONTENT_HEIGHT - THRESHOLD / 2; documentElement.scrollTop = positionBelowThreshold; window.dispatchEvent(new Event('scroll')); tick(); diff --git a/src/framework/theme/components/list/list-pager.directive.spec.ts b/src/framework/theme/components/list/list-pager.directive.spec.ts index 4798fdcfb8..e228a4dd9b 100644 --- a/src/framework/theme/components/list/list-pager.directive.spec.ts +++ b/src/framework/theme/components/list/list-pager.directive.spec.ts @@ -1,7 +1,6 @@ import { Component, ViewChild, ElementRef } from '@angular/core'; import { TestBed, ComponentFixture, fakeAsync, tick, ComponentFixtureAutoDetect } from '@angular/core/testing'; -import { NbListModule } from './list.module'; -import { NbListComponent } from './list.component'; +import { NbListModule, NbListComponent } from '@nebular/theme'; function waitForSpyCall(spy: jasmine.Spy, checkInterval: number = 40, timeout: number = 1000): Promise { const initialCallsCount = spy.calls.count(); @@ -36,23 +35,26 @@ let initialItemsCount: number = 100; [pageSize]="pageSize" [startPage]="startPage" (pageChange)="pageChanged($event)" - class="list"> + class="list" + > `, - styles: [` - .list { - background: lightslategray; - height: ${LIST_HEIGHT}px; - padding: 0 5px; - overflow: auto; - } - .list-item { - background: lightblue; - border: ${ITEM_HEIGHT * 0.01}px solid black; - height: ${ITEM_HEIGHT * 0.98}px; - } - `], + styles: [ + ` + .list { + background: lightslategray; + height: ${LIST_HEIGHT}px; + padding: 0 5px; + overflow: auto; + } + .list-item { + background: lightblue; + border: ${ITEM_HEIGHT * 0.01}px solid black; + height: ${ITEM_HEIGHT * 0.98}px; + } + `, + ], }) class PagerTestComponent { @ViewChild(NbListComponent, { read: ElementRef }) listElementRef: ElementRef; @@ -73,21 +75,19 @@ let testComponent: PagerTestComponent; let pageChangedSpy: jasmine.Spy; describe('Directive: NbListPageTrackerDirective', () => { - let initialTimeoutInterval; beforeAll(() => { initialTimeoutInterval = jasmine.DEFAULT_TIMEOUT_INTERVAL; jasmine.DEFAULT_TIMEOUT_INTERVAL = 5000; }); - afterAll(() => jasmine.DEFAULT_TIMEOUT_INTERVAL = initialTimeoutInterval); + afterAll(() => (jasmine.DEFAULT_TIMEOUT_INTERVAL = initialTimeoutInterval)); beforeEach(() => { fixture = TestBed.configureTestingModule({ - imports: [ NbListModule ], - declarations: [ PagerTestComponent ], - providers: [ { provide: ComponentFixtureAutoDetect, useValue: true } ], - }) - .createComponent(PagerTestComponent); + imports: [NbListModule], + declarations: [PagerTestComponent], + providers: [{ provide: ComponentFixtureAutoDetect, useValue: true }], + }).createComponent(PagerTestComponent); testComponent = fixture.componentInstance; fixture.detectChanges(); @@ -102,7 +102,6 @@ describe('Directive: NbListPageTrackerDirective', () => { })); describe('initial page', () => { - it('should emit initial page change when list was prefilled', async () => { try { await waitForSpyCall(pageChangedSpy); @@ -115,13 +114,12 @@ describe('Directive: NbListPageTrackerDirective', () => { }); describe('empty list', () => { - let initialItemsCountBefore; beforeAll(() => { initialItemsCountBefore = initialItemsCount; initialItemsCount = 0; }); - afterAll(() => initialItemsCount = initialItemsCountBefore); + afterAll(() => (initialItemsCount = initialItemsCountBefore)); it('should not emit initial page change when list is empty', async () => { try { @@ -148,13 +146,12 @@ describe('Directive: NbListPageTrackerDirective', () => { }); describe('start page', () => { - let initialItemsCountBefore; beforeAll(() => { initialItemsCountBefore = initialItemsCount; initialItemsCount = 0; }); - afterAll(() => initialItemsCount = initialItemsCountBefore); + afterAll(() => (initialItemsCount = initialItemsCountBefore)); it('should take into account start page when calculating current page', async () => { const startPage = 5; @@ -171,7 +168,7 @@ describe('Directive: NbListPageTrackerDirective', () => { expect(pageChangedSpy).toHaveBeenCalledTimes(1); expect(pageChangedSpy).toHaveBeenCalledWith(startPage); - const numberOfPagesToScroll = [ 1, 5 ]; + const numberOfPagesToScroll = [1, 5]; let timesPageShouldBeChanged = 1; for (const nPagesToScroll of numberOfPagesToScroll) { listElement.scrollTop = PAGE_HEIGHT * nPagesToScroll; @@ -189,7 +186,6 @@ describe('Directive: NbListPageTrackerDirective', () => { }); describe(`page change`, () => { - beforeEach(async () => { try { await waitForSpyCall(pageChangedSpy); @@ -207,7 +203,9 @@ describe('Directive: NbListPageTrackerDirective', () => { listElement.scrollTop = positionBeforePageTwo; try { await waitForSpyCall(pageChangedSpy); - } catch { /* Expecting to throw because 'pageChanged' shouldn't be called since page wasn't changed. */ } + } catch { + /* Expecting to throw because 'pageChanged' shouldn't be called since page wasn't changed. */ + } expect(pageChangedSpy).not.toHaveBeenCalled(); }); @@ -218,7 +216,7 @@ describe('Directive: NbListPageTrackerDirective', () => { const startPage = 1; let timesPageShouldBeChanged = 0; const lastPage = initialItemsCount / ITEMS_PER_PAGE - 1; - const numbersOfPagesToScroll = [ 1, 2, lastPage, 0 ]; + const numbersOfPagesToScroll = [1, 2, lastPage, 0]; for (const pagesToScroll of numbersOfPagesToScroll) { listElement.scrollTop = PAGE_HEIGHT * pagesToScroll; diff --git a/src/framework/theme/components/menu/menu.spec.ts b/src/framework/theme/components/menu/menu.spec.ts index 2aedf35c29..38e1d7c32b 100644 --- a/src/framework/theme/components/menu/menu.spec.ts +++ b/src/framework/theme/components/menu/menu.spec.ts @@ -11,6 +11,7 @@ import { ViewChild, ViewChildren, Injectable, + ProviderToken, } from '@angular/core'; import { Location } from '@angular/common'; import { Router, Routes } from '@angular/router'; @@ -18,9 +19,8 @@ import { RouterTestingModule } from '@angular/router/testing'; import { By } from '@angular/platform-browser'; import { NoopAnimationsModule } from '@angular/platform-browser/animations'; import { TestBed } from '@angular/core/testing'; -import { NbMenuModule } from './menu.module'; -import { NbMenuBag, NbMenuInternalService, NbMenuItem, NbMenuService } from './menu.service'; -import { NbThemeModule } from '../../theme.module'; +import { SpyLocation } from '@angular/common/testing'; +import { pairwise, take } from 'rxjs/operators'; import { getFragmentPartOfUrl, isFragmentContain, @@ -29,15 +29,19 @@ import { isUrlPathEqual, getPathPartOfUrl, } from './url-matching-helpers'; -import { pairwise, take } from 'rxjs/operators'; -import { NbMenuComponent } from './menu.component'; import { NbIconComponent, NbIconLibraries, NbLayoutDirection, NbLayoutDirectionService, + NbMenuModule, + NbMenuBag, + NbMenuItem, + NbMenuService, + NbMenuComponent, + NbThemeModule, } from '@nebular/theme'; -import { SpyLocation } from '@angular/common/testing'; +import { NbMenuInternalService } from './menu.service'; @Component({ template: '' }) export class NoopComponent {} @@ -46,7 +50,7 @@ export class NoopComponent {} template: ``, }) export class SingleMenuTestComponent { - constructor (public menuPublicService: NbMenuService) {} + constructor(public menuPublicService: NbMenuService) {} @Input() items: NbMenuItem[]; @Input() menuTag: string; @ViewChild(NbMenuComponent) menuComponent: NbMenuComponent; @@ -59,7 +63,7 @@ export class SingleMenuTestComponent { `, }) export class DoubleMenusTestComponent { - constructor (public menuPublicService: NbMenuService) {} + constructor(public menuPublicService: NbMenuService) {} @Input() firstMenuItems: NbMenuItem[]; @Input() secondMenuItems: NbMenuItem[]; @Input() firstMenuTag: string; @@ -67,7 +71,6 @@ export class DoubleMenusTestComponent { @ViewChildren(NbMenuComponent) menuComponent: QueryList; } - // Overrides SpyLocation path method to take into account `includeHash` parameter. // Original SpyLocation ignores parameters and always returns path with hash which is different // from Location. @@ -100,12 +103,12 @@ function createTestBed(routes: Routes = []) { const iconLibs: NbIconLibraries = TestBed.inject(NbIconLibraries); iconLibs.registerSvgPack('test', { 'some-icon': 'some-icon' }); - iconLibs.setDefaultPack('test') + iconLibs.setDefaultPack('test'); } function createSingleMenuComponent(menuItems, menuTag = 'menu') { createTestBed(); - const fixture = TestBed.createComponent( SingleMenuTestComponent ); + const fixture = TestBed.createComponent(SingleMenuTestComponent); fixture.componentInstance.items = menuItems; fixture.componentInstance.menuTag = menuTag; const menuService = fixture.componentInstance.menuPublicService; @@ -113,9 +116,9 @@ function createSingleMenuComponent(menuItems, menuTag = 'menu') { return { fixture, menuService }; } -function createDoubleMenuComponent( firstMenuItems, firstMenuTag, secondMenuItems, secondMenuTag ) { +function createDoubleMenuComponent(firstMenuItems, firstMenuTag, secondMenuItems, secondMenuTag) { createTestBed(); - const fixture = TestBed.createComponent( DoubleMenusTestComponent ); + const fixture = TestBed.createComponent(DoubleMenusTestComponent); fixture.componentInstance.firstMenuItems = firstMenuItems; fixture.componentInstance.secondMenuItems = secondMenuItems; fixture.componentInstance.firstMenuTag = firstMenuTag; @@ -131,7 +134,6 @@ function createMenuItems(items: Partial[], menuInternaleService: NbM } describe('NbMenuItem', () => { - it('should set tag attribute for menu services', () => { const { fixture } = createSingleMenuComponent([{ title: 'Home' }], 'menu'); const nbMenuTag = fixture.componentInstance.menuComponent.tag; @@ -193,7 +195,7 @@ describe('NbMenuItem', () => { it('should expand child menu items', () => { const { fixture } = createSingleMenuComponent([ - { title: 'Parent item', expanded: true, children: [{ title: 'Child item' }] }, + { title: 'Parent item', expanded: true, children: [{ title: 'Child item' }] }, ]); const childList = fixture.nativeElement.querySelector('.menu-item > ul.menu-items'); expect(childList.classList).toContain('expanded'); @@ -207,9 +209,7 @@ describe('NbMenuItem', () => { it('should set selected item', () => { const selectedItem = { title: 'Menu item selected', selected: true }; - const { fixture } = createSingleMenuComponent([ - { title: 'Menu item not selected' }, selectedItem, - ]); + const { fixture } = createSingleMenuComponent([{ title: 'Menu item not selected' }, selectedItem]); const activeItem = fixture.nativeElement.querySelector('a.active'); expect(activeItem.querySelector('span').innerHTML).toEqual(selectedItem.title); }); @@ -227,36 +227,31 @@ describe('NbMenuItem', () => { expect(iconComponent.componentInstance.icon).toEqual('chevron-right-outline'); }); - }); describe('menu services', () => { - it('should operate with menu by tag', () => { const { fixture, menuService } = createDoubleMenuComponent( - [{ title: 'Home'}], + [{ title: 'Home' }], 'menuFirst', - [{ title: 'Home'}], - 'menuSecond' ); + [{ title: 'Home' }], + 'menuSecond', + ); const itemToAdd = { title: 'Added item' }; const initialFirstMenuItemsCount = fixture.nativeElement .querySelector('nb-menu:first-child') - .querySelectorAll('.menu-item') - .length; + .querySelectorAll('.menu-item').length; const initialSecondMenuItemsCount = fixture.nativeElement .querySelector('nb-menu:last-child') - .querySelectorAll('.menu-item') - .length; + .querySelectorAll('.menu-item').length; menuService.addItems([itemToAdd], 'menuFirst'); fixture.detectChanges(); const afterAddFirstMenuItemsCount = fixture.nativeElement .querySelector('nb-menu:first-child') - .querySelectorAll('.menu-item') - .length; + .querySelectorAll('.menu-item').length; const afterAddSecondMenuItemsCount = fixture.nativeElement .querySelector('nb-menu:last-child') - .querySelectorAll('.menu-item') - .length; + .querySelectorAll('.menu-item').length; expect(afterAddFirstMenuItemsCount).toEqual(initialFirstMenuItemsCount + 1); expect(afterAddSecondMenuItemsCount).toEqual(initialSecondMenuItemsCount); }); @@ -273,8 +268,9 @@ describe('menu services', () => { it('should get selected menu item', (done) => { const selectedItem = { title: 'Menu item selected', selected: true }; - const { menuService } = createSingleMenuComponent([{ title: 'Menu item not selected' }, selectedItem ]); - menuService.getSelectedItem('menu') + const { menuService } = createSingleMenuComponent([{ title: 'Menu item not selected' }, selectedItem]); + menuService + .getSelectedItem('menu') .pipe(take(1)) .subscribe((menuBag: NbMenuBag) => { expect(menuBag.item.title).toEqual(selectedItem.title); @@ -299,7 +295,8 @@ describe('menu services', () => { children: [{ title: 'Menu item inner' }], }, ]); - menuService.onSubmenuToggle() + menuService + .onSubmenuToggle() .pipe(pairwise(), take(1)) .subscribe(([menuBagFirstCollapsed, menuBagSecondCollapsed]: NbMenuBag[]) => { expect(menuBagFirstCollapsed.item.title).toEqual('Menu item expanded 1'); @@ -309,7 +306,6 @@ describe('menu services', () => { menuService.collapseAll(); fixture.detectChanges(); }, 1000); - }); describe('NbMenuInternalService', () => { @@ -328,11 +324,11 @@ describe('NbMenuInternalService', () => { ]; createTestBed(routes); router = TestBed.inject(Router); - menuInternalService = TestBed.inject(NbMenuInternalService); + const internalServiceToken = NbMenuModule.forRoot().providers[1]; + menuInternalService = TestBed.inject(internalServiceToken as ProviderToken); }); describe('selectFromUrl pathMatch full', () => { - it('should select menu item with matching path', (done) => { const items: Partial[] = [{ link: '/menu-1' }]; const menuItems: NbMenuItem[] = createMenuItems(items, menuInternalService); @@ -340,12 +336,11 @@ describe('NbMenuInternalService', () => { expect(menuItem.selected).toBeFalsy(); - router.navigate([menuItem.link]) - .then(() => { - menuInternalService.selectFromUrl(menuItems, ''); - expect(menuItem.selected).toEqual(true); - done(); - }); + router.navigate([menuItem.link]).then(() => { + menuInternalService.selectFromUrl(menuItems, ''); + expect(menuItem.selected).toEqual(true); + done(); + }); }); it('should select menu item with matching path and fragment', (done) => { @@ -355,19 +350,20 @@ describe('NbMenuInternalService', () => { expect(menuItem.selected).toBeFalsy(); - router.navigate([menuItem.link], { fragment: menuItem.fragment }) - .then(() => { - menuInternalService.selectFromUrl(menuItems, ''); - expect(menuItem.selected).toEqual(true); - done(); - }); + router.navigate([menuItem.link], { fragment: menuItem.fragment }).then(() => { + menuInternalService.selectFromUrl(menuItems, ''); + expect(menuItem.selected).toEqual(true); + done(); + }); }); it('should select child menu item and its parent', (done) => { - const items: Partial[] = [{ - link: '/menu-2', - children: [{ link: '/menu-2/menu-2-level-2' }] as NbMenuItem[], - }]; + const items: Partial[] = [ + { + link: '/menu-2', + children: [{ link: '/menu-2/menu-2-level-2' }] as NbMenuItem[], + }, + ]; const menuItems: NbMenuItem[] = createMenuItems(items, menuInternalService); const parentMenuItem: NbMenuItem = menuItems[0]; const childMenuItem: NbMenuItem = parentMenuItem.children[0]; @@ -375,20 +371,21 @@ describe('NbMenuInternalService', () => { expect(parentMenuItem.selected).toBeFalsy(); expect(childMenuItem.selected).toBeFalsy(); - router.navigate([childMenuItem.link]) - .then(() => { - menuInternalService.selectFromUrl(menuItems, ''); - expect(parentMenuItem.selected).toEqual(true); - expect(childMenuItem.selected).toEqual(true); - done(); - }); + router.navigate([childMenuItem.link]).then(() => { + menuInternalService.selectFromUrl(menuItems, ''); + expect(parentMenuItem.selected).toEqual(true); + expect(childMenuItem.selected).toEqual(true); + done(); + }); }); it('should select child menu item with fragment', (done) => { - const items: Partial[] = [{ - link: '/menu-2', - children: [{ link: '/menu-2/menu-2-level-2', fragment: '22' }] as NbMenuItem[], - }]; + const items: Partial[] = [ + { + link: '/menu-2', + children: [{ link: '/menu-2/menu-2-level-2', fragment: '22' }] as NbMenuItem[], + }, + ]; const menuItems: NbMenuItem[] = createMenuItems(items, menuInternalService); const parentMenuItem: NbMenuItem = menuItems[0]; const childMenuItem: NbMenuItem = parentMenuItem.children[0]; @@ -396,31 +393,29 @@ describe('NbMenuInternalService', () => { expect(parentMenuItem.selected).toBeFalsy(); expect(childMenuItem.selected).toBeFalsy(); - router.navigate([childMenuItem.link], { fragment: childMenuItem.fragment }) - .then(() => { - menuInternalService.selectFromUrl(menuItems, ''); - expect(parentMenuItem.selected).toEqual(true); - expect(childMenuItem.selected).toEqual(true); - done(); - }); + router.navigate([childMenuItem.link], { fragment: childMenuItem.fragment }).then(() => { + menuInternalService.selectFromUrl(menuItems, ''); + expect(parentMenuItem.selected).toEqual(true); + expect(childMenuItem.selected).toEqual(true); + done(); + }); }); - it('should not select menu item with matching path if fragment doesn\'t match', function(done) { + it("should not select menu item with matching path if fragment doesn't match", function (done) { const items: Partial[] = [{ link: '/menu-1', fragment: '1' }]; const menuItems: NbMenuItem[] = createMenuItems(items, menuInternalService); const menuItem: NbMenuItem = menuItems[0]; expect(menuItem.selected).toBeFalsy(); - router.navigate([menuItem.link], { fragment: menuItem.fragment + 'random-fragment' }) - .then(() => { - menuInternalService.selectFromUrl(menuItems, ''); - expect(menuItem.selected).toBeFalsy(); - done(); - }); + router.navigate([menuItem.link], { fragment: menuItem.fragment + 'random-fragment' }).then(() => { + menuInternalService.selectFromUrl(menuItems, ''); + expect(menuItem.selected).toBeFalsy(); + done(); + }); }); - it('should not select menu item with matching fragment if path doesn\'t match', function(done) { + it("should not select menu item with matching fragment if path doesn't match", function (done) { const items: Partial[] = [{ link: '/menu-1', fragment: '1' }]; const menuItems: NbMenuItem[] = createMenuItems(items, menuInternalService); const menuItem: NbMenuItem = menuItems[0]; @@ -428,12 +423,11 @@ describe('NbMenuInternalService', () => { expect(menuItem.selected).toBeFalsy(); const url = menuItem.link + '/2'; - router.navigate([url], { fragment: menuItem.fragment }) - .then(() => { - menuInternalService.selectFromUrl(menuItems, ''); - expect(menuItem.selected).toBeFalsy(); - done(); - }); + router.navigate([url], { fragment: menuItem.fragment }).then(() => { + menuInternalService.selectFromUrl(menuItems, ''); + expect(menuItem.selected).toBeFalsy(); + done(); + }); }); it('should not select menu item with fragment if no fragment in url', (done) => { @@ -443,12 +437,11 @@ describe('NbMenuInternalService', () => { expect(menuItem.selected).toBeFalsy(); - router.navigate([menuItem.link]) - .then(() => { - menuInternalService.selectFromUrl(menuItems, ''); - expect(menuItem.selected).toBeFalsy(); - done(); - }); + router.navigate([menuItem.link]).then(() => { + menuInternalService.selectFromUrl(menuItems, ''); + expect(menuItem.selected).toBeFalsy(); + done(); + }); }); it('should not select menu item if path not matches fully', (done) => { @@ -459,12 +452,11 @@ describe('NbMenuInternalService', () => { expect(menuItem.selected).toBeFalsy(); const url = menuItem.link + '/2'; - router.navigate([url], { fragment: menuItem.fragment }) - .then(() => { - menuInternalService.selectFromUrl(menuItems, ''); - expect(menuItem.selected).toBeFalsy(); - done(); - }); + router.navigate([url], { fragment: menuItem.fragment }).then(() => { + menuInternalService.selectFromUrl(menuItems, ''); + expect(menuItem.selected).toBeFalsy(); + done(); + }); }); it('should not select menu item if path and fragment not matches fully', (done) => { @@ -474,18 +466,16 @@ describe('NbMenuInternalService', () => { expect(menuItem.selected).toBeFalsy(); - router.navigate([menuItem.link], { fragment: menuItem.fragment + '1' }) - .then(() => { - menuInternalService.selectFromUrl(menuItems, ''); - expect(menuItem.selected).toBeFalsy(); - done(); - }); + router.navigate([menuItem.link], { fragment: menuItem.fragment + '1' }).then(() => { + menuInternalService.selectFromUrl(menuItems, ''); + expect(menuItem.selected).toBeFalsy(); + done(); + }); }); }); describe('selectFromUrl pathMatch prefix', () => { - - it('should select menu item if url contains menu link', function(done) { + it('should select menu item if url contains menu link', function (done) { const items: Partial[] = [{ link: '/menu-1', pathMatch: 'prefix' }]; const menuItems: NbMenuItem[] = createMenuItems(items, menuInternalService); const menuItem: NbMenuItem = menuItems[0]; @@ -493,63 +483,58 @@ describe('NbMenuInternalService', () => { expect(menuItem.selected).toBeFalsy(); const url = menuItem.link + '/2'; - router.navigate([url]) - .then(() => { - menuInternalService.selectFromUrl(menuItems, ''); - expect(menuItem.selected).toEqual(true); - done(); - }); + router.navigate([url]).then(() => { + menuInternalService.selectFromUrl(menuItems, ''); + expect(menuItem.selected).toEqual(true); + done(); + }); }); - it('should select menu item if url contains menu link and fragment', function(done) { + it('should select menu item if url contains menu link and fragment', function (done) { const items: Partial[] = [{ link: '/menu-1', fragment: '1', pathMatch: 'prefix' }]; const menuItems: NbMenuItem[] = createMenuItems(items, menuInternalService); const menuItem: NbMenuItem = menuItems[0]; expect(menuItem.selected).toBeFalsy(); - router.navigate([menuItem.link], { fragment: menuItem.fragment + '1' }) - .then(() => { - menuInternalService.selectFromUrl(menuItems, ''); - expect(menuItem.selected).toEqual(true); - done(); - }); + router.navigate([menuItem.link], { fragment: menuItem.fragment + '1' }).then(() => { + menuInternalService.selectFromUrl(menuItems, ''); + expect(menuItem.selected).toEqual(true); + done(); + }); }); - it('should not select menu item if url contains link without fragment', function(done) { + it('should not select menu item if url contains link without fragment', function (done) { const items: Partial[] = [{ link: '/menu-1', fragment: '1', pathMatch: 'prefix' }]; const menuItems: NbMenuItem[] = createMenuItems(items, menuInternalService); const menuItem: NbMenuItem = menuItems[0]; expect(menuItem.selected).toBeFalsy(); - router.navigate([menuItem.link]) - .then(() => { - menuInternalService.selectFromUrl(menuItems, ''); - expect(menuItem.selected).toBeFalsy(); - done(); - }); + router.navigate([menuItem.link]).then(() => { + menuInternalService.selectFromUrl(menuItems, ''); + expect(menuItem.selected).toBeFalsy(); + done(); + }); }); - it('should not select menu item if url contains fragment without link', function(done) { + it('should not select menu item if url contains fragment without link', function (done) { const items: Partial[] = [{ link: '/menu-1', fragment: '1', pathMatch: 'prefix' }]; const menuItems: NbMenuItem[] = createMenuItems(items, menuInternalService); const menuItem: NbMenuItem = menuItems[0]; expect(menuItem.selected).toBeFalsy(); - router.navigate(['menu-2'], { fragment: menuItem.fragment }) - .then(() => { - menuInternalService.selectFromUrl(menuItems, ''); - expect(menuItem.selected).toBeFalsy(); - done(); - }); + router.navigate(['menu-2'], { fragment: menuItem.fragment }).then(() => { + menuInternalService.selectFromUrl(menuItems, ''); + expect(menuItem.selected).toBeFalsy(); + done(); + }); }); }); }); describe('menu URL helpers', () => { - it('isUrlPathContain should work by url segments', () => { expect(isUrlPathContain('/a/ba', '/a/b')).toBeFalsy(); expect(isUrlPathContain('/a/b/c', '/a/b')).toBeTruthy(); @@ -620,5 +605,4 @@ describe('menu URL helpers', () => { expect(isFragmentContain('/a1/b#222', '1')).toBeFalsy(); expect(isFragmentContain('/a1/b?a=1;b=2&c=3#222', '1')).toBeFalsy(); }); - }); diff --git a/src/framework/theme/components/popover/popover.spec.ts b/src/framework/theme/components/popover/popover.spec.ts index 92f420cc0a..44bc0720f6 100644 --- a/src/framework/theme/components/popover/popover.spec.ts +++ b/src/framework/theme/components/popover/popover.spec.ts @@ -4,17 +4,20 @@ import { RouterTestingModule } from '@angular/router/testing'; import { Subject } from 'rxjs'; import createSpy = jasmine.createSpy; -import { NbThemeModule } from '../../theme.module'; -import { NbLayoutModule } from '../layout/layout.module'; -import { NbAdjustment, NbPosition } from '../cdk/overlay/overlay-position'; -import { NbDynamicOverlayHandler } from '../cdk/overlay/dynamic/dynamic-overlay-handler'; -import { NbOverlayContent } from '../cdk/overlay/overlay-service'; -import { NbRenderableContainer } from '../cdk/overlay/overlay-container'; -import { NbTrigger } from '../cdk/overlay/overlay-trigger'; -import { NbPopoverDirective } from './popover.directive'; -import { NbPopoverComponent } from './popover.component'; -import { NbPopoverModule } from './popover.module'; -import { NbOverlayConfig } from '../cdk/overlay/mapping'; +import { + NbThemeModule, + NbLayoutModule, + NbAdjustment, + NbPosition, + NbDynamicOverlayHandler, + NbOverlayContent, + NbRenderableContainer, + NbTrigger, + NbPopoverDirective, + NbPopoverComponent, + NbPopoverModule, + NbOverlayConfig, +} from '@nebular/theme'; @Component({ selector: 'nb-popover-component-content-test', @@ -46,12 +49,14 @@ export class NbPopoverDefaultTestComponent { template: ` - + [nbPopoverContext]="context" + > @@ -107,8 +112,7 @@ export class NbDynamicOverlayHandlerMock { _offset = 15; _overlayConfig: NbOverlayConfig = {}; - constructor() { - } + constructor() {} host(host: ElementRef) { this._host = host; @@ -163,14 +167,11 @@ export class NbDynamicOverlayHandlerMock { return dynamicOverlay; } - connect() { - } + connect() {} - disconnect() { - } + disconnect() {} - destroy() { - } + destroy() {} } const TEST_COMPONENTS = [ @@ -186,32 +187,27 @@ const TEST_COMPONENTS = [ declarations: [...TEST_COMPONENTS], entryComponents: [NbPopoverComponentContentTestComponent], }) -class PopoverTestModule { } +class PopoverTestModule {} describe('Directive: NbPopoverDirective', () => { - const overlayHandler = new NbDynamicOverlayHandlerMock(); - beforeEach(waitForAsync(() => { - TestBed.resetTestingModule(); - TestBed.configureTestingModule({ - imports: [ - RouterTestingModule.withRoutes([]), - NbThemeModule.forRoot(), - PopoverTestModule, - ], - }); - })); + beforeEach( + waitForAsync(() => { + TestBed.resetTestingModule(); + TestBed.configureTestingModule({ + imports: [RouterTestingModule.withRoutes([]), NbThemeModule.forRoot(), PopoverTestModule], + }); + }), + ); describe('smoke ', () => { - let fixture: ComponentFixture; afterEach(() => { fixture.destroy(); }); - it('should render string', () => { fixture = TestBed.createComponent(NbPopoverDefaultTestComponent); @@ -242,7 +238,6 @@ describe('Directive: NbPopoverDirective', () => { }); it('should render different content type', () => { - fixture = TestBed.createComponent(NbPopoverBindingsTestComponent); fixture.detectChanges(); @@ -314,30 +309,22 @@ describe('Directive: NbPopoverDirective', () => { expect(popover.isShown).toEqual(true); }); - }); describe('mocked services', () => { - - beforeEach(waitForAsync(() => { - TestBed.resetTestingModule(); - TestBed.configureTestingModule({ - imports: [ - RouterTestingModule.withRoutes([]), - NbThemeModule.forRoot(), - PopoverTestModule, - ], - }) - .overrideDirective(NbPopoverDirective, { + beforeEach( + waitForAsync(() => { + TestBed.resetTestingModule(); + TestBed.configureTestingModule({ + imports: [RouterTestingModule.withRoutes([]), NbThemeModule.forRoot(), PopoverTestModule], + }).overrideDirective(NbPopoverDirective, { set: { - providers: [ - { provide: NbDynamicOverlayHandler, useValue: overlayHandler }, - ], + providers: [{ provide: NbDynamicOverlayHandler, useValue: overlayHandler }], }, }); - })); + }), + ); describe('default popover', () => { - let fixture: ComponentFixture; afterEach(() => { @@ -397,7 +384,6 @@ describe('Directive: NbPopoverDirective', () => { expect(hideSpy).toHaveBeenCalledTimes(1); expect(toggleSpy).toHaveBeenCalledTimes(0); - fixture.componentInstance.popover.toggle(); fixture.detectChanges(); @@ -419,7 +405,6 @@ describe('Directive: NbPopoverDirective', () => { }); describe('binding popover', () => { - let fixture: ComponentFixture; afterEach(() => { @@ -427,7 +412,6 @@ describe('Directive: NbPopoverDirective', () => { }); it('should rebuild', () => { - const componentSpy = spyOn(overlayHandler, 'componentType').and.callThrough(); const hostSpy = spyOn(overlayHandler, 'host').and.callThrough(); const positionSpy = spyOn(overlayHandler, 'position').and.callThrough(); @@ -493,7 +477,6 @@ describe('Directive: NbPopoverDirective', () => { }); describe('instance popover', () => { - let fixture: ComponentFixture; afterEach(() => { @@ -501,7 +484,6 @@ describe('Directive: NbPopoverDirective', () => { }); it('should rebuild', () => { - const componentSpy = spyOn(overlayHandler, 'componentType').and.callThrough(); const hostSpy = spyOn(overlayHandler, 'host').and.callThrough(); const positionSpy = spyOn(overlayHandler, 'position').and.callThrough(); @@ -541,7 +523,6 @@ describe('Directive: NbPopoverDirective', () => { expect(rebuildSpy).toHaveBeenCalledTimes(2); }); - it('should accept different content type', () => { const contentSpy = spyOn(overlayHandler, 'content').and.callThrough(); @@ -566,7 +547,6 @@ describe('Directive: NbPopoverDirective', () => { expect(contentSpy).toHaveBeenCalledTimes(5); expect(contentSpy).toHaveBeenCalledWith(fixture.componentInstance.template); }); - }); }); }); diff --git a/src/framework/theme/components/stepper/stepper.spec.ts b/src/framework/theme/components/stepper/stepper.spec.ts index 7417591537..76bc607baa 100644 --- a/src/framework/theme/components/stepper/stepper.spec.ts +++ b/src/framework/theme/components/stepper/stepper.spec.ts @@ -1,12 +1,9 @@ import { ComponentFixture, TestBed } from '@angular/core/testing'; -import { NbStepperComponent } from './stepper.component'; -import { NbStepComponent } from './step.component'; -import { NbIconModule } from '../icon/icon.module'; +import { NbStepperComponent, NbStepComponent, NbIconModule } from '@nebular/theme'; // TODO: this definitely requires more testing! describe('Component: NbStepper', () => { - let stepper: NbStepperComponent; let fixture: ComponentFixture; @@ -23,17 +20,10 @@ describe('Component: NbStepper', () => { it('should set class horizontal', () => { stepper.orientation = 'horizontal'; fixture.detectChanges(); - expect( - fixture - .debugElement.nativeElement.classList.contains('horizontal')) - .toBeTruthy(); + expect(fixture.debugElement.nativeElement.classList.contains('horizontal')).toBeTruthy(); stepper.orientation = 'vertical'; fixture.detectChanges(); - expect( - fixture - .debugElement.nativeElement.classList.contains('vertical')) - .toBeTruthy() + expect(fixture.debugElement.nativeElement.classList.contains('vertical')).toBeTruthy(); }); - }); diff --git a/src/framework/theme/components/tooltip/tooltip.spec.ts b/src/framework/theme/components/tooltip/tooltip.spec.ts index a28fd44772..dc3e418989 100644 --- a/src/framework/theme/components/tooltip/tooltip.spec.ts +++ b/src/framework/theme/components/tooltip/tooltip.spec.ts @@ -4,19 +4,21 @@ import { NoopAnimationsModule } from '@angular/platform-browser/animations'; import { RouterTestingModule } from '@angular/router/testing'; import { Subject } from 'rxjs'; import createSpy = jasmine.createSpy; - -import { NbThemeModule } from '../../theme.module'; -import { NbLayoutModule } from '../layout/layout.module'; -import { NbAdjustment, NbPosition } from '../cdk/overlay/overlay-position'; -import { NbDynamicOverlayHandler } from '../cdk/overlay/dynamic/dynamic-overlay-handler'; -import { NbOverlayContent } from '../cdk/overlay/overlay-service'; -import { NbRenderableContainer } from '../cdk/overlay/overlay-container'; -import { NbTrigger } from '../cdk/overlay/overlay-trigger'; -import { NbTooltipDirective } from './tooltip.directive'; -import { NbTooltipModule } from './tooltip.module'; -import { NbTooltipComponent } from './tooltip.component'; -import { NbIconLibraries } from '../icon/icon-libraries'; -import { NbOverlayConfig } from '../cdk/overlay/mapping'; +import { + NbThemeModule, + NbLayoutModule, + NbAdjustment, + NbPosition, + NbDynamicOverlayHandler, + NbOverlayContent, + NbRenderableContainer, + NbTrigger, + NbTooltipDirective, + NbTooltipModule, + NbTooltipComponent, + NbIconLibraries, + NbOverlayConfig, +} from '@nebular/theme'; @Component({ selector: 'nb-tooltip-default-test', diff --git a/src/framework/theme/public_api.ts b/src/framework/theme/public_api.ts index be972ac27d..fc023790a6 100644 --- a/src/framework/theme/public_api.ts +++ b/src/framework/theme/public_api.ts @@ -112,6 +112,7 @@ export * from './components/chat/chat.module'; export * from './components/chat/chat.options'; export * from './components/chat/chat-avatar.component'; export * from './components/chat/chat-custom-message.directive'; +export * from './components/chat/chat-custom-message.service'; export * from './components/spinner/spinner.component'; export * from './components/spinner/spinner.directive'; export * from './components/spinner/spinner.module'; diff --git a/src/framework/theme/services/breakpoints.spec.ts b/src/framework/theme/services/breakpoints.spec.ts index 91b5fa3802..111cf3e4e1 100644 --- a/src/framework/theme/services/breakpoints.spec.ts +++ b/src/framework/theme/services/breakpoints.spec.ts @@ -6,8 +6,7 @@ import { TestBed, inject, waitForAsync } from '@angular/core/testing'; -import { DEFAULT_MEDIA_BREAKPOINTS, NbMediaBreakpointsService } from './breakpoints.service'; -import { NB_MEDIA_BREAKPOINTS } from '../theme.options'; +import { DEFAULT_MEDIA_BREAKPOINTS, NbMediaBreakpointsService, NB_MEDIA_BREAKPOINTS } from '@nebular/theme'; describe('breakpoint-service', () => { let breakpointService: NbMediaBreakpointsService; @@ -15,20 +14,18 @@ describe('breakpoint-service', () => { beforeEach(() => { // Configure testbed to prepare services TestBed.configureTestingModule({ - providers: [ - { provide: NB_MEDIA_BREAKPOINTS, useValue: DEFAULT_MEDIA_BREAKPOINTS }, - NbMediaBreakpointsService, - ], + providers: [{ provide: NB_MEDIA_BREAKPOINTS, useValue: DEFAULT_MEDIA_BREAKPOINTS }, NbMediaBreakpointsService], }); }); // Single async inject to save references; which are used in all tests below - beforeEach(waitForAsync(inject( - [NbMediaBreakpointsService], - (_breakpointService) => { - breakpointService = _breakpointService - }, - ))); + beforeEach( + waitForAsync( + inject([NbMediaBreakpointsService], (_breakpointService) => { + breakpointService = _breakpointService; + }), + ), + ); const total = 8; it(`has ${total} default breakpoints`, () => { diff --git a/src/framework/theme/services/js-themes-registry.spec.ts b/src/framework/theme/services/js-themes-registry.spec.ts index c570bfb60c..d9a60fa9e2 100644 --- a/src/framework/theme/services/js-themes-registry.spec.ts +++ b/src/framework/theme/services/js-themes-registry.spec.ts @@ -6,9 +6,13 @@ import { TestBed, inject, waitForAsync } from '@angular/core/testing'; -import { NbJSThemeOptions } from './js-themes/theme.options'; -import { BUILT_IN_THEMES, NbJSThemesRegistry } from './js-themes-registry.service'; -import { NB_BUILT_IN_JS_THEMES, NB_JS_THEMES } from '../theme.options'; +import { + NbJSThemeOptions, + BUILT_IN_THEMES, + NbJSThemesRegistry, + NB_BUILT_IN_JS_THEMES, + NB_JS_THEMES, +} from '@nebular/theme'; describe('js-themes-registry-service', () => { let jsThemesRegistry: NbJSThemesRegistry; @@ -53,13 +57,14 @@ describe('js-themes-registry-service', () => { }); }); -// Single async inject to save references; which are used in all tests below - beforeEach(waitForAsync(inject( - [NbJSThemesRegistry], - (_jsThemesRegistry) => { - jsThemesRegistry = _jsThemesRegistry; - }, - ))); + // Single async inject to save references; which are used in all tests below + beforeEach( + waitForAsync( + inject([NbJSThemesRegistry], (_jsThemesRegistry) => { + jsThemesRegistry = _jsThemesRegistry; + }), + ), + ); it('has built in themes', () => { expect(jsThemesRegistry.get('default')).not.toBeUndefined(); @@ -72,12 +77,9 @@ describe('js-themes-registry-service', () => { }); it('has built in themes with inherited font', () => { - expect(jsThemesRegistry.get('default').variables.fontMain) - .toEqual('Open Sans, sans-serif'); - expect(jsThemesRegistry.get('cosmic').variables.fontMain) - .toEqual('Open Sans, sans-serif'); - expect(jsThemesRegistry.get('corporate').variables.fontMain) - .toEqual('Open Sans, sans-serif'); + expect(jsThemesRegistry.get('default').variables.fontMain).toEqual('Open Sans, sans-serif'); + expect(jsThemesRegistry.get('cosmic').variables.fontMain).toEqual('Open Sans, sans-serif'); + expect(jsThemesRegistry.get('corporate').variables.fontMain).toEqual('Open Sans, sans-serif'); }); it('has also new themes', () => { diff --git a/src/framework/theme/services/ruler.service.spec.ts b/src/framework/theme/services/ruler.service.spec.ts index e8f3f92538..d4dd02668d 100644 --- a/src/framework/theme/services/ruler.service.spec.ts +++ b/src/framework/theme/services/ruler.service.spec.ts @@ -2,11 +2,14 @@ import { Component, ElementRef, ViewChild } from '@angular/core'; import { APP_BASE_HREF } from '@angular/common'; import { RouterModule } from '@angular/router'; import { TestBed, ComponentFixture, fakeAsync, tick, inject, waitForAsync } from '@angular/core/testing'; -import { NbLayoutRulerService, NbLayoutDimensions } from './ruler.service'; -import { NbLayoutModule } from '../components/layout/layout.module'; -import { NbThemeService } from './theme.service'; -import { NbThemeModule } from '../theme.module'; -import { NB_DOCUMENT } from '../theme.options'; +import { + NbLayoutRulerService, + NbLayoutDimensions, + NbLayoutModule, + NbThemeService, + NbThemeModule, + NB_DOCUMENT, +} from '@nebular/theme'; let currentDocument; let fixture: ComponentFixture; @@ -23,7 +26,6 @@ let rulerService: NbLayoutRulerService; `, }) class RulerTestComponent { - @ViewChild('resize', { read: ElementRef }) private resizeElement: ElementRef; @ViewChild('layout', { read: ElementRef }) private layout: ElementRef; localScroll = false; @@ -48,7 +50,6 @@ class RulerTestComponent { // This is rather a smoke test describe('NbLayoutRulerService', () => { - beforeEach(() => { fixture = TestBed.configureTestingModule({ imports: [ @@ -56,23 +57,23 @@ describe('NbLayoutRulerService', () => { NbThemeModule.forRoot(), NbLayoutModule, ], - providers: [ NbLayoutRulerService, NbThemeService, { provide: APP_BASE_HREF, useValue: '/' } ], - declarations: [ RulerTestComponent ], - }) - .createComponent(RulerTestComponent); + providers: [NbLayoutRulerService, NbThemeService, { provide: APP_BASE_HREF, useValue: '/' }], + declarations: [RulerTestComponent], + }).createComponent(RulerTestComponent); componentInstance = fixture.componentInstance; fixture.detectChanges(); }); - beforeEach(waitForAsync(inject( - [NbLayoutRulerService, NB_DOCUMENT], - (_rulerService, _document) => { - rulerService = _rulerService; - currentDocument = _document; - }, - ))); + beforeEach( + waitForAsync( + inject([NbLayoutRulerService, NB_DOCUMENT], (_rulerService, _document) => { + rulerService = _rulerService; + currentDocument = _document; + }), + ), + ); afterEach(fakeAsync(() => { fixture.destroy(); @@ -82,41 +83,38 @@ describe('NbLayoutRulerService', () => { it('should get dimensions from document', (done) => { fixture.detectChanges(); - rulerService.getDimensions() - .subscribe((size: NbLayoutDimensions) => { - expect(size.clientHeight).toEqual(currentDocument.documentElement.clientHeight); - expect(size.clientWidth).toEqual(currentDocument.documentElement.clientWidth); - expect(size.scrollHeight).toEqual(currentDocument.documentElement.scrollHeight); - expect(size.scrollWidth).toEqual(currentDocument.documentElement.scrollWidth); - done(); - }) + rulerService.getDimensions().subscribe((size: NbLayoutDimensions) => { + expect(size.clientHeight).toEqual(currentDocument.documentElement.clientHeight); + expect(size.clientWidth).toEqual(currentDocument.documentElement.clientWidth); + expect(size.scrollHeight).toEqual(currentDocument.documentElement.scrollHeight); + expect(size.scrollWidth).toEqual(currentDocument.documentElement.scrollWidth); + done(); + }); }); it('should get dimensions from document when scrolls', (done) => { componentInstance.setSize('10000px', '10000px'); fixture.detectChanges(); - rulerService.getDimensions() - .subscribe((size: NbLayoutDimensions) => { - expect(size.clientHeight).toEqual(currentDocument.documentElement.clientHeight); - expect(size.clientWidth).toEqual(currentDocument.documentElement.clientWidth); - expect(size.scrollHeight).toEqual(currentDocument.documentElement.scrollHeight); - expect(size.scrollWidth).toEqual(currentDocument.documentElement.scrollWidth); - done(); - }) + rulerService.getDimensions().subscribe((size: NbLayoutDimensions) => { + expect(size.clientHeight).toEqual(currentDocument.documentElement.clientHeight); + expect(size.clientWidth).toEqual(currentDocument.documentElement.clientWidth); + expect(size.scrollHeight).toEqual(currentDocument.documentElement.scrollHeight); + expect(size.scrollWidth).toEqual(currentDocument.documentElement.scrollWidth); + done(); + }); }); it('should get dimensions from scrollable', (done) => { componentInstance.useLocalScroll(); fixture.detectChanges(); const scrollable = componentInstance.getScrollableElement(); - rulerService.getDimensions() - .subscribe((size: NbLayoutDimensions) => { - expect(size.clientHeight).toEqual(scrollable.clientHeight); - expect(size.clientWidth).toEqual(scrollable.clientWidth); - expect(size.scrollHeight).toEqual(scrollable.scrollHeight); - expect(size.scrollWidth).toEqual(scrollable.scrollWidth); - done(); - }) + rulerService.getDimensions().subscribe((size: NbLayoutDimensions) => { + expect(size.clientHeight).toEqual(scrollable.clientHeight); + expect(size.clientWidth).toEqual(scrollable.clientWidth); + expect(size.scrollHeight).toEqual(scrollable.scrollHeight); + expect(size.scrollWidth).toEqual(scrollable.scrollWidth); + done(); + }); }); it('should get dimensions from scrollable when scrolls', (done) => { @@ -124,14 +122,12 @@ describe('NbLayoutRulerService', () => { componentInstance.setSize('10000px', '10000px'); fixture.detectChanges(); const scrollable = componentInstance.getScrollableElement(); - rulerService.getDimensions() - .subscribe((size: NbLayoutDimensions) => { - expect(size.clientHeight).toEqual(scrollable.clientHeight); - expect(size.clientWidth).toEqual(scrollable.clientWidth); - expect(size.scrollHeight).toEqual(scrollable.scrollHeight); - expect(size.scrollWidth).toEqual(scrollable.scrollWidth); - done(); - }) + rulerService.getDimensions().subscribe((size: NbLayoutDimensions) => { + expect(size.clientHeight).toEqual(scrollable.clientHeight); + expect(size.clientWidth).toEqual(scrollable.clientWidth); + expect(size.scrollHeight).toEqual(scrollable.scrollHeight); + expect(size.scrollWidth).toEqual(scrollable.scrollWidth); + done(); + }); }); - }); diff --git a/src/framework/theme/services/scroll.service.spec.ts b/src/framework/theme/services/scroll.service.spec.ts index 28d4b49980..3a792b759b 100644 --- a/src/framework/theme/services/scroll.service.spec.ts +++ b/src/framework/theme/services/scroll.service.spec.ts @@ -2,11 +2,14 @@ import { Component, ElementRef, ViewChild } from '@angular/core'; import { APP_BASE_HREF } from '@angular/common'; import { RouterModule } from '@angular/router'; import { TestBed, ComponentFixture, fakeAsync, tick, inject, waitForAsync } from '@angular/core/testing'; -import { NbLayoutScrollService, NbScrollPosition } from './scroll.service'; -import { NbLayoutModule } from '../components/layout/layout.module'; -import { NbThemeService } from './theme.service'; -import { NbThemeModule } from '../theme.module'; -import { NB_WINDOW } from '../theme.options'; +import { + NbLayoutScrollService, + NbScrollPosition, + NbLayoutModule, + NbThemeService, + NbThemeModule, + NB_WINDOW, +} from '@nebular/theme'; let currentWindow; let fixture: ComponentFixture; @@ -21,15 +24,16 @@ let scrollService: NbLayoutScrollService; `, - styles: [` - ::ng-deep nb-layout.with-scroll .scrollable-container { - overflow: auto; - height: 100vh; - } - `], + styles: [ + ` + ::ng-deep nb-layout.with-scroll .scrollable-container { + overflow: auto; + height: 100vh; + } + `, + ], }) class ScrollTestComponent { - @ViewChild('resize', { read: ElementRef }) private resizeElement: ElementRef; @ViewChild('layout', { read: ElementRef }) private layout: ElementRef; localScroll = false; @@ -53,7 +57,6 @@ class ScrollTestComponent { } describe('NbScrollService', () => { - beforeEach(() => { fixture = TestBed.configureTestingModule({ imports: [ @@ -61,23 +64,23 @@ describe('NbScrollService', () => { NbThemeModule.forRoot(), NbLayoutModule, ], - providers: [ NbLayoutScrollService, NbThemeService, { provide: APP_BASE_HREF, useValue: '/' } ], - declarations: [ ScrollTestComponent ], - }) - .createComponent(ScrollTestComponent); + providers: [NbLayoutScrollService, NbThemeService, { provide: APP_BASE_HREF, useValue: '/' }], + declarations: [ScrollTestComponent], + }).createComponent(ScrollTestComponent); componentInstance = fixture.componentInstance; fixture.detectChanges(); }); - beforeEach(waitForAsync(inject( - [NbLayoutScrollService, NB_WINDOW], - (_scrollService, _window) => { - scrollService = _scrollService; - currentWindow = _window; - }, - ))); + beforeEach( + waitForAsync( + inject([NbLayoutScrollService, NB_WINDOW], (_scrollService, _window) => { + scrollService = _scrollService; + currentWindow = _window; + }), + ), + ); afterEach(fakeAsync(() => { fixture.destroy(); @@ -87,47 +90,43 @@ describe('NbScrollService', () => { it('should get initial scroll position', (done) => { fixture.detectChanges(); - scrollService.getPosition() - .subscribe((pos: NbScrollPosition) => { - expect(pos.x).toEqual(0); - expect(pos.y).toEqual(0); - done(); - }) + scrollService.getPosition().subscribe((pos: NbScrollPosition) => { + expect(pos.x).toEqual(0); + expect(pos.y).toEqual(0); + done(); + }); }); it('should get initial scroll position as nothing to scroll', (done) => { currentWindow.scrollTo(10, 10); fixture.detectChanges(); - scrollService.getPosition() - .subscribe((pos: NbScrollPosition) => { - expect(pos.x).toEqual(0); - expect(pos.y).toEqual(0); - done(); - }) + scrollService.getPosition().subscribe((pos: NbScrollPosition) => { + expect(pos.x).toEqual(0); + expect(pos.y).toEqual(0); + done(); + }); }); it('should get updated scroll position', (done) => { componentInstance.setSize('10000px', '10000px'); fixture.detectChanges(); currentWindow.scrollTo(10, 10); - scrollService.getPosition() - .subscribe((pos: NbScrollPosition) => { - expect(pos.x).toEqual(10); - expect(pos.y).toEqual(10); - done(); - }) + scrollService.getPosition().subscribe((pos: NbScrollPosition) => { + expect(pos.x).toEqual(10); + expect(pos.y).toEqual(10); + done(); + }); }); it('should get initial scroll position on scrollable', (done) => { componentInstance.useLocalScroll(); fixture.detectChanges(); const scrollable = componentInstance.getScrollableElement(); - scrollService.getPosition() - .subscribe((pos: NbScrollPosition) => { - expect(pos.x).toEqual(scrollable.scrollLeft); - expect(pos.y).toEqual(scrollable.scrollTop); - done(); - }); + scrollService.getPosition().subscribe((pos: NbScrollPosition) => { + expect(pos.x).toEqual(scrollable.scrollLeft); + expect(pos.y).toEqual(scrollable.scrollTop); + done(); + }); }); it('should get updated scroll position on scrollable', (done) => { @@ -137,12 +136,11 @@ describe('NbScrollService', () => { const scrollable = componentInstance.getScrollableElement(); scrollable.scrollTo(10, 10); fixture.detectChanges(); - scrollService.getPosition() - .subscribe((pos: NbScrollPosition) => { - expect(pos.x).toEqual(10); - expect(pos.y).toEqual(10); - done(); - }); + scrollService.getPosition().subscribe((pos: NbScrollPosition) => { + expect(pos.x).toEqual(10); + expect(pos.y).toEqual(10); + done(); + }); }); it('should scroll using service', (done) => { @@ -151,12 +149,11 @@ describe('NbScrollService', () => { fixture.detectChanges(); scrollService.scrollTo(10, 10); fixture.detectChanges(); - scrollService.getPosition() - .subscribe((pos: NbScrollPosition) => { - expect(pos.x).toEqual(10); - expect(pos.y).toEqual(10); - done(); - }); + scrollService.getPosition().subscribe((pos: NbScrollPosition) => { + expect(pos.x).toEqual(10); + expect(pos.y).toEqual(10); + done(); + }); }); it('should scroll using service (with default x)', (done) => { @@ -165,12 +162,11 @@ describe('NbScrollService', () => { fixture.detectChanges(); scrollService.scrollTo(null, 10); fixture.detectChanges(); - scrollService.getPosition() - .subscribe((pos: NbScrollPosition) => { - expect(pos.x).toEqual(0); - expect(pos.y).toEqual(10); - done(); - }); + scrollService.getPosition().subscribe((pos: NbScrollPosition) => { + expect(pos.x).toEqual(0); + expect(pos.y).toEqual(10); + done(); + }); }); it('should scroll using service (with default y)', (done) => { @@ -179,12 +175,11 @@ describe('NbScrollService', () => { fixture.detectChanges(); scrollService.scrollTo(10, null); fixture.detectChanges(); - scrollService.getPosition() - .subscribe((pos: NbScrollPosition) => { - expect(pos.x).toEqual(10); - expect(pos.y).toEqual(0); - done(); - }); + scrollService.getPosition().subscribe((pos: NbScrollPosition) => { + expect(pos.x).toEqual(10); + expect(pos.y).toEqual(0); + done(); + }); }); it('should scroll using service (with default x)', (done) => { @@ -196,12 +191,11 @@ describe('NbScrollService', () => { scrollService.scrollTo(null, 20); fixture.detectChanges(); - scrollService.getPosition() - .subscribe((pos: NbScrollPosition) => { - expect(pos.x).toEqual(10); - expect(pos.y).toEqual(20); - done(); - }); + scrollService.getPosition().subscribe((pos: NbScrollPosition) => { + expect(pos.x).toEqual(10); + expect(pos.y).toEqual(20); + done(); + }); }); it('should scroll using service (with default y)', (done) => { @@ -213,12 +207,11 @@ describe('NbScrollService', () => { scrollService.scrollTo(20, null); fixture.detectChanges(); - scrollService.getPosition() - .subscribe((pos: NbScrollPosition) => { - expect(pos.x).toEqual(20); - expect(pos.y).toEqual(10); - done(); - }); + scrollService.getPosition().subscribe((pos: NbScrollPosition) => { + expect(pos.x).toEqual(20); + expect(pos.y).toEqual(10); + done(); + }); }); it('should scroll using service back to 0,0', (done) => { @@ -230,12 +223,11 @@ describe('NbScrollService', () => { scrollService.scrollTo(0, 0); fixture.detectChanges(); - scrollService.getPosition() - .subscribe((pos: NbScrollPosition) => { - expect(pos.x).toEqual(0); - expect(pos.y).toEqual(0); - done(); - }); + scrollService.getPosition().subscribe((pos: NbScrollPosition) => { + expect(pos.x).toEqual(0); + expect(pos.y).toEqual(0); + done(); + }); }); it('should scroll using service back (with default x,y)', (done) => { @@ -247,22 +239,19 @@ describe('NbScrollService', () => { scrollService.scrollTo(); fixture.detectChanges(); - scrollService.getPosition() - .subscribe((pos: NbScrollPosition) => { - expect(pos.x).toEqual(10); - expect(pos.y).toEqual(10); - done(); - }); + scrollService.getPosition().subscribe((pos: NbScrollPosition) => { + expect(pos.x).toEqual(10); + expect(pos.y).toEqual(10); + done(); + }); }); it('should listen to scroll', (done) => { - scrollService.onScroll() - .subscribe((event: any) => { - expect(event).not.toBeNull(); - done(); - }); + scrollService.onScroll().subscribe((event: any) => { + expect(event).not.toBeNull(); + done(); + }); currentWindow.dispatchEvent(new Event('scroll')); }); - }); diff --git a/src/framework/theme/services/theme.spec.ts b/src/framework/theme/services/theme.spec.ts index 9e811a4174..5b2f5b44d4 100644 --- a/src/framework/theme/services/theme.spec.ts +++ b/src/framework/theme/services/theme.spec.ts @@ -5,14 +5,17 @@ */ import { TestBed, inject, waitForAsync } from '@angular/core/testing'; - -import { DEFAULT_MEDIA_BREAKPOINTS, NbMediaBreakpointsService } from './breakpoints.service'; -import { NbThemeService } from './theme.service'; -import { BUILT_IN_THEMES, NbJSThemesRegistry } from './js-themes-registry.service'; import { - NB_BUILT_IN_JS_THEMES, NB_JS_THEMES, NB_MEDIA_BREAKPOINTS, + DEFAULT_MEDIA_BREAKPOINTS, + NbMediaBreakpointsService, + NbThemeService, + BUILT_IN_THEMES, + NbJSThemesRegistry, + NB_BUILT_IN_JS_THEMES, + NB_JS_THEMES, + NB_MEDIA_BREAKPOINTS, NB_THEME_OPTIONS, -} from '../theme.options'; +} from '@nebular/theme'; describe('theme-service', () => { let breakpointService: NbMediaBreakpointsService; @@ -33,22 +36,22 @@ describe('theme-service', () => { }); }); -// Single async inject to save references; which are used in all tests below - beforeEach(waitForAsync(inject( - [NbMediaBreakpointsService, NbThemeService], - (_breakpointService, _themeService) => { - breakpointService = _breakpointService; - themeService = _themeService; - }, - ))); + // Single async inject to save references; which are used in all tests below + beforeEach( + waitForAsync( + inject([NbMediaBreakpointsService, NbThemeService], (_breakpointService, _themeService) => { + breakpointService = _breakpointService; + themeService = _themeService; + }), + ), + ); it('returns default theme specified in options', () => { let current: any; - const subscription = themeService.onThemeChange() - .subscribe((change: any) => { - current = change; - }); + const subscription = themeService.onThemeChange().subscribe((change: any) => { + current = change; + }); try { expect(current.name).toEqual('default'); expect(current.previous).toBeUndefined(); @@ -60,10 +63,9 @@ describe('theme-service', () => { it('listens to theme change, saving a previous one', () => { let current: any; - const subscription = themeService.onThemeChange() - .subscribe((change: any) => { - current = change; - }); + const subscription = themeService.onThemeChange().subscribe((change: any) => { + current = change; + }); try { expect(current.name).toEqual('default'); expect(current.previous).toBeUndefined(); @@ -83,10 +85,9 @@ describe('theme-service', () => { it('listens to window media query change', () => { let current: any; - const subscription = themeService.onMediaQueryChange() - .subscribe((change: any) => { - current = change; - }); + const subscription = themeService.onMediaQueryChange().subscribe((change: any) => { + current = change; + }); try { expect(current).toBeUndefined(); @@ -109,10 +110,9 @@ describe('theme-service', () => { it('listens to theme variables change', () => { let current: any; - const subscription = themeService.getJsTheme() - .subscribe((change: any) => { - current = change.variables; - }); + const subscription = themeService.getJsTheme().subscribe((change: any) => { + current = change.variables; + }); try { // TODO could be rewrite with usage of done() expect(current).not.toBeUndefined(); @@ -124,10 +124,8 @@ describe('theme-service', () => { themeService.changeTheme('corporate'); expect(current.bg).toEqual('#ffffff'); - } finally { subscription.unsubscribe(); } }); - }); diff --git a/src/tsconfig.spec-wp.json b/src/tsconfig.spec-wp.json index 9fd7024782..f9c1424886 100644 --- a/src/tsconfig.spec-wp.json +++ b/src/tsconfig.spec-wp.json @@ -3,7 +3,7 @@ "compilerOptions": { "paths": { "@nebular/*": [ - "../dist/*" + "dist/*" ] } } diff --git a/src/tsconfig.wp.json b/src/tsconfig.wp.json index af529ee841..54c8e904b2 100644 --- a/src/tsconfig.wp.json +++ b/src/tsconfig.wp.json @@ -3,7 +3,7 @@ "compilerOptions": { "paths": { "@nebular/*": [ - "../dist/*" + "dist/*" ] } }