fix(editor): Reset connection state when switching credential to private (#31713)

Co-authored-by: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
Guillaume Jacquart 2026-06-04 20:23:02 +02:00 committed by GitHub
parent 88fae045ef
commit b2942b4b54
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 38 additions and 0 deletions

View File

@ -1013,5 +1013,38 @@ describe('CredentialEdit', () => {
expect(confirmMock).not.toHaveBeenCalled();
});
});
describe('switching a static credential to private', () => {
test('resets the connected state so no Disconnect button is shown', async () => {
confirmMock.mockResolvedValue('confirm');
const pinia = createPiniaForBannerTest();
// A static credential whose per-user connection flag leaked over from a
// prior in-session connect. Switching it to private must not carry that
// connected state over, since no end-user connection exists yet.
const credentialsStore = setupOAuthCredential({
isResolvable: false,
connectedByMe: true,
oauthTokenData: false,
});
const { queryByTestId, getByTestId } = renderComponent({
props: {
activeId: 'cred-banner',
modalName: CREDENTIAL_EDIT_MODAL_KEY,
mode: 'edit',
},
pinia,
});
await retry(() => expect(credentialsStore.getCredentialData).toHaveBeenCalled());
await retry(() => expect(getByTestId('dynamic-credentials-toggle')).toBeVisible());
await userEvent.click(getByTestId('dynamic-credentials-toggle'));
await retry(() => expect(queryByTestId('oauth-not-connected-banner')).toBeVisible());
expect(queryByTestId('oauth-connect-success-banner')).not.toBeVisible();
expect(queryByTestId('oauth-disconnect-button')).not.toBeInTheDocument();
});
});
});
});

View File

@ -804,6 +804,11 @@ async function onResolvableChange(value: boolean) {
}
isResolvable.value = value;
// Switching sharing mode invalidates any carried-over connection state: a
// freshly-private credential has no per-user connection for the current
// user yet, so reset it to avoid rendering a stale "connected" state with a
// Disconnect button that has nothing to disconnect.
connectedByMe.value = false;
hasUnsavedChanges.value = true;
}