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

Unit tests - Applications and Messaging Views #94

Draft
wants to merge 12 commits into
base: main
Choose a base branch
from
Prev Previous commit
Next Next commit
merge main
vietle-cgi committed Feb 6, 2024
commit 0958c0d888b42b21262fb6d86d0934264f037c9c
32 changes: 0 additions & 32 deletions frontend/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

51 changes: 31 additions & 20 deletions frontend/src/components/account-mgmt/EditFacilityContacts.vue
Original file line number Diff line number Diff line change
@@ -34,16 +34,13 @@
label="Select contact to add"
density="compact"
variant="outlined"
@update:modelValue="addContact">
</v-autocomplete>
@update:modelValue="addContact"
:error-messages="errorMessage"></v-autocomplete>
</v-col>
</v-row>
<v-row>
<v-col class="pt-2">
<v-data-table
:headers="headers"
:items="sortedContacts"
density="compact">
<v-data-table :headers="headers" :items="sortedContacts" density="compact">
<template v-slot:item.name="{ item }">
{{ `${item.firstName} ${item.lastName}` }}
</template>
@@ -98,19 +95,24 @@ export default {
},
title: {
type: String,
required: true
required: true,
},
titleInfo: {
type: String,
required: true
required: true,
},
contacts: {
type: Array,
required: true
required: true,
},
contactsForAdd: {
type: Array,
required: true
required: true,
},
atLeastOneContactMandatory: {
type: Boolean,
required: false,
default: false,
},
},
emits: ['save-contact-updates'],
@@ -127,8 +129,10 @@ export default {
headers: [
{ title: 'Name', value: 'name', width: '20%' },
{ title: 'Role', value: 'role', width: '30%' },
{ title: '', value: 'actions', width: '50%' }
{ title: '', value: 'actions', width: '50%' },
],
errorMessage: '',
atLeastOneContactRules: [(v) => !!v || 'At least one expense authority is required for a facility.'],
}
},
computed: {
@@ -173,10 +177,13 @@ export default {
* NOTE: This is a workaround for the autocomplete component not triggering update event until the input loses focus.
*/
removeFocus() {
const autoComplete = this.$refs.autoComplete;
const autoComplete = this.$refs.autoComplete
if (autoComplete) {
autoComplete.focus();
autoComplete.blur();
autoComplete.focus()
autoComplete.blur()
if (this.contactsToDisplay?.length > 0) {
this.errorMessage = ''
}
}
},

@@ -187,10 +194,10 @@ export default {
if (!this.contactId) {
return
}
const contactToAdd = this.contactsAvailableForAdd.find(item => item.contactId === this.contactId)
const contactToAdd = this.contactsAvailableForAdd.find((item) => item.contactId === this.contactId)
this.contactsToDisplay.push(contactToAdd)
this.updatedContactsToAdd.push(contactToAdd)
this.contactsAvailableForAdd = this.contactsAvailableForAdd.filter(obj => obj.contactId !== contactToAdd.contactId);
this.contactsAvailableForAdd = this.contactsAvailableForAdd.filter((obj) => obj.contactId !== contactToAdd.contactId)
this.contactId = null
this.removeFocus()
},
@@ -199,7 +206,7 @@ export default {
* Remove a contact from the list of contacts to display and add to the list of contacts available for add
*/
deleteContact(contact) {
this.contactsToDisplay = this.contactsToDisplay.filter(obj => obj.contactId !== contact.contactId);
this.contactsToDisplay = this.contactsToDisplay.filter((obj) => obj.contactId !== contact.contactId)
this.updatedContactsToRemove.push(contact)
this.contactsAvailableForAdd = [...this.contactsAvailableForAdd, contact]
},
@@ -214,14 +221,19 @@ export default {
this.updatedContactsToRemove = []
this.contactId = null
this.editMode = false
this.errorMessage = ''
},

/**
* Send emit to save the updated contacts to add and remove
*/
saveContactsToUpdate() {
this.$emit('save-contact-updates', this.updatedContactsToAdd, this.updatedContactsToRemove)
this.editMode = false
if (this.atLeastOneContactMandatory && this.contactsToDisplay?.length === 0) {
this.errorMessage = 'At least one expense authority is required'
} else {
this.$emit('save-contact-updates', this.updatedContactsToAdd, this.updatedContactsToRemove)
this.editMode = false
}
},

/**
@@ -238,4 +250,3 @@ export default {
},
}
</script>

4 changes: 3 additions & 1 deletion frontend/src/views/account-mgmt/ManageFacilityView.vue
Original file line number Diff line number Diff line change
@@ -129,6 +129,7 @@
titleInfo="(You can have more than one expense authority)"
:contacts="expenseAuthorities"
:contactsForAdd="expenseAuthoritiesAvailableForAdd"
:atLeastOneContactMandatory="true"
@save-contact-updates="saveExpenseAuthorityUpdates" />
<EditFacilityContacts
:loading="loading"
@@ -148,6 +149,7 @@
</template>

<script>
import AppButton from '@/components/ui/AppButton.vue'
import AppBackButton from '@/components/ui/AppBackButton.vue'
import AppLabel from '@/components/ui/AppLabel.vue'
import FacilityInfo from '@/components/facilities/FacilityInfo.vue'
@@ -164,7 +166,7 @@ import ContactInfo from '@/components/applications/ContactInfo.vue'

export default {
name: 'ManageFacilityView',
components: { AppBackButton, AppLabel, FacilityInfo, EditFacilityContacts, ContactInfo },
components: { AppButton, AppBackButton, AppLabel, FacilityInfo, EditFacilityContacts, ContactInfo },
mixins: [alertMixin],
data() {
return {
17 changes: 9 additions & 8 deletions frontend/src/views/account-mgmt/ManageUsersView.vue
Original file line number Diff line number Diff line change
@@ -87,6 +87,7 @@
<script>
import { mapState } from 'pinia'
import { useAppStore } from '@/stores/app'
import AppButton from '@/components/ui/AppButton.vue'
import AppBackButton from '@/components/ui/AppBackButton.vue'
import { useAuthStore } from '@/stores/auth'
import rolesMixin from '@/mixins/rolesMixin.js'
@@ -98,7 +99,7 @@ import ManageUserDialog from '@/components/account-mgmt/ManageUserDialog.vue'
import DeactivateUserDialog from '@/components/account-mgmt/DeactivateUserDialog.vue'

export default {
components: { AppBackButton, ManageUserDialog, DeactivateUserDialog },
components: { AppButton, AppBackButton, ManageUserDialog, DeactivateUserDialog },
mixins: [rolesMixin, alertMixin],
data() {
return {
@@ -291,28 +292,28 @@ export default {

/**
* Get the last expense authority facility names for a user
*/
*/
getLastExpenseAuthoritiesForUser(user) {
// Find target users's facilities that are marked as isExpenseAuthority
const targetFacilities = user.facilities.filter(f => f.isExpenseAuthority) || []
const targetFacilities = user.facilities.filter((f) => f.isExpenseAuthority) || []
// If no facilities with isExpenseAuthority true, return false
if (targetFacilities.length === 0) {
return { isLastExpenseAuthority: false, facilityNames: [] }
}
const lastExpenseAuthorityFacilityNames = []
// Check for each of the target's facilities with isExpenseAuthority true
targetFacilities.forEach(facility => {
targetFacilities.forEach((facility) => {
// Check if any other user has a facility with the same facilityId and isExpenseAuthority true
const hasOtherUserWithAuthority = this.usersAndFacilities.some(userToCheck =>
userToCheck.contactId !== user.contactId &&
userToCheck.facilities.some(f => f.facilityId === facility.facilityId && f.isExpenseAuthority))
const hasOtherUserWithAuthority = this.usersAndFacilities.some(
(userToCheck) => userToCheck.contactId !== user.contactId && userToCheck.facilities.some((f) => f.facilityId === facility.facilityId && f.isExpenseAuthority),
)
if (!hasOtherUserWithAuthority) {
lastExpenseAuthorityFacilityNames.push(facility.facilityName)
}
})
return lastExpenseAuthorityFacilityNames
},
}
},
}
</script>

You are viewing a condensed version of this merge commit. You can view the full changes here.