Files
supabase/apps/studio/components/interfaces/ProjectHome/CustomReportSection.utils.test.ts
Jordi Enric 6770f1a148 feat(studio): share report snippets with the team when added to homepage report FE-3800 (#47629)
## Problem

Adding a private SQL snippet ('user' visibility) as a Home / project
overview report created a broken experience for other project members,
who saw "SQL snippet not found" because they had no access to the
snippet.

## Fix

Selecting a private snippet from the report block picker now shows a
confirmation step that makes the snippet public to the project before it
is added. Already-shared snippets are added directly, and snippets
created via drag-and-drop onto the report are now shared on creation.

## How to test

- Open a project's homepage and go to the Reports section
- Create a private SQL snippet if you do not have one
- Click "Add block" and select the private snippet
- Confirm a dialog appears explaining the snippet will become visible to
the team
- Confirm, and verify the block is added to the report
- Log in as another project member and confirm the report block renders
instead of "SQL snippet not found"
- Selecting an already-shared snippet should add it without the
confirmation dialog

<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->
## Summary by CodeRabbit

* **New Features**
* Added a “make snippet public” confirmation flow for user-owned report
blocks.
* Updated snippet selection to support a private-snippet share prompt
when appropriate.
* **Bug Fixes**
* Improved duplicate-block handling to prevent adding the same snippet
multiple times.
* **Refactor**
* Refactored SQL snippet upsert payload construction for more consistent
project visibility updates.
* **Tests**
  * Added unit tests covering snippet selection decision logic.
<!-- end of auto-generated comment: release notes by coderabbit.ai -->

---------

Co-authored-by: Claude Opus 4.8 <noreply@anthropic.com>
2026-07-06 13:04:36 +02:00

21 lines
939 B
TypeScript

import { describe, expect, it } from 'vitest'
import { resolveSnippetSelection } from './CustomReportSection.utils'
describe('resolveSnippetSelection', () => {
it('returns "already-added" when the snippet is already in the report', () => {
expect(resolveSnippetSelection({ visibility: 'user' }, true)).toBe('already-added')
expect(resolveSnippetSelection({ visibility: 'project' }, true)).toBe('already-added')
})
it('returns "confirm-share" for a private snippet not yet in the report', () => {
expect(resolveSnippetSelection({ visibility: 'user' }, false)).toBe('confirm-share')
})
it('returns "add" for an already-shared snippet not yet in the report', () => {
expect(resolveSnippetSelection({ visibility: 'project' }, false)).toBe('add')
expect(resolveSnippetSelection({ visibility: 'org' }, false)).toBe('add')
expect(resolveSnippetSelection({ visibility: 'public' }, false)).toBe('add')
})
})