Skip to content

Commit a811305

Browse files
committed
test improvements
1 parent 2cfc256 commit a811305

File tree

2 files changed

+19
-81
lines changed

2 files changed

+19
-81
lines changed

common/src/models/identity/roles.spec.ts

Lines changed: 15 additions & 77 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import { describe, expect, it } from 'vitest'
22
import { AVAILABLE_ROLES, getAllRoleDefinitions, getRoleDefinition } from './roles.js'
3-
import type { Roles } from './user.js'
43

54
describe('roles', () => {
65
describe('AVAILABLE_ROLES', () => {
@@ -30,86 +29,25 @@ describe('roles', () => {
3029
}
3130
})
3231

33-
it('should have correct metadata for admin role', () => {
34-
expect(AVAILABLE_ROLES.admin).toEqual({
35-
displayName: 'Application Admin',
36-
description: 'Full system access including user management and all settings',
37-
})
38-
})
39-
40-
it('should have correct metadata for media-manager role', () => {
41-
expect(AVAILABLE_ROLES['media-manager']).toEqual({
42-
displayName: 'Media Manager',
43-
description: 'Can manage movies, series, and encoding tasks',
44-
})
45-
})
46-
47-
it('should have correct metadata for viewer role', () => {
48-
expect(AVAILABLE_ROLES.viewer).toEqual({
49-
displayName: 'Viewer',
50-
description: 'Can browse and watch media content',
51-
})
52-
})
53-
54-
it('should have correct metadata for iot-manager role', () => {
55-
expect(AVAILABLE_ROLES['iot-manager']).toEqual({
56-
displayName: 'IoT Manager',
57-
description: 'Can manage IoT devices and their settings',
58-
})
32+
it.each([
33+
['admin', 'Application Admin', 'Full system access including user management and all settings'],
34+
['media-manager', 'Media Manager', 'Can manage movies, series, and encoding tasks'],
35+
['viewer', 'Viewer', 'Can browse and watch media content'],
36+
['iot-manager', 'IoT Manager', 'Can manage IoT devices and their settings'],
37+
] as const)('should have correct metadata for %s role', (role, displayName, description) => {
38+
expect(AVAILABLE_ROLES[role]).toEqual({ displayName, description })
5939
})
6040
})
6141

6242
describe('getRoleDefinition', () => {
63-
it('should return correct definition for admin role', () => {
64-
const definition = getRoleDefinition('admin')
65-
66-
expect(definition).toEqual({
67-
name: 'admin',
68-
displayName: 'Application Admin',
69-
description: 'Full system access including user management and all settings',
70-
})
71-
})
72-
73-
it('should return correct definition for media-manager role', () => {
74-
const definition = getRoleDefinition('media-manager')
75-
76-
expect(definition).toEqual({
77-
name: 'media-manager',
78-
displayName: 'Media Manager',
79-
description: 'Can manage movies, series, and encoding tasks',
80-
})
81-
})
82-
83-
it('should return correct definition for viewer role', () => {
84-
const definition = getRoleDefinition('viewer')
85-
86-
expect(definition).toEqual({
87-
name: 'viewer',
88-
displayName: 'Viewer',
89-
description: 'Can browse and watch media content',
90-
})
91-
})
92-
93-
it('should return correct definition for iot-manager role', () => {
94-
const definition = getRoleDefinition('iot-manager')
95-
96-
expect(definition).toEqual({
97-
name: 'iot-manager',
98-
displayName: 'IoT Manager',
99-
description: 'Can manage IoT devices and their settings',
100-
})
101-
})
102-
103-
it('should include name, displayName, and description for each role', () => {
104-
const roles: Array<Roles[number]> = ['admin', 'media-manager', 'viewer', 'iot-manager']
105-
106-
for (const roleName of roles) {
107-
const definition = getRoleDefinition(roleName)
108-
109-
expect(definition.name).toBe(roleName)
110-
expect(definition.displayName).toBeDefined()
111-
expect(definition.description).toBeDefined()
112-
}
43+
it.each([
44+
['admin', 'Application Admin', 'Full system access including user management and all settings'],
45+
['media-manager', 'Media Manager', 'Can manage movies, series, and encoding tasks'],
46+
['viewer', 'Viewer', 'Can browse and watch media content'],
47+
['iot-manager', 'IoT Manager', 'Can manage IoT devices and their settings'],
48+
] as const)('should return correct definition for %s role', (name, displayName, description) => {
49+
const definition = getRoleDefinition(name)
50+
expect(definition).toEqual({ name, displayName, description })
11351
})
11452
})
11553

e2e/user-management.spec.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -198,7 +198,7 @@ test.describe('Role Editing', () => {
198198
const secondOption = await options.nth(1).getAttribute('value')
199199
expect(secondOption, 'Expected option to have a value').toBeTruthy()
200200

201-
await roleSelect.selectOption(secondOption!)
201+
await roleSelect.selectOption(secondOption)
202202

203203
// Verify a new role tag appears
204204
const roleTags = detailsPage.locator('role-tag')
@@ -222,7 +222,7 @@ test.describe('Role Editing', () => {
222222
const secondOption = await options.nth(1).getAttribute('value')
223223
expect(secondOption, 'Expected option to have a value').toBeTruthy()
224224

225-
await roleSelect.selectOption(secondOption!)
225+
await roleSelect.selectOption(secondOption)
226226

227227
// Save button should now be enabled
228228
await expect(saveButton).toBeEnabled()
@@ -266,7 +266,7 @@ test.describe('Role Editing', () => {
266266
const secondOption = await options.nth(1).getAttribute('value')
267267
expect(secondOption, 'Expected option to have a value').toBeTruthy()
268268

269-
await roleSelect.selectOption(secondOption!)
269+
await roleSelect.selectOption(secondOption)
270270

271271
// Verify Save is now enabled
272272
await expect(saveButton).toBeEnabled()
@@ -306,7 +306,7 @@ test.describe('Save Role Changes', () => {
306306
const secondOption = await options.nth(1).getAttribute('value')
307307
expect(secondOption, 'Expected option to have a value').toBeTruthy()
308308

309-
await roleSelect.selectOption(secondOption!)
309+
await roleSelect.selectOption(secondOption)
310310

311311
// Save changes
312312
await saveButton.click()

0 commit comments

Comments
 (0)