Commit 4c9248e5 authored by Christopher Keim's avatar Christopher Keim
Browse files

[TOB-152] feat: Add drop down menu to new page



[TOB-165] fix: Add server configuration to assets

[TOB-196] chore: Add squareqube configuration

 * Add scripts and configuration for sonarqube
 * Fix minor linting errors
 * Add puppeteer for tests with headless chrome

[162] test: Add tests for service classes

 * Add tests for AppRouting/RouteGuards
 * Add tests for I18nService
 * Add tests for AuthService/AuthInterceptorService

[161] test: Add tests for components

 * Add tests for FileDropComponent
 * Add tests for NewStatementComponent
 * Add tests for NewStatementFormComponent
 * Add tests for NavigationComponent
 * Add tests for NavDropDownComponent
 * Add tests for ExitPageComponent
 * Add tests for ObjToArrayPipe
 * Add tests for MomentPipe

[TOB-130] feat: Add form for negative answer
 * Add API calls for Camunda process
 * Add store module for Camunda process
 * Add dynamically buttons to details component according to tasks
 * Add basic edit component for statements
Signed-off-by: Christopher Keim's avatarChristopher Keim <keim@develop-group.de>
parent 22dbe0d7
# Eclipse openK User Modules - Statement Public Affairs Frontend
This application represents a user module for the [Eclipse openK User Modules](https://projects.eclipse.org/projects/technology.openk-usermodules) project.
This application represents a user module for the
[Eclipse openK User Modules](https://projects.eclipse.org/projects/technology.openk-usermodules)
project.
## Development server
## Prerequisites
Run `npm run serve` for a dev server. Navigate to `http://localhost:4200/`. The app will automatically reload if you change any of the source files.
With `npm` in the path variable, run first `npm install` to
download and install all dependencies of this module.
After that, all npm scripts for deploying, developing and
testing are available.
Additionally, archiving the build as WAR file requires also
the Java Archiver command line tool in the path variable.
## Configuration
The whole application can be configured via certain properties in
the `./package.json`. The following options are available:
* `routes.spaFrontend`: Route on which the website is served
* `routes.spaBackend`: Route on which the website's backend is served
* `routes.portal`: Route on which the main portal is served
Changes to these properties take only effect after rebuilding the
application.
## Build
Run `npm run build` to build the project. All build artifacts will be stored in the `dist/` directory.
Building the application is done via the Angular CLI or by the
provided scripts in the `./package.json` (which also provide all
necessary configuration steps):
* `npm run build` Build the application via the Angular CLI
to the `./dist/statement-public-affairs` folder
* `npm run archive` Archive the build as WAR file
to `./dist/statement-public-affairs-frontend.war`
Note that the archiving script requires the Java Archiver
(`jar`) command line tool in the path variable.
## Development
Run `npm run start` for setting up a local dev server which is
served on http://localhost:4200/. The local dev server is also
a proxy which can be configured by the file `./proxy.conf.json`.
It redirects all calls to the back end to a specific location.
Run `npm run test` to execute all tests via Karma and Jasmine.
This also sets up a local dev server with live reload.
Run `npm run test:report` instead to generate a coverage report
at the folder `./coverage/statement-public-affairs`.
Run `npm run lint` for linting all source files, both
typescript and (s)css code.
Run `npm run lint:report` to generate instead linting report
files at `./lint.ts.report.json` and `./lint.styles.report.json`.
Run `npm run sonar` to upload the test and linting reports
to a sonarqube instance via the sonar-scanner.
This can be configured either by the
`./sonar-projects.properties` file or by arguments on the command
line. For example, uploading the reports to a different
port can be done via:
```
npm run sonar -- -Dsonar.host.url=http://localhost:9001
```
## Storybook
Run `start:storybook` for setting up a local storybook server.
Run `build:storybook` instead for building the storybook webpage
for later use.
## Miscellaneous Scripts
## Running unit tests
Run `npm run list-licenses` to generate a listing of all packages
and their licenses used for production. A file is created at
`./licenses.txt`.
The content of this file is required in the `./NOTICE.md` file.
Run `ng test` to execute the unit tests via [Karma](https://karma-runner.github.io).
Run `npm run check-legal-headers` to check if all source files
have a specific legal header.
## Scripts
## Git Hooks
###### npm run licenses
Run `npm run licenses` to generate a listing of all packages and their licenses used for production. A file is created at `./licenses.txt`. The content of the file is required in `NOTICE.md`.
Run `npm run pre-commit` to check if a commit passes the pre-commit
script. This script concatenates `npm run lint` and
`npm run check-legal-headers`.
......@@ -30,9 +30,15 @@
"input": "./src/assets",
"output": "/assets",
"ignore": [
"META-INF/*",
"WEB-INF/*"
]
},
{
"glob": "**/*",
"input": "./src/assets/META-INF",
"output": "/META-INF"
},
{
"glob": "**/*",
"input": "./src/assets/WEB-INF",
......
......@@ -14,6 +14,8 @@
// Karma configuration file, see link for more information
// https://karma-runner.github.io/1.0/config/configuration-file.html
process.env.CHROME_BIN = require('puppeteer').executablePath();
module.exports = function (config) {
config.set({
basePath: '',
......@@ -38,7 +40,7 @@ module.exports = function (config) {
colors: true,
logLevel: config.LOG_INFO,
autoWatch: true,
browsers: ['Chrome'],
browsers: ['Chrome', 'ChromeHeadless'],
singleRun: false,
restartOnFileChange: true
});
......
{
"name": "openkonsequenz-statement-public-affairs",
"version": "0.2.0",
"version": "0.3.0",
"lockfileVersion": 1,
"requires": true,
"dependencies": {
......@@ -2975,6 +2975,16 @@
}
}
},
"@types/yauzl": {
"version": "2.9.1",
"resolved": "https://registry.npmjs.org/@types/yauzl/-/yauzl-2.9.1.tgz",
"integrity": "sha512-A1b8SU4D10uoPjwb0lnHmmu8wZhR9d+9o2PKBQT2jU5YPTKsxac6M2qGAdY7VcL+dHHhARVUDmeg0rOrcd9EjA==",
"dev": true,
"optional": true,
"requires": {
"@types/node": "*"
}
},
"@webassemblyjs/ast": {
"version": "1.8.5",
"resolved": "https://registry.npmjs.org/@webassemblyjs/ast/-/ast-1.8.5.tgz",
......@@ -4346,6 +4356,40 @@
"file-uri-to-path": "1.0.0"
}
},
"bl": {
"version": "4.0.2",
"resolved": "https://registry.npmjs.org/bl/-/bl-4.0.2.tgz",
"integrity": "sha512-j4OH8f6Qg2bGuWfRiltT2HYGx0e1QcBTrK9KAHNMwMZdQnDZFk0ZSYIpADjYCB3U12nicC5tVJwSIhwOWjb4RQ==",
"dev": true,
"requires": {
"buffer": "^5.5.0",
"inherits": "^2.0.4",
"readable-stream": "^3.4.0"
},
"dependencies": {
"buffer": {
"version": "5.6.0",
"resolved": "https://registry.npmjs.org/buffer/-/buffer-5.6.0.tgz",
"integrity": "sha512-/gDYp/UtU0eA1ys8bOs9J6a+E/KWIY+DZ+Q2WESNUA0jFRsJOc0SNUO6xJ5SGA1xueg3NL65W6s+NY5l9cunuw==",
"dev": true,
"requires": {
"base64-js": "^1.0.2",
"ieee754": "^1.1.4"
}
},
"readable-stream": {
"version": "3.6.0",
"resolved": "https://registry.npmjs.org/readable-stream/-/readable-stream-3.6.0.tgz",
"integrity": "sha512-BViHy7LKeTz4oNnkcLJ+lVSL6vpiFeX6/d3oSH8zCW7UxP2onchk+vTGB143xuFjHS3deTgkKoXXymXqymiIdA==",
"dev": true,
"requires": {
"inherits": "^2.0.3",
"string_decoder": "^1.1.1",
"util-deprecate": "^1.0.1"
}
}
}
},
"blob": {
"version": "0.0.5",
"resolved": "https://registry.npmjs.org/blob/-/blob-0.0.5.tgz",
......@@ -4720,6 +4764,12 @@
"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-fill": {
"version": "1.0.0",
"resolved": "https://registry.npmjs.org/buffer-fill/-/buffer-fill-1.0.0.tgz",
......@@ -7313,6 +7363,29 @@
}
}
},
"extract-zip": {
"version": "2.0.0",
"resolved": "https://registry.npmjs.org/extract-zip/-/extract-zip-2.0.0.tgz",
"integrity": "sha512-i42GQ498yibjdvIhivUsRslx608whtGoFIhF26Z7O4MYncBxp8CwalOs1lnHy21A9sIohWO2+uiE4SRtC9JXDg==",
"dev": true,
"requires": {
"@types/yauzl": "^2.9.1",
"debug": "^4.1.1",
"get-stream": "^5.1.0",
"yauzl": "^2.10.0"
},
"dependencies": {
"get-stream": {
"version": "5.1.0",
"resolved": "https://registry.npmjs.org/get-stream/-/get-stream-5.1.0.tgz",
"integrity": "sha512-EXr1FOzrzTfGeL0gQdeFEvOMm2mzMOglyiOXSTpPC+iAjAKftbr3jpCMWynogwYnM+eSj9sHGc6wjIcDvYiygw==",
"dev": true,
"requires": {
"pump": "^3.0.0"
}
}
}
},
"extsprintf": {
"version": "1.3.0",
"resolved": "https://registry.npmjs.org/extsprintf/-/extsprintf-1.3.0.tgz",
......@@ -7378,6 +7451,15 @@
"websocket-driver": ">=0.5.1"
}
},
"fd-slicer": {
"version": "1.1.0",
"resolved": "https://registry.npmjs.org/fd-slicer/-/fd-slicer-1.1.0.tgz",
"integrity": "sha1-JcfInLH5B3+IkbvmHY85Dq4lbx4=",
"dev": true,
"requires": {
"pend": "~1.2.0"
}
},
"figgy-pudding": {
"version": "3.5.2",
"resolved": "https://registry.npmjs.org/figgy-pudding/-/figgy-pudding-3.5.2.tgz",
......@@ -7778,6 +7860,12 @@
"readable-stream": "^2.0.0"
}
},
"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": "4.0.2",
"resolved": "https://registry.npmjs.org/fs-extra/-/fs-extra-4.0.2.tgz",
......@@ -11007,6 +11095,12 @@
"minimist": "^1.2.5"
}
},
"mkdirp-classic": {
"version": "0.5.3",
"resolved": "https://registry.npmjs.org/mkdirp-classic/-/mkdirp-classic-0.5.3.tgz",
"integrity": "sha512-gKLcREMhtuZRwRAfqP3RFW+TK4JqApVBtOIftVgjuABpAtpxhPGaDcfvbhNvD0B8iD1oUr/txX35NjcaY6Ns/A==",
"dev": true
},
"moment": {
"version": "2.24.0",
"resolved": "https://registry.npmjs.org/moment/-/moment-2.24.0.tgz",
......@@ -12045,6 +12139,12 @@
"sha.js": "^2.4.8"
}
},
"pend": {
"version": "1.2.0",
"resolved": "https://registry.npmjs.org/pend/-/pend-1.2.0.tgz",
"integrity": "sha1-elfrVQpng/kRUzH89GY9XI4AelA=",
"dev": true
},
"performance-now": {
"version": "2.1.0",
"resolved": "https://registry.npmjs.org/performance-now/-/performance-now-2.1.0.tgz",
......@@ -13005,6 +13105,12 @@
"integrity": "sha512-3ouUOpQhtgrbOa17J7+uxOTpITYWaGP7/AhoR3+A+/1e9skrzelGi/dXzEYyvbxubEF6Wn2ypscTKiKJFFn1ag==",
"dev": true
},
"progress": {
"version": "2.0.3",
"resolved": "https://registry.npmjs.org/progress/-/progress-2.0.3.tgz",
"integrity": "sha512-7PiHtLll5LdnKIMw100I+8xJXR5gW2QwWYkT6iJva0bXitZKa/XMrSbdmg3r2Xnaidz9Qumd0VPaMrZlF9V9sA==",
"dev": true
},
"proj4": {
"version": "2.6.1",
"resolved": "https://registry.npmjs.org/proj4/-/proj4-2.6.1.tgz",
......@@ -13272,6 +13378,12 @@
"ipaddr.js": "1.9.1"
}
},
"proxy-from-env": {
"version": "1.1.0",
"resolved": "https://registry.npmjs.org/proxy-from-env/-/proxy-from-env-1.1.0.tgz",
"integrity": "sha512-D+zkORCbA9f1tdWRK0RaCR3GPv50cMxcrz4X8k5LTSUD1Dkw47mKJEZQNunItRTkWwgtaUSo1RVFRIG9ZXiFYg==",
"dev": true
},
"prr": {
"version": "1.0.1",
"resolved": "https://registry.npmjs.org/prr/-/prr-1.0.1.tgz",
......@@ -13343,6 +13455,54 @@
"integrity": "sha512-XRsRjdf+j5ml+y/6GKHPZbrF/8p2Yga0JPtdqTIY2Xe5ohJPD9saDJJLPvp9+NSBprVvevdXZybnj2cv8OEd0A==",
"dev": true
},
"puppeteer": {
"version": "3.1.0",
"resolved": "https://registry.npmjs.org/puppeteer/-/puppeteer-3.1.0.tgz",
"integrity": "sha512-jLa9sqdVx0tPnr2FcwAq+8DSjGhSM4YpkwOf3JE22Ycyqm71SW7B5uGfTyMGFoLCmbCozbLZclCjasPb0flTRw==",
"dev": true,
"requires": {
"debug": "^4.1.0",
"extract-zip": "^2.0.0",
"https-proxy-agent": "^4.0.0",
"mime": "^2.0.3",
"progress": "^2.0.1",
"proxy-from-env": "^1.0.0",
"rimraf": "^3.0.2",
"tar-fs": "^2.0.0",
"unbzip2-stream": "^1.3.3",
"ws": "^7.2.3"
},
"dependencies": {
"agent-base": {
"version": "5.1.1",
"resolved": "https://registry.npmjs.org/agent-base/-/agent-base-5.1.1.tgz",
"integrity": "sha512-TMeqbNl2fMW0nMjTEPOwe3J/PRFP4vqeoNuQMG0HlMrtm5QxKqdvAkZ1pRBQ/ulIyDD5Yq0nJ7YbdD8ey0TO3g==",
"dev": true
},
"https-proxy-agent": {
"version": "4.0.0",
"resolved": "https://registry.npmjs.org/https-proxy-agent/-/https-proxy-agent-4.0.0.tgz",
"integrity": "sha512-zoDhWrkR3of1l9QAL8/scJZyLu8j/gBkcwcaQOZh7Gyh/+uJQzGVETdgT30akuwkpL8HTRfssqI3BZuV18teDg==",
"dev": true,
"requires": {
"agent-base": "5",
"debug": "4"
}
},
"mime": {
"version": "2.4.6",
"resolved": "https://registry.npmjs.org/mime/-/mime-2.4.6.tgz",
"integrity": "sha512-RZKhC3EmpBchfTGBVb8fb+RL2cWyw/32lshnsETttkBAyAUXSGHxbEJWWRXc751DrIxG1q04b8QwMbAwkRPpUA==",
"dev": true
},
"ws": {
"version": "7.3.0",
"resolved": "https://registry.npmjs.org/ws/-/ws-7.3.0.tgz",
"integrity": "sha512-iFtXzngZVXPGgpTlP1rBqsUK82p9tKqsWRPg5L56egiljujJT3vGAYnHANvFxBieXrTFavhzhxW52jnaWV+w2w==",
"dev": true
}
}
},
"q": {
"version": "1.5.1",
"resolved": "https://registry.npmjs.org/q/-/q-1.5.1.tgz",
......@@ -16283,6 +16443,12 @@
"socks": "^2.3.3"
}
},
"sonar-scanner": {
"version": "3.1.0",
"resolved": "https://registry.npmjs.org/sonar-scanner/-/sonar-scanner-3.1.0.tgz",
"integrity": "sha1-UcHBEB9UuYq8XYVlIJsdkjKXk0M=",
"dev": true
},
"sort-keys": {
"version": "1.1.2",
"resolved": "https://registry.npmjs.org/sort-keys/-/sort-keys-1.1.2.tgz",
......@@ -17439,6 +17605,44 @@
}
}
},
"tar-fs": {
"version": "2.1.0",
"resolved": "https://registry.npmjs.org/tar-fs/-/tar-fs-2.1.0.tgz",
"integrity": "sha512-9uW5iDvrIMCVpvasdFHW0wJPez0K4JnMZtsuIeDI7HyMGJNxmDZDOCQROr7lXyS+iL/QMpj07qcjGYTSdRFXUg==",
"dev": true,
"requires": {
"chownr": "^1.1.1",
"mkdirp-classic": "^0.5.2",
"pump": "^3.0.0",
"tar-stream": "^2.0.0"
}
},
"tar-stream": {
"version": "2.1.2",
"resolved": "https://registry.npmjs.org/tar-stream/-/tar-stream-2.1.2.tgz",
"integrity": "sha512-UaF6FoJ32WqALZGOIAApXx+OdxhekNMChu6axLJR85zMMjXKWFGjbIRe+J6P4UnRGg9rAwWvbTT0oI7hD/Un7Q==",
"dev": true,
"requires": {
"bl": "^4.0.1",
"end-of-stream": "^1.4.1",
"fs-constants": "^1.0.0",
"inherits": "^2.0.3",
"readable-stream": "^3.1.1"
},
"dependencies": {
"readable-stream": {
"version": "3.6.0",
"resolved": "https://registry.npmjs.org/readable-stream/-/readable-stream-3.6.0.tgz",
"integrity": "sha512-BViHy7LKeTz4oNnkcLJ+lVSL6vpiFeX6/d3oSH8zCW7UxP2onchk+vTGB143xuFjHS3deTgkKoXXymXqymiIdA==",
"dev": true,
"requires": {
"inherits": "^2.0.3",
"string_decoder": "^1.1.1",
"util-deprecate": "^1.0.1"
}
}
}
},
"telejson": {
"version": "3.3.0",
"resolved": "https://registry.npmjs.org/telejson/-/telejson-3.3.0.tgz",
......@@ -17990,6 +18194,28 @@
"integrity": "sha512-UIEXBNeYmKptWH6z8ZnqTeS8fV74zG0/eRU9VGkpzz+LIJNs8W/zM/L+7ctCkRrgbNnnR0xxw4bKOr0cW0N0Og==",
"dev": true
},
"unbzip2-stream": {
"version": "1.4.3",
"resolved": "https://registry.npmjs.org/unbzip2-stream/-/unbzip2-stream-1.4.3.tgz",
"integrity": "sha512-mlExGW4w71ebDJviH16lQLtZS32VKqsSfk80GCfUlwT/4/hNRFsoscrF/c++9xinkMzECL1uL9DDwXqFWkruPg==",
"dev": true,
"requires": {
"buffer": "^5.2.1",
"through": "^2.3.8"
},
"dependencies": {
"buffer": {
"version": "5.6.0",
"resolved": "https://registry.npmjs.org/buffer/-/buffer-5.6.0.tgz",
"integrity": "sha512-/gDYp/UtU0eA1ys8bOs9J6a+E/KWIY+DZ+Q2WESNUA0jFRsJOc0SNUO6xJ5SGA1xueg3NL65W6s+NY5l9cunuw==",
"dev": true,
"requires": {
"base64-js": "^1.0.2",
"ieee754": "^1.1.4"
}
}
}
},
"unfetch": {
"version": "4.1.0",
"resolved": "https://registry.npmjs.org/unfetch/-/unfetch-4.1.0.tgz",
......@@ -20682,6 +20908,16 @@
"decamelize": "^1.2.0"
}
},
"yauzl": {
"version": "2.10.0",
"resolved": "https://registry.npmjs.org/yauzl/-/yauzl-2.10.0.tgz",
"integrity": "sha1-x+sXyT4RLLEIb6bY5R+wZnt5pfk=",
"dev": true,
"requires": {
"buffer-crc32": "~0.2.3",
"fd-slicer": "~1.1.0"
}
},
"yeast": {
"version": "0.1.2",
"resolved": "https://registry.npmjs.org/yeast/-/yeast-0.1.2.tgz",
......
{
"name": "openkonsequenz-statement-public-affairs",
"version": "0.2.0",
"version": "0.3.0",
"description": "Statement Public Affairs",
"license": "Eclipse Public License - v 2.0",
"routes": {
......@@ -16,12 +16,15 @@
"build:stats:analyze": "webpack-bundle-analyzer ./dist/statement-public-affairs/stats-es2015.json",
"-- Development ----------": "",
"start": "ng serve",
"test": "ng test --codeCoverage=true --watch=false",
"test:watch": "ng test --watch=true",
"test": "ng test --watch=true",
"test:report": "ng test --codeCoverage=true --watch=false --browsers=ChromeHeadless",
"lint": "npm run lint:ts && npm run lint:styles",
"lint:ts": "ng lint",
"lint:styles": "stylelint \"./src/**/*.html\" \"./src/**/*.css\" \"./src/**/*.scss\"",
"lint:styles:fix": "stylelint \"./src/**/*.html\" \"./src/**/*.css\" \"./src/**/*.scss\" --fix",
"lint:report": "npm run lint:report:ts && npm run lint:report:styles",
"lint:report:ts": "ng lint --force=true --format=json > lint.ts.report.json",
"lint:report:styles": "stylelint -f json \"./src/**/*.html\" \"./src/**/*.css\" \"./src/**/*.scss\" > lint.styles.report.json || true",
"sonar": "sonar-scanner",
"-- Storybook ------------": "",
"start:storybook": "start-storybook -p 6006",
"build:storybook": "build-storybook -o ./dist/storybook",
......@@ -49,13 +52,13 @@
"@ngx-translate/http-loader": "^4.0.0",
"leaflet": "^1.6.0",
"material-design-icons": "^3.0.1",
"moment": "2.24.0",
"primeng": "^9.0.6",
"proj4": "^2.6.1",
"rxjs": "~6.5.4",
"source-sans-pro": "^3.6.0",
"tslib": "^1.10.0",
"zone.js": "~0.10.2",
"moment": "2.24.0"
"zone.js": "~0.10.2"
},
"devDependencies": {
"@angular-devkit/build-angular": "~0.901.0",
......@@ -88,6 +91,8 @@
"karma-jasmine-html-reporter": "^1.4.2",
"license-checker": "^25.0.1",
"protractor": "~5.4.3",
"puppeteer": "^3.1.0",
"sonar-scanner": "^3.1.0",
"stylelint": "^13.3.0",
"stylelint-config-sass-guidelines": "^7.0.0",
"ts-node": "~8.3.0",
......
sonar.projectKey=openk.dg:statement-public-affairs.fe
sonar.login=admin
sonar.password=admin
sonar.language=ts,css
sonar.sourceEncoding=UTF-8
sonar.sources=src
sonar.exclusions=**/*.stories.ts
sonar.tests=src
sonar.test.inclusions=src/test.ts,**/*.spec.ts
sonar.javascript.lcov.reportPaths=coverage/statement-public-affairs/lcov.info
sonar.typescript.tsconfigPath=tsconfig.app.json
sonar.typescript.tslint.reportPaths=lint.ts.report.json
sonar.css.stylelint.reportPaths=lint.styles.report.json
/********************************************************************************
* Copyright (c) 2020 Contributors to the Eclipse Foundation
*
* See the NOTICE file(s) distributed with this work for additional
* information regarding copyright ownership.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License 2.0 which is available at
* http://www.eclipse.org/legal/epl-2.0
*
* SPDX-License-Identifier: EPL-2.0
********************************************************************************/
import {Location} from "@angular/common";
import {NgZone} from "@angular/core";
import {async, TestBed} from "@angular/core/testing";
import {CanActivate, Router} from "@angular/router";
import {RouterTestingModule} from "@angular/router/testing";
import {appRoutes} from "./app-routing.module";
import {NewStatementRouteGuardService} from "./features/new/services/new-statement-route-guard.service";
class RouteGuardMock implements CanActivate {
public canActivate() {
return true;
}
}
describe("AppRoutingModule", () => {
let router: Router;
let location: Location;
function callInZone<T>(fn: () => T | Promise<T>): Promise<T> {
return new Promise<T>((res, rej) => {
const ngZone = TestBed.inject(NgZone);
ngZone.run(() => Promise.resolve().then(() => fn()).then(res).catch(rej));
});
}
beforeEach(async(() => {
TestBed.configureTestingModule({
imports: [
RouterTestingModule.withRoutes(appRoutes)
],
providers: [
{
provide: NewStatementRouteGuardService,
useClass: RouteGuardMock
}
]
}).compileComponents();
router = TestBed.inject(Router);
location = TestBed.inject(Location);
}));
it("should use wildcard and redirect to /", async () => {
const isRoutingSuccessful = await callInZone(() => router.navigate(["wildcard"]));
expect(isRoutingSuccessful).toBeTruthy();
expect(location.path()).toBe("/");
});
it("should navigate to /details", async () => {
const queryParams = {id: 19};
const isRoutingSuccessful = await callInZone(() => router.navigate(["details"], {queryParams}));
expect(isRoutingSuccessful).toBeTruthy();
expect(location.path()).toBe("/details?id=19");
});
it("should navigate to /edit", async () => {
const queryParams = {id: 19, taskId: "ABCDEFG"};
const isRoutingSuccessful = await callInZone(() => router.navigate(["edit"], {queryParams}));
expect(isRoutingSuccessful).toBeTruthy();
expect(location.path()).toBe("/edit?id=19&taskId=ABCDEFG");
});
it("should navigate to /new", async () => {
const isRoutingSuccessful = await callInZone(() => router.navigate(["new"]));
expect(isRoutingSuccessful).toBeTruthy();
expect(location.path()).toBe("/new");
});
});
......@@ -14,7 +14,7 @@
import {NgModule} from "@angular/core";
import {RouterModule, Routes} from "@angular/router";