-
Notifications
You must be signed in to change notification settings - Fork 86
Expand file tree
/
Copy pathSubscriptionWizard.test.tsx
More file actions
246 lines (193 loc) · 9.27 KB
/
SubscriptionWizard.test.tsx
File metadata and controls
246 lines (193 loc) · 9.27 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
import '@testing-library/jest-dom/vitest';
import { render, screen, waitFor } from '@testing-library/react';
import userEvent from '@testing-library/user-event';
import { MemoryRouter } from 'react-router-dom';
import { beforeEach, describe, expect, it, vi } from 'vitest';
import { SubscriptionWizard } from './SubscriptionWizard';
const mockOnSuccess = vi.fn();
const defaultProps = {
onSuccess: mockOnSuccess,
};
const renderWithRouter = (props = defaultProps) => {
return render(
<MemoryRouter>
<SubscriptionWizard {...props} />
</MemoryRouter>
);
};
describe('SubscriptionWizard Component', () => {
beforeEach(() => {
vi.clearAllMocks();
});
describe('Wizard Structure', () => {
it('should render wizard with proper navigation steps', () => {
renderWithRouter();
// Check that wizard navigation is present
expect(screen.getByRole('navigation', { name: 'Steps' })).toBeInTheDocument();
// Check that all three steps are present in navigation
const navigation = screen.getByRole('navigation', { name: 'Steps' });
expect(navigation).toHaveTextContent('Ansible Automation Platform Subscription');
expect(navigation).toHaveTextContent('End User License Agreement');
expect(navigation).toHaveTextContent('Review');
// The first step should be marked as current
const currentStep = screen.getByRole('button', {
name: 'Ansible Automation Platform Subscription',
});
expect(currentStep).toHaveClass('pf-m-current');
// Other steps should be disabled
const licenseStep = screen.getByRole('button', { name: 'End User License Agreement' });
const reviewStep = screen.getByRole('button', { name: 'Review' });
expect(licenseStep).toBeDisabled();
expect(reviewStep).toBeDisabled();
// Check that the next, back, and cancel buttons are present
expect(screen.getByRole('button', { name: 'Next' })).toBeInTheDocument();
expect(screen.getByRole('button', { name: 'Back' })).toBeInTheDocument();
expect(screen.getByRole('button', { name: 'Cancel' })).toBeInTheDocument();
});
});
describe('Initial Content', () => {
it('should display welcome content and instructions', () => {
renderWithRouter();
expect(
screen.getByText('Welcome to Red Hat Ansible Automation Platform!')
).toBeInTheDocument();
expect(
screen.getByText('Please complete the steps below to activate your subscription.')
).toBeInTheDocument();
expect(
screen.getByText('Select one of the following methods to add your subscription.')
).toBeInTheDocument();
});
it('should display trial subscription link', () => {
renderWithRouter();
const trialLink = screen.getByRole('link', { name: 'trial subscription' });
expect(trialLink).toBeInTheDocument();
expect(trialLink).toHaveAttribute('href', 'https://www.ansible.com/license');
});
});
describe('Subscription Selection Options', () => {
it('should render all 4 subscription toggle options', () => {
renderWithRouter();
// Verify all 4 toggle options exist
expect(screen.getByRole('button', { name: 'Subscription manifest' })).toBeInTheDocument();
expect(screen.getByRole('button', { name: 'Service Account' })).toBeInTheDocument();
expect(screen.getByRole('button', { name: 'Username and Password' })).toBeInTheDocument();
expect(screen.getByRole('button', { name: 'Red Hat Satellite' })).toBeInTheDocument();
});
});
describe('Subscription Manifest Form', () => {
it('should display subscription allocations link when manifest is selected', async () => {
const user = userEvent.setup();
renderWithRouter();
await user.click(screen.getByRole('button', { name: 'Subscription manifest' }));
const allocationsLink = screen.getByRole('link', { name: 'subscription allocations' });
expect(allocationsLink).toBeInTheDocument();
expect(allocationsLink).toHaveAttribute(
'href',
'https://access.redhat.com/management/subscription_allocations'
);
});
it('should validate subscription manifest form field', async () => {
const user = userEvent.setup();
renderWithRouter();
await user.click(screen.getByRole('button', { name: 'Subscription manifest' }));
// Find the file upload field by querying for file input type
const fileUploadField = document.querySelector('input[type="file"]') as HTMLInputElement;
expect(fileUploadField).toBeInTheDocument();
// Note: File upload field may not show as required in the hidden input, but the component validates it
// Create a mock file for testing
const mockFile = new File(['test content'], 'test-manifest.zip', { type: 'application/zip' });
// Upload the file
await user.upload(fileUploadField, mockFile);
// Verify the file was uploaded
expect(fileUploadField.files?.[0]).toBe(mockFile);
});
});
describe('Service Account Form', () => {
it('should display service account form with proper validation', async () => {
const user = userEvent.setup();
renderWithRouter();
await user.click(screen.getByRole('button', { name: 'Service Account' }));
expect(
screen.getByText(/Provide your service account credentials below/)
).toBeInTheDocument();
const consoleLink = screen.getByRole('link', { name: 'here on console.redhat.com' });
expect(consoleLink).toBeInTheDocument();
expect(consoleLink).toHaveAttribute(
'href',
'https://console.redhat.com/iam/service-accounts'
);
// Verify required form fields are present
const clientIdField = await screen.findByRole('textbox', { name: 'Client ID' });
const clientSecretField = document.querySelector(
'input[type="password"]'
) as HTMLInputElement;
const subscriptionSelect = screen.getByRole('button', { name: 'Subscription' });
expect(clientIdField).toBeInTheDocument();
expect(clientSecretField).toBeInTheDocument();
expect(subscriptionSelect).toBeInTheDocument();
// Verify subscription select is disabled when credentials are empty
expect(subscriptionSelect).toBeDisabled();
// Fill in client ID and verify subscription select is still disabled
await user.type(clientIdField, 'test-client-id');
expect(subscriptionSelect).toBeDisabled();
// Fill in client secret and verify subscription select becomes enabled
await user.type(clientSecretField, 'test-client-secret');
await waitFor(() => {
expect(subscriptionSelect).toBeEnabled();
});
}, 10000);
});
describe('Username and Password Form', () => {
it('should display username and password form with proper validation', async () => {
const user = userEvent.setup();
renderWithRouter();
await user.click(screen.getByRole('button', { name: 'Username and Password' }));
// Verify required form fields are present
const usernameField = screen.getByRole('textbox', { name: 'Username' });
const passwordField = document.querySelector('input[type="password"]') as HTMLInputElement;
const subscriptionSelect = screen.getByRole('button', { name: 'Subscription' });
expect(usernameField).toBeInTheDocument();
expect(passwordField).toBeInTheDocument();
expect(subscriptionSelect).toBeInTheDocument();
// Verify subscription select is disabled when credentials are empty
expect(subscriptionSelect).toBeDisabled();
// Fill in username and verify subscription select is still disabled
await user.type(usernameField, 'test-username');
expect(subscriptionSelect).toBeDisabled();
// Fill in password and verify subscription select becomes enabled
await user.type(passwordField, 'test-password');
await waitFor(() => {
expect(subscriptionSelect).toBeEnabled();
});
}, 10000);
});
describe('Red Hat Satellite Form', () => {
it('should display red hat satellite form with proper validation', async () => {
const user = userEvent.setup();
renderWithRouter();
await user.click(screen.getByRole('button', { name: 'Red Hat Satellite' }));
// Verify required form fields are present
const satelliteUsernameField = screen.getByRole('textbox', {
name: 'Red Hat Satellite username',
});
const satellitePasswordField = document.querySelector(
'input[type="password"]'
) as HTMLInputElement;
const subscriptionSelect = screen.getByRole('button', { name: 'Subscription' });
expect(satelliteUsernameField).toBeInTheDocument();
expect(satellitePasswordField).toBeInTheDocument();
expect(subscriptionSelect).toBeInTheDocument();
// Verify subscription select is disabled when credentials are empty
expect(subscriptionSelect).toBeDisabled();
// Fill in satellite username and verify subscription select is still disabled
await user.type(satelliteUsernameField, 'test-satellite-username');
expect(subscriptionSelect).toBeDisabled();
// Fill in satellite password and verify subscription select becomes enabled
await user.type(satellitePasswordField, 'test-password');
await waitFor(() => {
expect(subscriptionSelect).toBeEnabled();
});
}, 10000);
});
});