Skip to content

Commit d2e3458

Browse files
chore: removed unused comments and fix project structure
1 parent a973a01 commit d2e3458

17 files changed

Lines changed: 82 additions & 1498 deletions

File tree

frontend/coverage-report.json

Lines changed: 0 additions & 3 deletions
This file was deleted.

frontend/src/components/HomeComponents/Navbar/navbar-utils.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,6 @@ export const deleteAllTasks = async (props: Props) => {
6666
try {
6767
const taskCount = await db.tasks.where('email').equals(props.email).count();
6868

69-
// If no tasks, show Red toast
7069
if (taskCount === 0) {
7170
toast.update(loadingToastId, {
7271
render: `No tasks to delete for ${props.email}.`,

frontend/src/components/HomeComponents/SetupGuide/SetupGuide.test.tsx

Lines changed: 0 additions & 88 deletions
This file was deleted.
Lines changed: 75 additions & 73 deletions
Original file line numberDiff line numberDiff line change
@@ -1,86 +1,88 @@
1-
import { render, screen } from '@testing-library/react';
1+
import { render, screen, fireEvent } from '@testing-library/react';
22
import { SetupGuide } from '../SetupGuide';
3-
import { Props } from '../../../utils/types';
4-
import { url } from '@/components/utils/URLs';
53

6-
// Mocking the CopyableCode component
4+
// Using jest.mock to mock external dependencies
5+
jest.mock('@/components/utils/URLs', () => ({
6+
url: {
7+
containerOrigin: 'https://test-container',
8+
},
9+
}));
10+
11+
// Mock CopyableCode component
712
jest.mock('../CopyableCode', () => ({
8-
CopyableCode: ({
9-
text,
10-
copyText,
11-
isSensitive,
12-
}: {
13-
text: string;
14-
copyText: string;
15-
isSensitive?: boolean;
16-
}) => (
17-
<div
18-
data-testid="copyable-code"
19-
data-text={text}
20-
data-copytext={copyText}
21-
data-issensitive={isSensitive}
22-
>
23-
{text}
24-
</div>
13+
CopyableCode: ({ text }: { text: string }) => (
14+
<div data-testid="copyable-code">{text}</div>
2515
),
2616
}));
2717

28-
const props: Props = {
29-
name: 'test-name',
30-
encryption_secret: 'test-encryption-secret',
31-
uuid: 'test-uuid',
18+
// Mock exportConfigSetup utility
19+
const mockExportConfigSetup = jest.fn();
20+
jest.mock('../utils', () => ({
21+
exportConfigSetup: (props: any) => mockExportConfigSetup(props),
22+
}));
23+
24+
const defaultProps = {
25+
name: 'Test User',
26+
encryption_secret: 'secret123',
27+
uuid: 'uuid-1234',
3228
};
33-
describe('SetupGuide Component', () => {
34-
test('renders SetupGuide component with correct text', () => {
35-
render(<SetupGuide {...props} />);
29+
30+
describe('SetupGuide', () => {
31+
test('renders setup guide sections', () => {
32+
render(<SetupGuide {...defaultProps} />);
33+
34+
// Section exists
35+
expect(document.querySelector('#setup-guide')).toBeInTheDocument();
36+
37+
// Sub-section headings
38+
expect(screen.getByText('PREREQUISITES')).toBeInTheDocument();
39+
expect(screen.getByText('CONFIGURATION')).toBeInTheDocument();
40+
expect(screen.getByText('SYNC')).toBeInTheDocument();
3641
});
3742

38-
test('renders CopyableCode components with correct props', () => {
39-
render(<SetupGuide {...props} />);
40-
41-
// Check for CopyableCode components
42-
const copyableCodeElements = screen.getAllByTestId('copyable-code');
43-
expect(copyableCodeElements.length).toBe(5);
44-
45-
// Validate the text and copyText props of each CopyableCode component
46-
expect(copyableCodeElements[0]).toHaveAttribute(
47-
'data-text',
48-
'task --version'
49-
);
50-
expect(copyableCodeElements[0]).toHaveAttribute(
51-
'data-copytext',
52-
'task --version'
53-
);
54-
expect(copyableCodeElements[1]).toHaveAttribute(
55-
'data-text',
56-
`task config sync.encryption_secret ${props.encryption_secret}`
57-
);
58-
expect(copyableCodeElements[1]).toHaveAttribute(
59-
'data-copytext',
60-
`task config sync.encryption_secret ${props.encryption_secret}`
61-
);
62-
expect(copyableCodeElements[2]).toHaveAttribute(
63-
'data-text',
64-
`task config sync.server.origin ${url.containerOrigin}`
65-
);
66-
expect(copyableCodeElements[2]).toHaveAttribute(
67-
'data-copytext',
68-
`task config sync.server.origin ${url.containerOrigin}`
69-
);
70-
expect(copyableCodeElements[3]).toHaveAttribute(
71-
'data-text',
72-
`task config sync.server.client_id ${props.uuid}`
73-
);
74-
expect(copyableCodeElements[3]).toHaveAttribute(
75-
'data-copytext',
76-
`task config sync.server.client_id ${props.uuid}`
77-
);
43+
test('renders configuration commands using props', () => {
44+
render(<SetupGuide {...defaultProps} />);
45+
46+
expect(
47+
screen.getByText(
48+
`task config sync.encryption_secret ${defaultProps.encryption_secret}`
49+
)
50+
).toBeInTheDocument();
51+
52+
expect(
53+
screen.getByText(`task config sync.server.client_id ${defaultProps.uuid}`)
54+
).toBeInTheDocument();
55+
56+
expect(
57+
screen.getByText('task config sync.server.origin https://test-container')
58+
).toBeInTheDocument();
7859
});
79-
});
8060

81-
describe('SetupGuide component using snapshot', () => {
82-
test('renders correctly', () => {
83-
const { asFragment } = render(<SetupGuide {...props} />);
84-
expect(asFragment()).toMatchSnapshot();
61+
test('clicking download configuration triggers download logic', () => {
62+
mockExportConfigSetup.mockReturnValue('config-content');
63+
64+
// Polyfill missing browser APIs
65+
Object.defineProperty(global.URL, 'createObjectURL', {
66+
writable: true,
67+
value: jest.fn(() => 'blob:http://localhost/file'),
68+
});
69+
70+
Object.defineProperty(global.URL, 'revokeObjectURL', {
71+
writable: true,
72+
value: jest.fn(),
73+
});
74+
75+
const appendSpy = jest.spyOn(document.body, 'appendChild');
76+
const removeSpy = jest.spyOn(document.body, 'removeChild');
77+
78+
render(<SetupGuide {...defaultProps} />);
79+
80+
fireEvent.click(screen.getByText(/DOWNLOAD CONFIGURATION/i));
81+
82+
expect(mockExportConfigSetup).toHaveBeenCalledWith(defaultProps);
83+
expect(URL.createObjectURL).toHaveBeenCalled();
84+
expect(URL.revokeObjectURL).toHaveBeenCalled();
85+
expect(appendSpy).toHaveBeenCalled();
86+
expect(removeSpy).toHaveBeenCalled();
8587
});
8688
});

0 commit comments

Comments
 (0)