-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: geo 656 user management screen (#552)
Co-authored-by: Sukanya Rath <98050194+sukanya-rath@users.noreply.github.com>
- Loading branch information
1 parent
b768e39
commit 6396a05
Showing
32 changed files
with
741 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,142 @@ | ||
<template>User Management placeholder</template> | ||
<template> | ||
<div v-if="loading" class="loader-root"> | ||
<v-progress-circular color="primary" indeterminate></v-progress-circular> | ||
<span class="mt-2">Loading users</span> | ||
</div> | ||
<div v-if="!loading && users !== undefined" class="main-root"> | ||
<div class="toolbar"> | ||
<div class="title">Users ({{ users.length }})</div> | ||
<span style="flex: 1 1 auto" /> | ||
<v-btn prepend-icon="mdi-account-plus" color="primary" variant="elevated" | ||
>Add New User</v-btn | ||
> | ||
</div> | ||
<v-row class="users-grid" no-gutters> | ||
<v-col | ||
class="user-card-wrapper" | ||
cols="12" | ||
sm="12" | ||
md="3" | ||
v-for="user of users" | ||
> | ||
<v-card class="pa-4 ma-2 user-card"> | ||
<div class="actions d-flex"> | ||
<v-avatar color="primary"> | ||
<span class="text-h6">{{ getUserInitials(user) }}</span> | ||
</v-avatar> | ||
<span style="flex: 1 1 auto" /> | ||
|
||
<script lang="ts"></script> | ||
<v-btn | ||
density="compact" | ||
variant="text" | ||
color="error" | ||
icon="mdi-trash-can-outline" | ||
aria-label="Delete user" | ||
></v-btn> | ||
</div> | ||
<div class="display-name mt-2"> | ||
{{ user.displayName }} | ||
</div> | ||
<v-menu location="bottom"> | ||
<template v-slot:activator="{ props }"> | ||
<v-btn | ||
color="primary" | ||
variant="text" | ||
append-icon="mdi-chevron-down" | ||
class="role-menu-button" | ||
:aria-label="`Role ${RoleLabels[user.role]}`" | ||
v-bind="props" | ||
>{{ RoleLabels[user.role] }}</v-btn | ||
> | ||
</template> | ||
|
||
<style></style> | ||
<v-list> | ||
<v-list-item | ||
:variant="user.role === item.value ? 'tonal' : 'plain'" | ||
v-for="(item, index) in RoleOptions" | ||
:key="index" | ||
:class="user.role === item.value ? 'selected-role' : undefined" | ||
> | ||
<v-list-item-title v-text="item.label"></v-list-item-title> | ||
<template v-slot:append v-if="user.role === item.value"> | ||
<v-icon size="x-small" icon="mdi-check" /> | ||
</template> | ||
</v-list-item> | ||
</v-list> | ||
</v-menu> | ||
</v-card> | ||
</v-col> | ||
</v-row> | ||
</div> | ||
</template> | ||
|
||
<script setup lang="ts"> | ||
import { storeToRefs } from 'pinia'; | ||
import { onMounted } from 'vue'; | ||
import { useUsersStore } from '../store/modules/usersStore'; | ||
import { RoleOptions, RoleLabels } from '../constants'; | ||
const usersStore = useUsersStore(); | ||
const { users, loading } = storeToRefs(usersStore); | ||
const getUserInitials = (user) => { | ||
const tokens = user.displayName.split(' '); | ||
return `${tokens[0][0]}${tokens[1][0]}`; | ||
}; | ||
onMounted(async () => { | ||
await usersStore.getUsers(); | ||
}); | ||
</script> | ||
|
||
<style scoped lang="scss"> | ||
.loader-root { | ||
width: 100%; | ||
height: calc(100vh - 200px); | ||
display: flex; | ||
align-items: center; | ||
justify-content: center; | ||
flex-direction: column; | ||
} | ||
.main-root { | ||
width: 100%; | ||
min-height: calc(100vh - 200px); | ||
display: flex; | ||
flex-direction: column; | ||
.toolbar { | ||
width: 100%; | ||
display: flex; | ||
flex-direction: row; | ||
margin-bottom: 10px; | ||
.title { | ||
font-weight: bold; | ||
font-size: large; | ||
} | ||
} | ||
} | ||
.users-grid { | ||
flex: none; | ||
.user-card-wrapper { | ||
.user-card { | ||
.actions { | ||
width: 100%; | ||
} | ||
.display-name { | ||
font-weight: 700; | ||
color: #000; | ||
} | ||
} | ||
} | ||
} | ||
.role-menu-button { | ||
padding: 5px; | ||
padding-right: 5px; | ||
} | ||
.selected-role { | ||
color: #003366; | ||
font-weight: 600; | ||
} | ||
</style> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
104 changes: 104 additions & 0 deletions
104
admin-frontend/src/components/__tests__/UserManagementPage.spec.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,104 @@ | ||
import { vi, beforeEach, describe, it, expect } from 'vitest'; | ||
import UserManagementPage from '../UserManagementPage.vue'; | ||
import { createVuetify } from 'vuetify'; | ||
import * as components from 'vuetify/components'; | ||
import * as directives from 'vuetify/directives'; | ||
import { createTestingPinia } from '@pinia/testing'; | ||
import { useUsersStore } from '../../store/modules/usersStore'; | ||
import { render, waitFor, fireEvent } from '@testing-library/vue'; | ||
|
||
global.ResizeObserver = require('resize-observer-polyfill'); | ||
|
||
const mockGetUsers = vi.fn(); | ||
vi.mock('../../../services/apiService', () => ({ | ||
default: { | ||
getUsers: () => mockGetUsers(), | ||
}, | ||
})); | ||
|
||
const vuetify = createVuetify({ | ||
components, | ||
directives, | ||
}); | ||
|
||
const pinia = createTestingPinia({ | ||
initialState: {}, | ||
}); | ||
|
||
const wrappedRender = () => { | ||
return render(UserManagementPage, { | ||
global: { | ||
plugins: [pinia, vuetify], | ||
}, | ||
}); | ||
}; | ||
|
||
const store = useUsersStore(); | ||
|
||
describe('UserManagementPage', () => { | ||
beforeEach(() => { | ||
store.$patch({ | ||
loading: false, | ||
users: [], | ||
}); | ||
}); | ||
|
||
it('should display loading spinner', async () => { | ||
const wrapper = await wrappedRender(); | ||
store.$patch({ | ||
loading: true, | ||
users: [], | ||
}); | ||
|
||
await waitFor(() => { | ||
wrapper.getByText('Loading users'); | ||
}); | ||
}); | ||
it('should add user button', async () => { | ||
const wrapper = await wrappedRender(); | ||
store.$patch({ | ||
loading: false, | ||
users: [], | ||
}); | ||
|
||
await waitFor(() => { | ||
wrapper.getByRole('button', { name: 'Add New User' }); | ||
}); | ||
}); | ||
it('should display the number of users found', async () => { | ||
const wrapper = await wrappedRender(); | ||
store.$patch({ | ||
loading: false, | ||
users: [ | ||
{ | ||
userName: 'testusername', | ||
displayName: 'Test display name', | ||
role: 'PTRT-ADMIN', | ||
}, | ||
], | ||
}); | ||
|
||
await waitFor(() => { | ||
wrapper.getByText('Users (1)'); | ||
}); | ||
}); | ||
it('should user cards', async () => { | ||
const wrapper = await wrappedRender(); | ||
store.$patch({ | ||
loading: false, | ||
users: [ | ||
{ | ||
userName: 'testusername', | ||
displayName: 'Test Display FIN:EX', | ||
role: 'PTRT-ADMIN', | ||
}, | ||
], | ||
}); | ||
|
||
await waitFor(() => { | ||
expect(wrapper.getByRole('button', { name: 'Delete user' })); | ||
expect(wrapper.getByText('Test Display FIN:EX')).toBeInTheDocument(); | ||
expect(wrapper.getByRole('button', { name: 'Role Manager' })); | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
export const ADMIN_ROLE_NAME = 'PTRT-ADMIN'; | ||
export const USER_ROLE_NAME = 'PTRT-USER'; | ||
|
||
export const RoleLabels = { | ||
'PTRT-ADMIN': 'Manager', | ||
'PTRT-USER': 'User' | ||
} | ||
|
||
export const RoleOptions = [ | ||
{ label: RoleLabels['PTRT-ADMIN'], value: 'PTRT-ADMIN' }, | ||
{ label: RoleLabels['PTRT-USER'], value: 'PTRT-USER' }, | ||
]; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.