Skip to content
This repository was archived by the owner on Sep 3, 2025. It is now read-only.

Commit 470e36c

Browse files
authored
Only display active roles in CaseParticipantsTab component, add Vitest, and unit test(s) (#2960)
* Change commaSeperated filter to only show active participant roles * Add vitest and add unit tests for ParticipantsTab * Try running w/o coverage to resolve error * try to update various componenets in gh actions workflow * add another test case for renouncedRoles not being displayed * Run coverage again * Fix tests to actually test things * Only display active participant roles for incidents * correctly import component * remove debug log lines
1 parent e580795 commit 470e36c

File tree

9 files changed

+3610
-1017
lines changed

9 files changed

+3610
-1017
lines changed

.github/workflows/javascript.yml

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,11 @@ jobs:
88

99
steps:
1010
- name: Check out Git repository
11-
uses: actions/checkout@v2
11+
uses: actions/checkout@v3
1212
- name: Setup Node.js environment
13-
uses: actions/setup-node@v1
13+
uses: actions/setup-node@v3
1414
with:
15-
node-version: '12'
15+
node-version: 16
1616
- name: Install dev deps
1717
working-directory: src/dispatch/static/dispatch
1818
run: |
@@ -21,3 +21,7 @@ jobs:
2121
working-directory: src/dispatch/static/dispatch
2222
run: |
2323
npm run lint
24+
- name: Run Vitest
25+
working-directory: src/dispatch/static/dispatch
26+
run: |
27+
npm run test:coverage

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -211,3 +211,5 @@ docker/.env
211211
/playwright-report/
212212
/playwright/.cache/
213213
/tests/static/e2e/artifacts/*
214+
src/dispatch/static/dispatch/tests/__snapshots__
215+
src/dispatch/static/dispatch/coverage

src/dispatch/static/dispatch/package-lock.json

Lines changed: 3477 additions & 987 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/dispatch/static/dispatch/package.json

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,13 @@
44
"private": true,
55
"scripts": {
66
"serve": "cross-env NODE_ENV=dev NODE_OPTIONS='--max-http-header-size=100000' vite",
7-
"preview": "vite preview --open --port 8080",
87
"build": "vite build --out-dir dist",
8+
"test:unit": "vue-cli-service test:unit",
99
"lint": "eslint src",
10-
"lint:fix": "eslint src --fix"
10+
"lint:fix": "eslint src --fix",
11+
"preview": "vite preview --open --port 8080",
12+
"test": "vitest",
13+
"test:coverage": "vitest run --coverage"
1114
},
1215
"dependencies": {
1316
"@json2csv/plainjs": "^6.1.1",
@@ -42,25 +45,30 @@
4245
"devDependencies": {
4346
"@mdi/font": "^5.9.55",
4447
"@playwright/test": "^1.30.0",
45-
"@vitejs/plugin-vue2": "^2.0.0",
48+
"@vitejs/plugin-vue2": "^2.2.0",
49+
"@vitest/coverage-c8": "^0.28.4",
50+
"@vitest/coverage-istanbul": "^0.28.4",
4651
"@vue/compiler-sfc": "^3.0.11",
52+
"@vue/test-utils": "^1.3.4",
4753
"babel-runtime": "^6.26.0",
4854
"cross-env": "^7.0.3",
4955
"eslint": "^8.26.0",
5056
"eslint-config-prettier": "^8.5.0",
5157
"eslint-plugin-prettier": "^4.2.1",
5258
"eslint-plugin-vue": "^9.7.0",
5359
"jquery": "^3.6.0",
60+
"jsdom": "^21.1.0",
5461
"jwt-decode": "^3.1.2",
5562
"prettier": "^2.7.1",
5663
"sass": "~1.32.12",
5764
"stylus": "^0.54.8",
5865
"stylus-loader": "^3.0.2",
5966
"unplugin-vue-components": "^0.22.9",
60-
"vite": "^3.2.1",
67+
"vite": "^4.0.0",
6168
"vite-plugin-babel": "^1.1.2",
6269
"vite-plugin-eslint": "^1.8.1",
6370
"vite-plugin-monaco-editor": "^1.1.0",
71+
"vitest": "^0.28.4",
6472
"vue-cli-plugin-vuetify": "^2.3.1",
6573
"vue-template-compiler": "^2.6.12",
6674
"vuetify-loader": "^1.7.2",

src/dispatch/static/dispatch/src/case/ParticipantsTab.vue

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@
44
<span v-for="participant in participants" :key="participant.id">
55
<v-list-item :href="participant.individual.weblink" target="_blank">
66
<v-list-item-content>
7-
<v-list-item-title>
7+
<v-list-item-title ref="participants">
88
{{ participant.individual.name }} ({{
9-
participant.participant_roles | commaSeparatedRoles
9+
participant.participant_roles | activeRoles
1010
}})
1111
</v-list-item-title>
1212
<v-list-item-subtitle>
@@ -37,15 +37,5 @@ export default {
3737
computed: {
3838
...mapFields("case_management", ["selected.participants"]),
3939
},
40-
41-
filters: {
42-
commaSeparatedRoles: function (value) {
43-
return value
44-
.map(function (v) {
45-
return v.role
46-
})
47-
.join(", ")
48-
},
49-
},
5040
}
5141
</script>

src/dispatch/static/dispatch/src/filters.js

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,3 +104,16 @@ Vue.filter("commaString", function (value, key) {
104104
.join(", ")
105105
}
106106
})
107+
108+
export const activeRoles = function (value) {
109+
if (value) {
110+
return value
111+
.filter((role) => !role.renounced_at)
112+
.map(function (role) {
113+
return role.role
114+
})
115+
.join(", ")
116+
}
117+
}
118+
119+
Vue.filter("activeRoles", activeRoles)

src/dispatch/static/dispatch/src/incident/ParticipantsTab.vue

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
<v-list-item-content>
77
<v-list-item-title>
88
{{ participant.individual.name }} ({{
9-
participant.participant_roles | commaSeparatedRoles
9+
participant.participant_roles | activeRoles
1010
}})
1111
</v-list-item-title>
1212
<v-list-item-subtitle>
@@ -37,15 +37,5 @@ export default {
3737
computed: {
3838
...mapFields("incident", ["selected.participants"]),
3939
},
40-
41-
filters: {
42-
commaSeparatedRoles: function (value) {
43-
return value
44-
.map(function (v) {
45-
return v.role
46-
})
47-
.join(", ")
48-
},
49-
},
5040
}
5141
</script>
Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
/**
2+
* @vitest-environment jsdom
3+
*/
4+
5+
import { describe, expect, it, vi } from "vitest"
6+
import { createLocalVue, shallowMount } from "@vue/test-utils"
7+
import CaseParticipantsTab from "src/case/ParticipantsTab.vue"
8+
import { activeRoles } from "src/filters"
9+
10+
describe("CaseParticipantsTab", () => {
11+
const localVue = createLocalVue()
12+
localVue.filter("activeRoles", activeRoles)
13+
14+
vi.mock("vuex-map-fields", () => ({
15+
getterType: vi.fn(),
16+
mapFields: vi.fn(),
17+
}))
18+
19+
const participants = [
20+
{
21+
id: 1,
22+
individual: {
23+
name: "John Doe",
24+
weblink: "https://example.com/john-doe",
25+
},
26+
participant_roles: [
27+
{ role: "Participant", renounced_at: null },
28+
{ role: "Reporter", renounced_at: "2022-01-01T00:00:00.000Z" },
29+
],
30+
team: "Team A",
31+
location: "Location A",
32+
},
33+
{
34+
id: 2,
35+
individual: {
36+
name: "Jane Doe",
37+
weblink: "https://example.com/jane-doe",
38+
},
39+
participant_roles: [{ role: "Assignee", renounced_at: null }],
40+
team: "Team B",
41+
location: "Location B",
42+
},
43+
]
44+
45+
const computed = {
46+
participants: () => participants,
47+
}
48+
49+
it("assert if there's participants that we render them", () => {
50+
const wrapper = shallowMount(CaseParticipantsTab, { localVue, computed })
51+
const participantListItems = wrapper.findAll("v-list-item-title").wrappers
52+
expect(participantListItems).to.have.lengthOf(2)
53+
})
54+
55+
it("displays active roles", () => {
56+
const wrapper = shallowMount(CaseParticipantsTab, { localVue, computed })
57+
const participantListItems = wrapper.findAll("v-list-item-title").wrappers
58+
59+
participantListItems.forEach((participantListItem, index) => {
60+
const participant = participants[index]
61+
const activeRoles = participant.participant_roles
62+
.filter((role) => !role.renounced_at)
63+
.map((role) => role.role)
64+
.join(", ")
65+
66+
expect(participantListItem.text()).to.include(activeRoles)
67+
})
68+
})
69+
70+
it("does not display renounced roles", () => {
71+
const wrapper = shallowMount(CaseParticipantsTab, { localVue, computed })
72+
const participantListItems = wrapper.findAll("v-list-item-title").wrappers
73+
74+
participantListItems.forEach((participantListItem, index) => {
75+
const participant = participants[index]
76+
const renouncedRoles = participant.participant_roles
77+
.filter((role) => role.renounced_at)
78+
.map((role) => role.role)
79+
.join(", ")
80+
81+
if (renouncedRoles) {
82+
expect(participantListItem.text()).to.not.include(renouncedRoles)
83+
}
84+
})
85+
})
86+
})
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
import { defineConfig } from "vite"
2+
import vue from "@vitejs/plugin-vue2"
3+
4+
// https://vitejs.dev/config/
5+
export default defineConfig({
6+
plugins: [vue()],
7+
test: {
8+
globals: true,
9+
},
10+
})

0 commit comments

Comments
 (0)