Skip to content

Commit 6a2480e

Browse files
committed
AXON-762: added more tests
1 parent f1479be commit 6a2480e

File tree

7 files changed

+321
-0
lines changed

7 files changed

+321
-0
lines changed
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
import { render, screen } from '@testing-library/react';
2+
import React from 'react';
3+
4+
import { RepoData } from '../../../../../lib/ipc/toUI/startWork';
5+
import { BranchPrefixSelector } from './BranchPrefixSelector';
6+
7+
describe('BranchPrefixSelector', () => {
8+
const mockRepoData: RepoData = {
9+
workspaceRepo: {
10+
rootUri: '/test/repo',
11+
mainSiteRemote: { site: undefined, remote: { name: 'origin', isReadOnly: false } },
12+
siteRemotes: [{ site: undefined, remote: { name: 'origin', isReadOnly: false } }],
13+
},
14+
localBranches: [],
15+
remoteBranches: [],
16+
branchTypes: [
17+
{ kind: 'Feature', prefix: 'feature/' },
18+
{ kind: 'Bugfix', prefix: 'bugfix/' },
19+
],
20+
developmentBranch: 'main',
21+
userName: 'test',
22+
userEmail: '[email protected]',
23+
isCloud: false,
24+
};
25+
26+
it('should not render when no branch types or custom prefixes', () => {
27+
const repoWithoutBranchTypes = {
28+
...mockRepoData,
29+
branchTypes: [],
30+
};
31+
32+
const { container } = render(
33+
<BranchPrefixSelector
34+
selectedRepository={repoWithoutBranchTypes}
35+
selectedBranchType={{ kind: 'Feature', prefix: 'feature/' }}
36+
customPrefixes={[]}
37+
onBranchTypeChange={jest.fn()}
38+
/>,
39+
);
40+
41+
expect(container.firstChild).toBeNull();
42+
});
43+
44+
it('should render with branch types', () => {
45+
render(
46+
<BranchPrefixSelector
47+
selectedRepository={mockRepoData}
48+
selectedBranchType={{ kind: 'Feature', prefix: 'feature/' }}
49+
customPrefixes={[]}
50+
onBranchTypeChange={jest.fn()}
51+
/>,
52+
);
53+
54+
expect(screen.getByText('Branch prefix')).toBeTruthy();
55+
});
56+
});
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
import { fireEvent, render, screen } from '@testing-library/react';
2+
import React from 'react';
3+
4+
import { RepoData } from '../../../../../lib/ipc/toUI/startWork';
5+
import { ExistingBranchesSection } from './ExistingBranchesSection';
6+
7+
describe('ExistingBranchesSection', () => {
8+
const mockRepoData: RepoData = {
9+
workspaceRepo: {
10+
rootUri: '/test/repo',
11+
mainSiteRemote: { site: undefined, remote: { name: 'origin', isReadOnly: false } },
12+
siteRemotes: [{ site: undefined, remote: { name: 'origin', isReadOnly: false } }],
13+
},
14+
localBranches: [
15+
{ name: 'feature/TEST-123-test-issue', type: 0 },
16+
{ name: 'bugfix/TEST-123-fix', type: 0 },
17+
],
18+
remoteBranches: [{ name: 'origin/feature/TEST-123-old', type: 1, remote: 'origin' }],
19+
branchTypes: [],
20+
developmentBranch: 'main',
21+
userName: 'test',
22+
userEmail: '[email protected]',
23+
isCloud: false,
24+
};
25+
26+
it('should not render when no existing branches', () => {
27+
const repoWithoutBranches = {
28+
...mockRepoData,
29+
localBranches: [],
30+
remoteBranches: [],
31+
};
32+
33+
const { container } = render(
34+
<ExistingBranchesSection
35+
selectedRepository={repoWithoutBranches}
36+
issueKey="TEST-123"
37+
onExistingBranchClick={jest.fn()}
38+
/>,
39+
);
40+
41+
expect(container.firstChild).toBeNull();
42+
});
43+
44+
it('should handle existing branch click', () => {
45+
const onExistingBranchClick = jest.fn();
46+
render(
47+
<ExistingBranchesSection
48+
selectedRepository={mockRepoData}
49+
issueKey="TEST-123"
50+
onExistingBranchClick={onExistingBranchClick}
51+
/>,
52+
);
53+
54+
const branchLink = screen.getByText('feature/TEST-123-test-issue');
55+
fireEvent.click(branchLink);
56+
57+
expect(onExistingBranchClick).toHaveBeenCalledWith('feature/TEST-123-test-issue');
58+
});
59+
});
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
import { fireEvent, render, screen } from '@testing-library/react';
2+
import React from 'react';
3+
4+
import { LocalBranchInput } from './LocalBranchInput';
5+
6+
describe('LocalBranchInput', () => {
7+
it('should replace spaces with dashes in branch name', () => {
8+
const onLocalBranchChange = jest.fn();
9+
render(<LocalBranchInput localBranch="" onLocalBranchChange={onLocalBranchChange} />);
10+
11+
const input = screen.getByRole('textbox');
12+
fireEvent.change(input, { target: { value: 'feature TEST 123' } });
13+
14+
expect(onLocalBranchChange).toHaveBeenCalledWith('feature-TEST-123');
15+
});
16+
17+
it('should display current branch name', () => {
18+
const onLocalBranchChange = jest.fn();
19+
render(<LocalBranchInput localBranch="feature/TEST-123" onLocalBranchChange={onLocalBranchChange} />);
20+
21+
const input = screen.getByRole('textbox');
22+
expect((input as HTMLInputElement).value).toBe('feature/TEST-123');
23+
});
24+
});
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
import { fireEvent, render, screen } from '@testing-library/react';
2+
import React from 'react';
3+
4+
import { PushBranchToggle } from './PushBranchToggle';
5+
6+
describe('PushBranchToggle', () => {
7+
it('should toggle push branch enabled state', () => {
8+
const onPushBranchChange = jest.fn();
9+
render(<PushBranchToggle pushBranchEnabled={true} onPushBranchChange={onPushBranchChange} />);
10+
11+
const checkbox = screen.getByRole('checkbox');
12+
fireEvent.click(checkbox);
13+
14+
expect(onPushBranchChange).toHaveBeenCalledWith(false);
15+
});
16+
17+
it('should display correct checkbox state', () => {
18+
const onPushBranchChange = jest.fn();
19+
render(<PushBranchToggle pushBranchEnabled={false} onPushBranchChange={onPushBranchChange} />);
20+
21+
const checkbox = screen.getByRole('checkbox') as HTMLInputElement;
22+
expect(checkbox.checked).toBe(false);
23+
});
24+
});
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
import { fireEvent, render, screen } from '@testing-library/react';
2+
import React from 'react';
3+
4+
import { RepoData } from '../../../../../lib/ipc/toUI/startWork';
5+
import { RepositorySelector } from './RepositorySelector';
6+
7+
describe('RepositorySelector', () => {
8+
const mockRepoData: RepoData[] = [
9+
{
10+
workspaceRepo: {
11+
rootUri: '/test/repo1',
12+
mainSiteRemote: { site: undefined, remote: { name: 'origin', isReadOnly: false } },
13+
siteRemotes: [{ site: undefined, remote: { name: 'origin', isReadOnly: false } }],
14+
},
15+
localBranches: [],
16+
remoteBranches: [],
17+
branchTypes: [],
18+
developmentBranch: 'main',
19+
userName: 'test',
20+
userEmail: '[email protected]',
21+
isCloud: false,
22+
},
23+
{
24+
workspaceRepo: {
25+
rootUri: '/test/repo2',
26+
mainSiteRemote: { site: undefined, remote: { name: 'origin', isReadOnly: false } },
27+
siteRemotes: [{ site: undefined, remote: { name: 'origin', isReadOnly: false } }],
28+
},
29+
localBranches: [],
30+
remoteBranches: [],
31+
branchTypes: [],
32+
developmentBranch: 'main',
33+
userName: 'test',
34+
userEmail: '[email protected]',
35+
isCloud: false,
36+
},
37+
];
38+
39+
it('should not render when only one repository', () => {
40+
const onRepositoryChange = jest.fn();
41+
const { container } = render(
42+
<RepositorySelector
43+
repoData={[mockRepoData[0]]}
44+
selectedRepository={mockRepoData[0]}
45+
onRepositoryChange={onRepositoryChange}
46+
/>,
47+
);
48+
49+
expect(container.firstChild).toBeNull();
50+
});
51+
52+
it('should handle repository change', () => {
53+
const onRepositoryChange = jest.fn();
54+
render(
55+
<RepositorySelector
56+
repoData={mockRepoData}
57+
selectedRepository={mockRepoData[0]}
58+
onRepositoryChange={onRepositoryChange}
59+
/>,
60+
);
61+
62+
const select = screen.getByDisplayValue('/test/repo1');
63+
fireEvent.change(select, { target: { value: '/test/repo2' } });
64+
65+
expect(onRepositoryChange).toHaveBeenCalledWith(mockRepoData[1]);
66+
});
67+
});
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
import { render, screen } from '@testing-library/react';
2+
import React from 'react';
3+
4+
import { SuccessAlert } from './SuccessAlert';
5+
6+
describe('SuccessAlert', () => {
7+
it('should display success message with branch and transition information', () => {
8+
const submitResponse = {
9+
transistionStatus: 'In Progress',
10+
branch: 'feature/TEST-123-test-issue',
11+
upstream: 'origin',
12+
};
13+
14+
render(<SuccessAlert submitResponse={submitResponse} />);
15+
16+
expect(screen.getByText('Success!')).toBeTruthy();
17+
expect(screen.getByText('- Assigned the issue to you')).toBeTruthy();
18+
expect(screen.getByText(/Transitioned status to/)).toBeTruthy();
19+
expect(screen.getByText('In Progress')).toBeTruthy();
20+
expect(screen.getByText(/Switched to/)).toBeTruthy();
21+
expect(screen.getByText('feature/TEST-123-test-issue')).toBeTruthy();
22+
});
23+
24+
it('should display success message without optional fields', () => {
25+
const submitResponse = {};
26+
27+
render(<SuccessAlert submitResponse={submitResponse} />);
28+
29+
expect(screen.getByText('Success!')).toBeTruthy();
30+
expect(screen.getByText('- Assigned the issue to you')).toBeTruthy();
31+
expect(screen.queryByText(/Transitioned status/)).toBeNull();
32+
expect(screen.queryByText(/Switched to/)).toBeNull();
33+
});
34+
});
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
import { fireEvent, render, screen } from '@testing-library/react';
2+
import React from 'react';
3+
4+
import { RepoData } from '../../../../../lib/ipc/toUI/startWork';
5+
import { UpstreamSelector } from './UpstreamSelector';
6+
7+
describe('UpstreamSelector', () => {
8+
const mockRepoData: RepoData = {
9+
workspaceRepo: {
10+
rootUri: '/test/repo',
11+
mainSiteRemote: { site: undefined, remote: { name: 'origin', isReadOnly: false } },
12+
siteRemotes: [
13+
{ site: undefined, remote: { name: 'origin', isReadOnly: false } },
14+
{ site: undefined, remote: { name: 'upstream', isReadOnly: false } },
15+
],
16+
},
17+
localBranches: [],
18+
remoteBranches: [],
19+
branchTypes: [],
20+
developmentBranch: 'main',
21+
userName: 'test',
22+
userEmail: '[email protected]',
23+
isCloud: false,
24+
};
25+
26+
it('should not render when only one remote', () => {
27+
const repoWithOneRemote = {
28+
...mockRepoData,
29+
workspaceRepo: {
30+
...mockRepoData.workspaceRepo,
31+
siteRemotes: [{ site: undefined, remote: { name: 'origin', isReadOnly: false } }],
32+
},
33+
};
34+
35+
const { container } = render(
36+
<UpstreamSelector selectedRepository={repoWithOneRemote} upstream="origin" onUpstreamChange={jest.fn()} />,
37+
);
38+
39+
expect(container.firstChild).toBeNull();
40+
});
41+
42+
it('should handle upstream change', () => {
43+
const onUpstreamChange = jest.fn();
44+
render(
45+
<UpstreamSelector
46+
selectedRepository={mockRepoData}
47+
upstream="origin"
48+
onUpstreamChange={onUpstreamChange}
49+
/>,
50+
);
51+
52+
const select = screen.getByDisplayValue('origin');
53+
fireEvent.change(select, { target: { value: 'upstream' } });
54+
55+
expect(onUpstreamChange).toHaveBeenCalledWith('upstream');
56+
});
57+
});

0 commit comments

Comments
 (0)