Files
supabase/apps/studio/components/interfaces/Organization/TeamSettings/TeamSettings.utils.test.ts
Gildas GarciaandJoshen Lim c829b26bd5 (feat) Allow to filter organization users by role (#51653)
## Problem

It can be hard to verify users roles in organizations with many members

## Solution

Add a filter on the team pages for organization roles.
<img width="1174" height="310" alt="image"
src="https://github.com/user-attachments/assets/dfc2ccdc-b83e-45c5-9a6c-d50417a3ff3e"
/>

## Review instructions

- Open the organization team page
- Select a role and verify only members who have this role are displayed
- Ensure other filters still work

---------

Co-authored-by: Joshen Lim <joshenlimek@gmail.com>
2026-10-15 11:31:46 +02:00

76 lines
2.9 KiB
TypeScript

import { describe, expect, it } from 'vitest'
import { getMemberRowHeight, matchesMfaFilter, matchesOrgRole } from './TeamSettings.utils'
describe('getMemberRowHeight', () => {
it('uses the minimum height for members with one role', () => {
expect(getMemberRowHeight({ role_ids: [1] })).toBe(60)
})
it('uses the minimum height when the role list is empty or missing', () => {
expect(getMemberRowHeight({ role_ids: [] })).toBe(60)
expect(getMemberRowHeight({} as { role_ids: number[] })).toBe(60)
})
it('grows by one line per role once the roles no longer fit in the minimum height', () => {
expect(getMemberRowHeight({ role_ids: [1, 2, 3] })).toBe(60)
expect(getMemberRowHeight({ role_ids: [1, 2, 3, 4] })).toBe(80)
expect(getMemberRowHeight({ role_ids: [1, 2, 3, 4, 5] })).toBe(100)
})
})
describe('matchesMfaFilter', () => {
const withMfa = { mfa_enabled: true }
const withoutMfa = { mfa_enabled: false }
const invite = { mfa_enabled: false, invited_id: 1 }
it('keeps everyone, including pending invites, when the filter is "all"', () => {
expect(matchesMfaFilter(withMfa, 'all')).toBe(true)
expect(matchesMfaFilter(withoutMfa, 'all')).toBe(true)
expect(matchesMfaFilter(invite, 'all')).toBe(true)
})
it('keeps only members with MFA when the filter is "enabled"', () => {
expect(matchesMfaFilter(withMfa, 'enabled')).toBe(true)
expect(matchesMfaFilter(withoutMfa, 'enabled')).toBe(false)
})
it('keeps only members without MFA when the filter is "disabled"', () => {
expect(matchesMfaFilter(withoutMfa, 'disabled')).toBe(true)
expect(matchesMfaFilter(withMfa, 'disabled')).toBe(false)
})
it('leaves pending invites out of the "enabled" and "disabled" filters', () => {
expect(matchesMfaFilter(invite, 'enabled')).toBe(false)
expect(matchesMfaFilter(invite, 'disabled')).toBe(false)
})
})
describe('matchesOrgRole', () => {
const noRole = { role_ids: [] }
const singleRole = { role_ids: [2] }
const anotherSingleRole = { role_ids: [3] }
const multipleRoles = { role_ids: [1, 2, 3] }
it('keeps everyone when roles filter is empty', () => {
expect(matchesOrgRole(noRole, [])).toBe(true)
expect(matchesOrgRole(singleRole, [])).toBe(true)
expect(matchesOrgRole(anotherSingleRole, [])).toBe(true)
expect(matchesOrgRole(multipleRoles, [])).toBe(true)
})
it('keeps only members who have the provided role', () => {
expect(matchesOrgRole(noRole, [2])).toBe(false)
expect(matchesOrgRole(singleRole, [2])).toBe(true)
expect(matchesOrgRole(anotherSingleRole, [2])).toBe(false)
expect(matchesOrgRole(multipleRoles, [2])).toBe(true)
})
it('keeps only members who have any of the provided roles', () => {
expect(matchesOrgRole(noRole, [2, 3])).toBe(false)
expect(matchesOrgRole(singleRole, [2, 3])).toBe(true)
expect(matchesOrgRole(anotherSingleRole, [2, 3])).toBe(true)
expect(matchesOrgRole(multipleRoles, [2, 3])).toBe(true)
})
})