Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Case insensitive admin search, testing updates and manager setting of notes and report status #281

Merged
merged 60 commits into from
Feb 5, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
60 commits
Select commit Hold shift + click to select a range
3524e9e
Remove --runInBand
dcloud Jan 27, 2021
60b68e0
Add some docs around testing
dcloud Feb 1, 2021
bb1a516
Merge branch 'main' into dcloud/test-failure-fixes
dcloud Feb 1, 2021
8484d6e
Allow search to be case-insensitive
Feb 1, 2021
4ef5971
Fix Eslint issue
Feb 1, 2021
3f43234
Fix example
dcloud Feb 1, 2021
deac317
Rename docker-compose file used for dynamic security scans
dcloud Jan 26, 2021
f3f9022
Create bin/docker script, which will make command composition easier
dcloud Jan 27, 2021
44af291
Remove --runInBand
dcloud Jan 27, 2021
9b422f3
Add option parsing and rename docker script
dcloud Jan 27, 2021
84b24b8
Multiple docker-compose configs for multiple environments
dcloud Jan 27, 2021
92a41c4
bin/docker-run fixes, improvements
dcloud Jan 28, 2021
32f38c8
Minor docker-run improvements
dcloud Jan 28, 2021
de13b1f
Change 'conf' to be a string, since that's how it gets used. Echo cmd…
dcloud Jan 29, 2021
a232a91
docker-run: 'test' uses test env by default
dcloud Jan 29, 2021
ac43405
Undo the composed compose files; docker-compose wasn't handling diffe…
dcloud Jan 29, 2021
188b05f
Remove 2-liners in favor of echo_exec function
dcloud Jan 29, 2021
ece7bb4
docker-run: Make default config a readonly var
dcloud Jan 29, 2021
c8886f0
Add simpler run-tests script. Improve docker-compose.test.yml with na…
dcloud Feb 1, 2021
8b0bece
Remove bin/docker-run since we are no longer composing multiple
dcloud Feb 1, 2021
43e18c9
One last rename
dcloud Feb 1, 2021
90c4e50
Managers can add notes and set status of reports
jasalisbury Feb 2, 2021
975711e
Add API docs
jasalisbury Feb 2, 2021
fe19276
Update DB diagram
jasalisbury Feb 2, 2021
58b12ac
Merge branch 'main' into dcloud/test-failure-fixes
dcloud Feb 2, 2021
13ff30f
Simplify networking, remove unused containers per @dcmcand
dcloud Feb 2, 2021
e56cf18
update failing tests
Feb 2, 2021
43ed721
Merge branch 'main' into js-137-manager-approves-report
jasalisbury Feb 2, 2021
486acd4
Add section on caveats with creating/deleting databas records
dcloud Feb 2, 2021
6dee177
Merge branch 'main' into dcloud/test-failure-fixes
dcloud Feb 2, 2021
b14eeb9
Split run-test into multiple steps, per @dcmcand
dcloud Feb 2, 2021
11b92b9
Fix API docs. Split review page into components. Add DECIMAL_BASE
jasalisbury Feb 2, 2021
f698be6
Merge branch 'js-137-manager-approves-report' of github.com:adhocteam…
jasalisbury Feb 2, 2021
25e5f1f
Switch shortcut, also per @dcmcand
dcloud Feb 2, 2021
d227006
Merge branch 'main' into dcloud/split-docker-local-test
dcloud Feb 2, 2021
0a785fd
Merge branch 'main' into 274-allow-case-insensitive-search
gopar Feb 3, 2021
4eadc38
Merge branch 'main' into dcloud/test-failure-fixes
dcloud Feb 3, 2021
b3fb374
Merge branch 'main' into dcloud/test-failure-fixes
dcloud Feb 3, 2021
9e05993
Merge pull request #134 from adhocteam/dcloud/test-failure-fixes
dcloud Feb 3, 2021
b80d852
Merge branch 'main' into dcloud/split-docker-local-test
dcloud Feb 3, 2021
e976f8a
Merge branch 'main' into 274-allow-case-insensitive-search
gopar Feb 3, 2021
db9cb58
Merge pull request #138 from adhocteam/dcloud/split-docker-local-test
dcloud Feb 3, 2021
2956987
Merge branch 'main' into 274-allow-case-insensitive-search
gopar Feb 3, 2021
eb867ac
Merge pull request #137 from adhocteam/274-allow-case-insensitive-search
gopar Feb 3, 2021
75e4df0
Merge branch 'main' into js-137-manager-approves-report
jasalisbury Feb 4, 2021
d31f14f
Merge pull request #139 from adhocteam/js-137-manager-approves-report
jasalisbury Feb 4, 2021
a50285f
Increase wait time for the server to spin up in cucummber ci tests
jasalisbury Feb 4, 2021
ba18d84
Merge pull request #145 from adhocteam/js-increase-ci-cucumber-wait-time
jasalisbury Feb 4, 2021
d29a75d
Document bin/run-tests, make sure frontend tests run in frontend inst…
dcloud Feb 4, 2021
3f47788
Feedback from PR
jasalisbury Feb 4, 2021
c99ba9a
Add frontend tests
jasalisbury Feb 4, 2021
e027cdf
Remove unused import
jasalisbury Feb 4, 2021
c6f62d6
Merge pull request #147 from adhocteam/dcloud/docker-tests-changes-pe…
dcloud Feb 4, 2021
4680a12
Merge branch 'main' into js-manager-notes-feedback
jasalisbury Feb 5, 2021
5a31b94
Merge pull request #148 from adhocteam/js-manager-notes-feedback
jasalisbury Feb 5, 2021
c08eb4c
Somehow service == container_name for docker-compose exec
dcloud Feb 5, 2021
6cf1025
Add param to run-tests to choose to run only frontend or backend test…
dcloud Feb 5, 2021
c4c7bd4
Check exit codes of docker cmds, and 'log' errors. Return exit_code e…
dcloud Feb 5, 2021
68a76de
Merge branch 'main' into dcloud/test-script-improvements
dcloud Feb 5, 2021
f327246
Merge pull request #149 from adhocteam/dcloud/test-script-improvements
dcloud Feb 5, 2021
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 7 additions & 7 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,7 @@ jobs:
- run:
name: Run cucumber
command: |
sleep 5
sleep 10
yarn cucumber:ci
- store_artifacts:
path: reports/
Expand All @@ -240,12 +240,12 @@ jobs:
- run:
name: Start up local server
command: | # production style build (single BE server with static FE)
docker-compose -f docker-compose-test.yml run --rm server yarn install --production=false
docker-compose -f docker-compose-test.yml run --rm server yarn --cwd frontend install --production=false
docker-compose -f docker-compose-test.yml run --rm server yarn build
docker-compose -f docker-compose-test.yml run --rm server yarn --cwd frontend run build
docker-compose -f docker-compose-test.yml up -d
docker-compose -f docker-compose-test.yml exec server yarn db:migrate:ci
docker-compose -f docker-compose.dss.yml run --rm server yarn install --production=false
docker-compose -f docker-compose.dss.yml run --rm server yarn --cwd frontend install --production=false
docker-compose -f docker-compose.dss.yml run --rm server yarn build
docker-compose -f docker-compose.dss.yml run --rm server yarn --cwd frontend run build
docker-compose -f docker-compose.dss.yml up -d
docker-compose -f docker-compose.dss.yml exec server yarn db:migrate:ci
- run:
name: Pull OWASP ZAP docker image
command: docker pull owasp/zap2docker-weekly
Expand Down
77 changes: 77 additions & 0 deletions bin/run-tests
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
#!/bin/bash

declare -a options=(frontend backend)
declare lr=">>>>>>>>"
declare -i exit_code=0

log() {
echo "$lr $*"
}

check_exit() {
if [[ "$1" -ne 0 ]]; then
echo "$lr last docker-compose command failed"
((exit_code++))
fi
}

main() {
local opt=""

for o in "${options[@]}"; do
if [[ "${1}" == "$o" ]]; then
opt="$o";
fi
done

log "Running tests in using test config 'docker-compose.test.yml'"
# Start containers
docker-compose -f 'docker-compose.test.yml' up -d
check_exit "$?"

# Let postgres initialize
echo
log "Giving postgres a few seconds to start up..."
sleep 5

# Migrate and seed db
echo
log "Migrating & seeding db"
docker exec test-backend bash -c "yarn db:migrate"
check_exit "$?"
docker exec test-backend bash -c "yarn db:seed;"
check_exit "$?"

if [[ "$opt" == "backend" || -z "$opt" ]]; then
# Test backend
echo
log "Running backend tests"
docker exec test-backend bash -c "yarn test:ci"
check_exit "$?"
fi

if [[ "$opt" == "frontend" || -z "$opt" ]]; then
# Test frontend
echo
log "Running frontend tests"
docker exec test-frontend bash -c "yarn --cwd frontend run test:ci"
check_exit "$?"
fi

# Cleanup
echo
log "Cleaning up test containers"
docker-compose \
-f 'docker-compose.test.yml' \
down --volumes
check_exit "$?"

if [[ $exit_code -ne 0 ]]; then
echo
log "Errors occurred during script execution"
fi

exit "$exit_code"
}

main "$@"
File renamed without changes.
39 changes: 39 additions & 0 deletions docker-compose.test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
version: "3.5"
services:
test-backend:
build:
context: .
container_name: test-backend
command: yarn server
user: ${CURRENT_USER:-root}
depends_on:
- test-db
environment:
- POSTGRES_HOST=test-db
volumes:
- ".:/app:rw"
networks:
- ttadp-test
test-frontend:
build:
context: .
container_name: test-frontend
command: yarn start
user: ${CURRENT_USER:-root}
stdin_open: true
volumes:
- "./frontend:/app:rw"
- "./scripts:/app/scripts"
environment:
- BACKEND_PROXY=http://test-backend:8080
networks:
- ttadp-test
test-db:
image: postgres:12.4
container_name: test-db
env_file: .env
networks:
- ttadp-test
# Use non-default network so we don't conflict with the developer environment
networks:
ttadp-test:
5 changes: 3 additions & 2 deletions docs/logical_data_model.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Logical Data Model
==================

<img src="http://www.plantuml.com/plantuml/png/nLVRRkCs47tNL_2jRO0OHOkYm29Ox6xgBV9GDqYo7p2M9Z9RYiCEHzaQSVwzffWAeYnd6QkNbmGwSpyyrCZll01BsvZ2bs1GVRluyOUY-4h10-bAEQQrmSQhpres2cnji58bqsUlxX6byBzhwu2XKKPRbAr3HImRAehIWFVgaqTMZuLIPqfNwetILh3UGnSNDLfa4ApUljsRDnvzyBqAJbvOstgFMcXm-EmsP77LDcla8Noci05jXf1eCVX6eMsRa9qQlC5QaxqQDF7rzzzzeswM7vStozNbybQvTcrqkOYEVg6hBdN96BfyB_j0qGrwWSPrbjPL4vQdlqUFUNA6FniDsgUuBSdXAHcKgj2Nh9reiZqwQvnhv4PxdprIwv4ps0w7tdFD9vwH3pnbX7Ly_XCd-qUBNfRCn3w73NBXGPCTdb3BUlZOe6meKJ_7CX-esgQmTsGz7iClgS8UdpaecIdvlIJPEtAwp8_foyIuB6KncPp33bdxivQG_ghwKapNnNo1_4nWyZXGoWj8wuT8I7ZF8pVjFp8rjmsm-0sYt0bS6mY2MXCP13klusxmbzgkzxOCqaEA_ujq1YkOgTVvbOxM6Q-dazzgTHmeX_Ne6GCF1TLj-9z0S3GeskeGdKrCa436HJvbm9IQtBWOTPA6Pt2n8XkxFcM1pol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nVf35OmKw_pAnsjCxwUJZxLwZXG3klHCmQE11KHbfz0S3GeskeGdKrCa43EHZvXm9IQtBWOTPA6Pt2n8XkxFkK2drVwVIdwGSls1Xsnv9HdzDHokN-39NSGL9KMJHRCYWGJLKMX_tf_3Iowr2umdUo52er-GDx-Sd2pLMr_7LPOwWPCeiOmN2BR7e9-igwWHYjtMuSJT-RuVNYu9nnJpT24-803CsmleZKG8i0roZMvrkmxdV9X14zsmk0IHiRcU2nE6WJYF0UMagpWdv8C03NUIcJdDq-sWngm7SZfIfty63FWvLCKseVjl_oIUmwRB_c16FEs7IHx9QFXT7F5nbzr7CKGsnyF6N6htdasKMdxbsGCh8b1YFyhlbuho10otNx-LJEtxHDkaEUsmmHgjpkdHnMb7f4dEZ_VFGv-L1NnjzuX7gEc36Hw__qJgeXlwAVT7Wez554rlLj_FnVXpm4QKouMAlmVf9o6Oj4-smY9XSFaVOddKL8ivJaaEQxGIDsBBb_Cb_Hxp1Gf79cJjHoPqi_49pcJ8Y_1FcqUF1gE-hn3MxMD-Gi0">

UML Source
----------
Expand Down Expand Up @@ -150,6 +150,7 @@ class ActivityReport {
ttaType : array<string>
context : string
pageState : json
managerNotes : string
* userId : integer(32) REFERENCES public.Users.id
* lastUpdatedById : integer(32) REFERENCES public.Users.id
* regionId : integer(32) REFERENCES public.Region.id
Expand Down Expand Up @@ -208,7 +209,7 @@ NonGrantee ||-{ ActivityParticipant
Instructions
------------

1. [Edit this diagram with plantuml.com](http://www.plantuml.com/plantuml/uml/nLVRRkCs47tNL_2jRO0OHOkYm29Ox6xgBV9GDqYo7p2M9Z9RYiCEHzaQSVwzffWAeYnd6QkNbmGwSpyyrCZll01BsvZ2bs1GVRluyOUY-4h10-bAEQQrmSQhpres2cnji58bqsUlxX6byBzhwu2XKKPRbAr3HImRAehIWFVgaqTMZuLIPqfNwetILh3UGnSNDLfa4ApUljsRDnvzyBqAJbvOstgFMcXm-EmsP77LDcla8Noci05jXf1eCVX6eMsRa9qQlC5Qaxq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TAcBPK56K1hnNdpooUYoKEbDTjZTAMy6wWoukQhJ885YzVTkPDnvzyBqAJbvOsxf3BJGu_7ORihXgcpNo43vJs80sGqYq67oZqBPDo4uDtc2joLuDclZw----KJVBZykRvUfoUQjSkpQwN4H7lz3LFdN96BfyBrsWw0QzGEFsbjPL4vQdlqUFUNA6FniDsgUuBSdXAHcKgj2Nh9reiZqwQvnhv4PxdprIwv4ps0wBtdFD9wwH3pnbXEtv_2TMze-smvRCn3w73NBXGvCThb3BUlZPe6meKJ_7CX-esgQmTsGz7iClgS8UdpaecIdvlIJPEtAwp8_foyIuB6KncPp53bdxjPQG_ghwKio-Y_a2-Pd0v76Wb1UGrW-HaF2UHsxQVsHgRXjWyHj4kHEuDX04jIOo27PMnt7PNcgxxcmPf8SK_nVf35OmKw_pAnsjCxwUJZxLwZXG3klHCmQE11KHbfz0S3GeskeGdKrCa43EHZvXm9IQtBWOTPA6Pt2n8XkxFkK2drVwVIdwGSls1Xsnv9HdzDHokN-39NSGL9KMJHRCYWGJLKMX_tf_3Iowr2umdUo52er-GDx-Sd2pLMr_7LPOwWPCeiOmN2BR7e9-igwWHYjtMuSJT-RuVNYu9nnJpT24-803CsmleZKG8i0roZMvrkmxdV9X14zsmk0IHiRcU2nE6WJYF0UMagpWdv8C03NUIcJdDq-sWngm7SZfIfty63FWvLCKseVjl_oIUmwRB_c16FEs7IHx9QFXT7F5nbzr7CKGsnyF6N6htdasKMdxbsGCh8b1YFyhlbuho10otNx-LJEtxHDkaEUsmmHgjpkdHnMb7f4dEZ_VFGv-L1NnjzuX7gEc36Hw__qJgeXlwAVT7Wez554rlLj_FnVXpm4QKouMAlmVf9o6Oj4-smY9XSFaVOddKL8ivJaaEQxGIDsBBb_Cb_Hxp1Gf79cJjHoPqi_49pcJ8Y_1FcqUF1gE-hn3MxMD-Gi0)
2. Copy and paste the final UML into the UML Source section
3. Update the img src and edit link target to the current values

Expand Down
46 changes: 46 additions & 0 deletions docs/openapi/paths/activity-reports/review.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
put:
tags:
- activity-reports
summary: Review an activity report
description: >
An approving manager reviews an activity report to determine if it requires
any additional updates. If the report needs updates the manager sets the status to
'Needs Action', otherwise to 'Approved'
requestBody:
description: The status and any manager notes
required: true
content:
application/json:
schema:
type: object
properties:
status:
type: string
description: The status of the report after review
enum:
- Approved
- Needs Action
managerNotes:
type: string
description: Any notes the manager needs to relay to the author/collaborators of the report
parameters:
- in: path
name: activityReportId
required: true
schema:
type: number
responses:
200:
description: The new status of the activity report
content:
application/json:
schema:
type: object
properties:
status:
type: string
enum:
- Approved
- Needs Action
managerNotes:
type: string
2 changes: 1 addition & 1 deletion docs/openapi/paths/collaborators.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,4 @@ get:
schema:
type: array
items:
$ref: '../../index.yaml#/components/schemas/selectableUser'
$ref: '../index.yaml#/components/schemas/selectableUser'
2 changes: 2 additions & 0 deletions docs/openapi/paths/index.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -22,5 +22,7 @@
$ref: './activity-reports/activity-reports-id.yaml'
'/activity-reports/{activityReportId}/submit':
$ref: './activity-reports/submit.yaml'
'/activity-reports/{activityReportId}/review':
$ref: './activity-reports/review.yaml'
'/files':
$ref: './files.yaml'
48 changes: 48 additions & 0 deletions docs/testing.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
# Testing

## Tips and Caveats when writing tests


### Handling async/promises

When writing tests that rely on asynchronous operations, such as writing to the database, take care to make sure that those operations are resolved before any tests that rely on them run. If you need to create database records in a setup function such as `beforeAll`, you will want to make sure all async/promise operations resolve before subsequent tests run. You can make sure multiple await (promise) operations resolve by using [`Promise.all()`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise/all) (which takes an iterable of promises).

Here's how that might look:

```
let a = someAsyncFun();
let b = anotherAsyncFun();

return Promise.all([a, b]);
```

### Creating/deleting database records

Some tests will require interactions with the database, but at present all tests run using the same instance of the database. That means that any records you create or delete can potentially affect tests elsewhere. On top of that, tests run in parallel, so database operations may run in an unexpected order. That can mean tests may pass various times only to fail due to missing or unexpected records in the database when your tests run.

To mitigate issues with missing or unexpected records causing failing tests, you can try a few approaches. One approach is to avoid using the database if your test doesn't actually require it. You may be able to use mock models or responses rather than interact with the database. If your test does require the database, you should create the records you need before your tests run and delete the records you created (and no others) when your tests finish. If you `Model.create`, make sure you `Model.destroy()` the records you created.

When writing tests that create database records, it might also help to use a `try...catch` to catch errors in database transactions and log meaningful output. Sequelize error messages can be vague, and it might help others to see more informative messages.

## Testing in Docker

### Using `./bin/run-tests`

To simplify running tests in Docker, there is a bash script, `./bin/run-tests` that will run the appropriate commands to start `test-` variations of the services used in tests. You should be able to run tests using that command while your development Docker environment is running. The script uses a separate `docker-compose.test.yml` which does not create a user-accessible network and cleans up after itself once tests have run.

This script is written such that it will log errors, but won't exit if a docker command fails. It will count the number of errors and the number of errors will be the exit code (`$?`) for the script. So if three docker commands fail, the exit code would be 3.

By default, `./bin/run-tests` will run both backend and frontend tests. If you want to run only one set of tests, supply 'frontend' or 'backend' as a parameter. So to run only the backend tests, you'd run `./bin/run-tests backend`.

### Running tests in your development Docker environment

When running tests in Docker, be aware that there are tests that will modify/delete database records. For tests to run, the 'db' service needs to exist and `db:migrate` and `db:seed` need to have been run (to create the tables and populate certain records).

In the `docker-compose.yml` configuration, the database is set up to persist to a volume, "dbdata", so database records will persist between runs of the 'db' service, unless you remove that volume explicitly (e.g. `docker volume rm` or `docker-compose down --volumes`).

rahearn marked this conversation as resolved.
Show resolved Hide resolved

### Notes on docker-compose and multiple configurations

`docker-compose` has a feature for providing multiple `docker-compose.*.yml` files where subsequent files can override settings in previous files, which sounds like it would suit the use case of running docker for local development and for testing. However, the ability to [override configurations](https://docs.docker.com/compose/extends/#adding-and-overriding-configuration) is limited. While experimenting with overrides, it became clear that doing so would require a minimum of three docker-compose.yml files: one "base", one for local development, one for running tests. Trying to compose docker-compose.yml files would be complicated.

In addition, while experimenting with multiple configuration files, it became clear that docker was unable to differentiate between different versions of the same service. Trying to override the 'db' service for testing would not work as expected: if the local/dev 'db' service had already been created, that one would be used when tests were run.
4 changes: 2 additions & 2 deletions frontend/src/App.js
Original file line number Diff line number Diff line change
Expand Up @@ -75,8 +75,8 @@ function App() {
/>
<Route
path="/activity-reports/:activityReportId/:currentPage?"
render={({ match }) => (
<ActivityReport match={match} />
render={({ match, location }) => (
<ActivityReport location={location} match={match} user={user} />
)}
/>
{admin
Expand Down
2 changes: 2 additions & 0 deletions frontend/src/Constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,3 +64,5 @@ export const REGIONS = [
11,
12,
];

export const DECIMAL_BASE = 10;
5 changes: 4 additions & 1 deletion frontend/src/components/Navigator/__tests__/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ const pages = [
label: 'review page',
path: 'review',
review: true,
render: (hookForm, allComplete, formData, submitted, onSubmit) => (
render: (hookForm, allComplete, formData, onSubmit) => (
<div>
<button type="button" data-testid="review" onClick={onSubmit}>Continue</button>
</div>
Expand All @@ -59,6 +59,9 @@ describe('Navigator', () => {
<Navigator
submitted={false}
initialData={initialData}
status="draft"
onReview={() => {}}
approvingManager={false}
defaultValues={{ first: '', second: '' }}
pages={pages}
currentPage={currentPage}
Expand Down
7 changes: 6 additions & 1 deletion frontend/src/components/Navigator/components/SideNav.css
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,13 @@
color: #f8f8f8;
}

.smart-hub--tag-needs-action {
background-color: #f9e0e4;
color: #d42240;
}

.smart-hub--tag {
width: 84px;
width: 94px;
text-align: center;
font-weight: normal;
display: inline-block;
Expand Down
8 changes: 6 additions & 2 deletions frontend/src/components/Navigator/components/SideNav.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import moment from 'moment';
import Container from '../../Container';
import './SideNav.css';
import {
NOT_STARTED, IN_PROGRESS, COMPLETE, SUBMITTED,
NOT_STARTED, IN_PROGRESS, COMPLETE, SUBMITTED, APPROVED, NEEDS_ACTION,
} from '../constants';

const tagClass = (state) => {
Expand All @@ -26,6 +26,10 @@ const tagClass = (state) => {
return 'smart-hub--tag-complete';
case SUBMITTED:
return 'smart-hub--tag-submitted';
case APPROVED:
return 'smart-hub--tag-submitted';
case NEEDS_ACTION:
return 'smart-hub--tag-needs-action';
default:
return '';
}
Expand All @@ -46,7 +50,7 @@ function SideNav({
>
<span className="margin-left-2">{page.label}</span>
<span className="margin-left-auto margin-right-2">
{page.state
{page.state !== 'draft'
&& (
<Tag className={`smart-hub--tag ${tagClass(page.state)}`}>
{page.state}
Expand Down
2 changes: 2 additions & 0 deletions frontend/src/components/Navigator/constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,5 @@ export const NOT_STARTED = 'Not started';
export const IN_PROGRESS = 'In progress';
export const COMPLETE = 'Complete';
export const SUBMITTED = 'Submitted';
export const APPROVED = 'Approved';
export const NEEDS_ACTION = 'Needs Action';
Loading