feat(editor): Auto-select all credentials by default in push modal (#21216)

This commit is contained in:
Csaba Tuncsik 2025-10-28 10:48:22 +01:00 committed by GitHub
parent 4e9ee11c23
commit cd403bda12
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 87 additions and 1 deletions

View file

@ -368,7 +368,8 @@ describe('SourceControlPushModal', () => {
expect(sourceControlStore.pushWorkfolder).toHaveBeenCalledWith(
expect.objectContaining({
commitMessage,
fileNames: expect.arrayContaining(status.filter((file) => file.type !== 'credential')),
// All files including credentials should be pushed (credentials now selected by default)
fileNames: expect.arrayContaining(status),
force: true,
}),
);
@ -434,6 +435,82 @@ describe('SourceControlPushModal', () => {
expect(submitButton).not.toBeDisabled();
});
it('should have all credentials selected by default', async () => {
const status: SourceControlledFile[] = [
{
id: 'workflow-1',
name: 'My workflow',
type: 'workflow',
status: 'created',
location: 'local',
conflict: false,
file: '/home/user/.n8n/git/workflows/workflow-1.json',
updatedAt: '2024-09-20T10:30:00.000Z',
},
{
id: 'cred-1',
name: 'My credential 1',
type: 'credential',
status: 'created',
location: 'local',
conflict: false,
file: '/home/user/.n8n/git/credentials/cred-1.json',
updatedAt: '2024-09-20T10:31:40.000Z',
},
{
id: 'cred-2',
name: 'My credential 2',
type: 'credential',
status: 'modified',
location: 'local',
conflict: false,
file: '/home/user/.n8n/git/credentials/cred-2.json',
updatedAt: '2024-09-20T14:42:51.968Z',
},
];
sourceControlStore.getAggregatedStatus.mockResolvedValue(status);
const { getAllByTestId, getByText } = renderModal({
pinia,
props: {
data: {
eventBus,
status,
},
},
});
// Wait for modal content to be visible
await waitFor(() => {
expect(getByText('Commit and push changes')).toBeInTheDocument();
});
await waitFor(() => {
const workflows = getAllByTestId('source-control-push-modal-file-checkbox');
expect(workflows).toHaveLength(1);
});
// Switch to credentials tab
const tabs = getAllByTestId('source-control-push-modal-tab');
const credentialsTab = tabs.find((tab) => tab.textContent?.includes('Credentials'));
await userEvent.click(credentialsTab!);
await waitFor(() => {
const credentials = getAllByTestId('source-control-push-modal-file-checkbox');
expect(credentials).toHaveLength(2);
});
const credentials = getAllByTestId('source-control-push-modal-file-checkbox');
// All credentials should be selected by default
expect(within(credentials[0]).getByRole('checkbox')).toBeChecked();
expect(within(credentials[1]).getByRole('checkbox')).toBeChecked();
// Verify the tab shows correct count
expect(credentialsTab?.textContent).toContain('2 / 2 selected');
});
it('should show credentials in a different tab', async () => {
const status: SourceControlledFile[] = [
{
@ -499,6 +576,8 @@ describe('SourceControlPushModal', () => {
const credentials = getAllByTestId('source-control-push-modal-file-checkbox');
expect(credentials).toHaveLength(1);
expect(within(credentials[0]).getByText('My credential')).toBeInTheDocument();
// Credentials should be selected by default
expect(within(credentials[0]).getByRole('checkbox')).toBeChecked();
});
describe('filters', () => {

View file

@ -97,6 +97,13 @@ async function loadSourceControlStatus() {
}
status.value = freshStatus;
// Auto-select all credentials by default (only once on load)
freshStatus.forEach((file) => {
if (file.type === 'credential') {
selectedCredentials.add(file.id);
}
});
} catch (error) {
toast.showError(error, i18n.baseText('error'));
close();