import { describe, expect, it } from 'vitest' import { mount } from '@vue/test-utils' import SecretInput from '../../components/SecretInput.vue' import { isPluginSecretRef, keepPluginSecret, pluginSecretLabel, pluginSecretState, } from '../../utils/pluginSecrets' const storedRef = { $secret: 'sec_0f2a4c6e8a0c2e4a6c8e0a2c4e6a8c0e', set: true } const lockedRef = { $secret: null, locked: true } describe('pluginSecrets helpers', () => { it('should classify each marker the settings response can publish', () => { expect([ pluginSecretState(storedRef), pluginSecretState(null), pluginSecretState(lockedRef), pluginSecretLabel(storedRef), pluginSecretLabel(null), pluginSecretLabel(lockedRef), ]).toEqual(['set', 'unset', 'environment', 'Set', 'Not set', 'Provided by environment']) }) it('should only treat reserved marker shapes as references', () => { expect([ isPluginSecretRef(storedRef), isPluginSecretRef({ $mint: 'placeholder' }), isPluginSecretRef({ $secret: 'x', label: 'not a marker' }), isPluginSecretRef('plain-string'), keepPluginSecret(storedRef), keepPluginSecret('typed'), ]).toEqual([true, false, false, false, { ...storedRef }, null]) }) }) describe('SecretInput', () => { it('should show the stored state without exposing a value', () => { const wrapper = mount(SecretInput, { props: { modelValue: storedRef } }) expect([ wrapper.find('.mint-secret-input__badge').text(), wrapper.find('input').exists(), ]).toEqual(['Set', false]) }) it('should submit the typed string once the user enters a new value', async () => { const wrapper = mount(SecretInput, { props: { modelValue: storedRef } }) await wrapper.findAll('button')[0]!.trigger('click') await wrapper.setProps({ modelValue: '' }) await wrapper.find('input').setValue('typed-secret') expect(wrapper.emitted('update:modelValue')).toEqual([[''], ['typed-secret']]) }) it('should submit null when the user clears a stored secret', async () => { const wrapper = mount(SecretInput, { props: { modelValue: storedRef } }) const clear = wrapper.findAll('button').at(-1)! await clear.trigger('click') expect(wrapper.emitted('update:modelValue')).toEqual([[null]]) }) it('should restore the stored reference when an edit is cancelled', async () => { const wrapper = mount(SecretInput, { props: { modelValue: storedRef } }) await wrapper.findAll('button')[0]!.trigger('click') await wrapper.setProps({ modelValue: 'partial' }) await wrapper.findAll('button')[0]!.trigger('click') expect(wrapper.emitted('update:modelValue')?.at(-1)).toEqual([{ ...storedRef }]) }) it('should keep an environment-provided secret read-only', async () => { const wrapper = mount(SecretInput, { props: { modelValue: lockedRef } }) expect([ wrapper.find('.mint-secret-input__badge').text(), wrapper.find('.mint-secret-input__hint').exists(), wrapper.findAll('button').every(button => button.attributes('disabled') !== undefined), wrapper.emitted('update:modelValue'), ]).toEqual(['Provided by environment', true, true, undefined]) }) it('should mark the unset state with a hollow status dot class (10b)', () => { const wrapper = mount(SecretInput, { props: { modelValue: null } }) expect(wrapper.find('.mint-secret-input__badge--unset .mint-secret-input__dot').exists()).toBe(true) }) })