Skip to content

Commit e36cad1

Browse files
committed
Updated tests
1 parent 9878577 commit e36cad1

File tree

14 files changed

+110
-324
lines changed

14 files changed

+110
-324
lines changed

__tests__/v2/UserEditor.test.js

Lines changed: 41 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -113,14 +113,8 @@ describe('UserEditor', () => {
113113
expect.anything(),
114114
expect.objectContaining({
115115
body: JSON.stringify({
116-
slurm_accounts: [],
117116
project_dir: '/path/to/project/dir',
118-
slurm_user: 'user',
119-
ssh_host: null,
120-
ssh_username: null,
121-
ssh_private_key_path: null,
122-
ssh_tasks_dir: null,
123-
ssh_jobs_dir: null
117+
slurm_user: 'user'
124118
})
125119
})
126120
);
@@ -182,14 +176,7 @@ describe('UserEditor', () => {
182176
expect.anything(),
183177
expect.objectContaining({
184178
body: JSON.stringify({
185-
slurm_accounts: [],
186-
project_dir: 'xxx',
187-
slurm_user: null,
188-
ssh_host: null,
189-
ssh_username: null,
190-
ssh_private_key_path: null,
191-
ssh_tasks_dir: null,
192-
ssh_jobs_dir: null
179+
project_dir: 'xxx'
193180
})
194181
})
195182
);
@@ -216,39 +203,66 @@ describe('UserEditor', () => {
216203
...initialSettings,
217204
ssh_host: 'localhost',
218205
ssh_username: 'username',
219-
ssh_private_key_path: '/path/to/private/key',
220-
ssh_tasks_dir: '/path/to/tasks/dir',
221-
ssh_jobs_dir: '/path/to/jobs/dir'
206+
ssh_private_key_path: '/path/to/private/key'
222207
})
223208
)
224209
});
225210

226211
await user.type(screen.getByRole('textbox', { name: 'SSH host' }), 'localhost');
227212
await user.type(screen.getByRole('textbox', { name: 'SSH username' }), 'username');
228213
await user.type(screen.getByRole('textbox', { name: 'SSH Private Key Path' }), 'xxx');
229-
await user.type(screen.getByRole('textbox', { name: 'SSH Tasks Dir' }), 'yyy');
230-
await user.type(screen.getByRole('textbox', { name: 'SSH Jobs Dir' }), 'zzz');
231214
await user.click(screen.getByRole('button', { name: 'Save' }));
232215
await screen.findByText('User successfully updated');
233216

234217
expect(mockRequest).toHaveBeenCalledWith(
235218
expect.anything(),
236219
expect.objectContaining({
237220
body: JSON.stringify({
238-
slurm_accounts: [],
239-
project_dir: null,
240-
slurm_user: null,
241221
ssh_host: 'localhost',
242222
ssh_username: 'username',
243-
ssh_private_key_path: 'xxx',
244-
ssh_tasks_dir: 'yyy',
245-
ssh_jobs_dir: 'zzz'
223+
ssh_private_key_path: 'xxx'
246224
})
247225
})
248226
);
249227
});
250228

251229
it('Update settings with slurm_ssh runner backend - validation error', async () => {
230+
const mockRequest = /** @type {import('vitest').Mock} */ (fetch)
231+
.mockResolvedValueOnce({
232+
ok: true,
233+
status: 200,
234+
// mock profile
235+
json: () => new Promise((resolve) => resolve({ id: 1, resource_id: 1 }))
236+
})
237+
.mockResolvedValueOnce({
238+
ok: true,
239+
status: 200,
240+
// mock resources
241+
json: () => new Promise((resolve) => resolve([{ id: 1 }]))
242+
})
243+
.mockResolvedValueOnce({
244+
ok: true,
245+
status: 200,
246+
// mock profiles
247+
json: () => new Promise((resolve) => resolve([{ id: 1 }]))
248+
})
249+
.mockResolvedValueOnce({
250+
ok: false,
251+
status: 422,
252+
json: () =>
253+
new Promise((resolve) =>
254+
resolve({
255+
detail: [
256+
{
257+
loc: ['body', 'ssh_private_key_path'],
258+
msg: 'mock_error_ssh_private_key_path',
259+
type: 'value_error'
260+
}
261+
]
262+
})
263+
)
264+
});
265+
252266
const user = userEvent.setup();
253267

254268
render(UserEditor, {
@@ -260,58 +274,22 @@ describe('UserEditor', () => {
260274
}
261275
});
262276

263-
const mockRequest = /** @type {import('vitest').Mock} */ (fetch).mockResolvedValue({
264-
ok: false,
265-
status: 422,
266-
json: () =>
267-
new Promise((resolve) =>
268-
resolve({
269-
detail: [
270-
{
271-
loc: ['body', 'ssh_private_key_path'],
272-
msg: 'mock_error_ssh_private_key_path',
273-
type: 'value_error'
274-
},
275-
{
276-
loc: ['body', 'ssh_tasks_dir'],
277-
msg: 'mock_error_ssh_tasks_dir',
278-
type: 'value_error'
279-
},
280-
{
281-
loc: ['body', 'ssh_jobs_dir'],
282-
msg: 'mock_error_ssh_jobs_dir',
283-
type: 'value_error'
284-
}
285-
]
286-
})
287-
)
288-
});
289-
290277
await user.type(screen.getByRole('textbox', { name: 'SSH host' }), 'localhost');
291278
await user.type(screen.getByRole('textbox', { name: 'SSH username' }), 'username');
292279
await user.type(
293280
screen.getByRole('textbox', { name: 'SSH Private Key Path' }),
294281
'/path/to/private/key'
295282
);
296-
await user.type(screen.getByRole('textbox', { name: 'SSH Tasks Dir' }), '/path/to/tasks/dir');
297-
await user.type(screen.getByRole('textbox', { name: 'SSH Jobs Dir' }), '/path/to/jobs/dir');
298283
await user.click(screen.getByRole('button', { name: 'Save' }));
299284
await screen.findByText('mock_error_ssh_private_key_path');
300-
await screen.findByText('mock_error_ssh_tasks_dir');
301-
await screen.findByText('mock_error_ssh_jobs_dir');
302285

303286
expect(mockRequest).toHaveBeenCalledWith(
304287
expect.anything(),
305288
expect.objectContaining({
306289
body: JSON.stringify({
307-
slurm_accounts: [],
308-
project_dir: null,
309-
slurm_user: null,
310290
ssh_host: 'localhost',
311291
ssh_username: 'username',
312-
ssh_private_key_path: '/path/to/private/key',
313-
ssh_tasks_dir: '/path/to/tasks/dir',
314-
ssh_jobs_dir: '/path/to/jobs/dir'
292+
ssh_private_key_path: '/path/to/private/key'
315293
})
316294
})
317295
);

playwright.config.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ export default defineConfig({
8888

8989
webServer: [
9090
{
91-
command: './tests/start-test-server.sh --branch main',
91+
command: './tests/start-test-server.sh --branch dev',
9292
port: 8000,
9393
waitForPort: true,
9494
stdout: 'pipe',
@@ -104,7 +104,7 @@ export default defineConfig({
104104
},
105105
{
106106
command:
107-
'npm run build && LOG_LEVEL_CONSOLE=debug ORIGIN=http://localhost:5173 PORT=5173 FRACTAL_RUNNER_BACKEND=slurm node build',
107+
'npm run build && LOG_LEVEL_CONSOLE=debug ORIGIN=http://localhost:5173 PORT=5173 FRACTAL_RUNNER_BACKEND=local node build',
108108
port: 5173,
109109
stdout: 'pipe',
110110
reuseExistingServer: !process.env.CI

src/lib/components/v2/admin/UserSettingsEditor.svelte

Lines changed: 2 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -50,9 +50,7 @@
5050
'slurm_user',
5151
'ssh_host',
5252
'ssh_username',
53-
'ssh_private_key_path',
54-
'ssh_tasks_dir',
55-
'ssh_jobs_dir'
53+
'ssh_private_key_path'
5654
]);
5755
const settingsValidationErrors = settingsFormErrorHandler.getValidationErrorStore();
5856
@@ -76,7 +74,7 @@
7674
method: 'PATCH',
7775
credentials: 'include',
7876
headers,
79-
body: normalizePayload({ ...editableSettings, id: undefined }, { nullifyEmptyStrings: true })
77+
body: normalizePayload({ ...editableSettings, id: undefined }, { stripEmptyElements: true })
8078
});
8179
if (!response.ok) {
8280
await settingsFormErrorHandler.handleErrorResponse(response);
@@ -185,42 +183,6 @@
185183
>
186184
</div>
187185
</div>
188-
<div class="row mb-3 has-validation">
189-
<label for="sshTasksDir" class="col-sm-3 col-form-label text-end">
190-
<strong>SSH Tasks Dir</strong>
191-
</label>
192-
<div class="col-sm-9">
193-
<input
194-
type="text"
195-
class="form-control"
196-
id="sshTasksDir"
197-
bind:value={editableSettings.ssh_tasks_dir}
198-
class:is-invalid={settingsFormSubmitted && $settingsValidationErrors['ssh_tasks_dir']}
199-
/>
200-
<div class="form-text">
201-
Task-venvs base folder on <code>ssh_host</code>
202-
</div>
203-
<span class="invalid-feedback">{$settingsValidationErrors['ssh_tasks_dir']}</span>
204-
</div>
205-
</div>
206-
<div class="row mb-3 has-validation">
207-
<label for="sshJobsDir" class="col-sm-3 col-form-label text-end">
208-
<strong>SSH Jobs Dir</strong>
209-
</label>
210-
<div class="col-sm-9">
211-
<input
212-
type="text"
213-
class="form-control"
214-
id="sshJobsDir"
215-
bind:value={editableSettings.ssh_jobs_dir}
216-
class:is-invalid={settingsFormSubmitted && $settingsValidationErrors['ssh_jobs_dir']}
217-
/>
218-
<div class="form-text">
219-
Jobs base folder on <code>ssh_host</code>
220-
</div>
221-
<span class="invalid-feedback">{$settingsValidationErrors['ssh_jobs_dir']}</span>
222-
</div>
223-
</div>
224186
{/if}
225187
{#if runnerBackend !== 'local'}
226188
<div class="row mb-3 has-validation">

src/routes/v2/admin/groups/[groupId]/edit/+page.svelte

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -416,8 +416,8 @@
416416
disabled={savingSettings || !settingsPendingChanges}
417417
>
418418
{#if savingSettings}
419-
<span class="spinner-border spinner-border-sm" role="status" aria-hidden="true"
420-
></span>
419+
<span class="spinner-border spinner-border-sm" role="status" aria-hidden="true">
420+
</span>
421421
{/if}
422422
Save
423423
</button>

src/routes/v2/admin/users/[userId]/+page.svelte

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -119,14 +119,6 @@
119119
<th>SSH Private Key Path</th>
120120
<td>{settings.ssh_private_key_path || '-'}</td>
121121
</tr>
122-
<tr>
123-
<th>SSH Tasks Dir</th>
124-
<td>{settings.ssh_tasks_dir || '-'}</td>
125-
</tr>
126-
<tr>
127-
<th>SSH Jobs Dir</th>
128-
<td>{settings.ssh_jobs_dir || '-'}</td>
129-
</tr>
130122
{/if}
131123
{#if runnerBackend === 'slurm_sudo' || runnerBackend === 'slurm_ssh'}
132124
<tr>

tests/profile.spec.js

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,13 @@ test('User profile', async ({ page }) => {
1313
const cells = await page.locator('table td').all();
1414
await expect(cells[0]).toHaveText('1');
1515
await expect(cells[1]).toHaveText('[email protected]');
16-
await expect(cells[2]).toHaveText('admin');
16+
await verifyChecked(cells, 2, true);
1717
await verifyChecked(cells, 3, true);
18-
await verifyChecked(cells, 4, true);
19-
await expect(cells[6]).toContainText('All');
20-
await expect(cells[7]).toHaveText('-');
18+
await expect(cells[5]).toContainText('All');
19+
await expect(cells[6]).toHaveText('-');
20+
await verifyChecked(cells, 7, true);
21+
await expect(cells[8]).toContainText('Local profile');
22+
await expect(cells[9]).toContainText('Local resource');
2123
});
2224
});
2325

tests/settings.spec.js

Lines changed: 4 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ test.use({ storageState: { cookies: [], origins: [] } });
77
test('User settings', async ({ page }) => {
88
const randomUsername = Math.random().toString(36).substring(7);
99
const randomEmail = `${randomUsername}@example.com`;
10-
const randomSlurmAccount = `${randomUsername}_slurm`;
1110

1211
await test.step('Login as admin and create test user', async () => {
1312
await login(page, '[email protected]', '1234');
@@ -18,6 +17,9 @@ test('User settings', async ({ page }) => {
1817
await page.getByRole('textbox', { name: 'Confirm password' }).fill('1234');
1918
await page.getByRole('button', { name: 'Save' }).click();
2019
await page.waitForURL(/\/v2\/admin\/users\/\d+\/edit/);
20+
await page.getByRole('textbox', { name: 'Project dir' }).fill('/tmp/project');
21+
await page.getByRole('button', { name: 'Save' }).click();
22+
await expect(page.getByText('User successfully updated')).toBeVisible();
2123
await logout(page, '[email protected]');
2224
});
2325

@@ -26,28 +28,7 @@ test('User settings', async ({ page }) => {
2628
await page.getByRole('button', { name: randomEmail }).click();
2729
await page.getByRole('link', { name: 'My settings' }).click();
2830
await waitPageLoading(page);
29-
});
30-
31-
await test.step('Add SLURM account (validation error)', async () => {
32-
const addAccountBtn = page.getByRole('button', { name: 'Add SLURM account' });
33-
await addAccountBtn.click();
34-
await addAccountBtn.click();
35-
await page.getByLabel('SLURM account 1').fill(randomSlurmAccount);
36-
await page.getByLabel('SLURM account 2').fill(randomSlurmAccount);
37-
await page.getByRole('button', { name: 'Save' }).click();
38-
await page.getByText('List has repetitions').waitFor();
39-
});
40-
41-
await test.step('Add SLURM account (success)', async () => {
42-
await page.getByLabel('Remove SLURM account').last().click();
43-
await page.getByRole('button', { name: 'Save' }).click();
44-
await expect(page.getByText('User settings successfully updated')).toBeVisible();
45-
});
46-
47-
await test.step('Verify data was updated', async () => {
48-
await page.reload();
49-
await waitPageLoading(page);
50-
await expect(page.getByLabel('SLURM account 1')).toHaveValue(randomSlurmAccount);
31+
await expect(page.getByText('/tmp/project')).toBeVisible();
5132
});
5233

5334
await test.step('Logout test user', async () => {

tests/start-test-server.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ if [ ! -d "$fractal_server_test_path" ]; then
4747
. myenv/bin/activate
4848
pip install "$pip_arg"
4949
fractalctl set-db
50+
fractalctl init-db-data --resource default --profile default
5051
else
5152
cd "$fractal_server_test_path"
5253
. myenv/bin/activate

tests/v2/admin_groups.spec.js

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -119,9 +119,6 @@ test('Admin groups management', async ({ page }) => {
119119
await page.getByRole('row', { name: group1 }).getByRole('link', { name: 'Edit' }).click();
120120
await waitPageLoading(page);
121121
await page.getByRole('textbox', { name: 'Project dir' }).fill('/tmp/test/project-dir');
122-
await page.getByRole('textbox', { name: 'SLURM user' }).fill('test-slurm-user');
123-
await page.getByRole('button', { name: 'Add SLURM account' }).click();
124-
await page.getByLabel('SLURM account #1', { exact: true }).fill('test-slurm-account');
125122
await page.getByRole('button', { name: 'Save' }).nth(1).click();
126123
await expect(page.getByText('Settings successfully updated')).toBeVisible();
127124
});
@@ -134,10 +131,6 @@ test('Admin groups management', async ({ page }) => {
134131
await expect(page.getByRole('textbox', { name: 'Project dir' })).toHaveValue(
135132
'/tmp/test/project-dir'
136133
);
137-
await expect(page.getByRole('textbox', { name: 'SLURM user' })).toHaveValue('test-slurm-user');
138-
await expect(page.getByLabel('SLURM account #1', { exact: true })).toHaveValue(
139-
'test-slurm-account'
140-
);
141134
});
142135

143136
await test.step('Remove user from group1 by editing group', async () => {

tests/v2/admin_import_user_settings.spec.js

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,6 @@ test('Import user settings from another user', async ({ page }) => {
1111

1212
await test.step('Fill user1 settings', async () => {
1313
await page.getByRole('textbox', { name: 'Project dir' }).fill('/test/import/proj_dir');
14-
await page.getByRole('textbox', { name: 'SLURM user' }).fill('test-import-slurm-user');
15-
await page.getByRole('button', { name: 'Add SLURM account' }).click();
16-
await page.getByLabel('SLURM account #1', { exact: true }).fill('test-import-slurm-account');
1714
await page.getByRole('button', { name: 'Save' }).click();
1815
});
1916

@@ -51,12 +48,6 @@ test('Import user settings from another user', async ({ page }) => {
5148
await expect(page.getByRole('textbox', { name: 'Project dir' })).toHaveValue(
5249
'/test/import/proj_dir'
5350
);
54-
await expect(page.getByRole('textbox', { name: 'SLURM user' })).toHaveValue(
55-
'test-import-slurm-user'
56-
);
57-
await expect(page.getByLabel('SLURM account #1', { exact: true })).toHaveValue(
58-
'test-import-slurm-account'
59-
);
6051
});
6152

6253
await test.step('Cleanup test group', async () => {

0 commit comments

Comments
 (0)