-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #583 from fractal-analytics-platform/align-server-2.7
Alignment with fractal-server 2.7
- Loading branch information
Showing
52 changed files
with
1,050 additions
and
842 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,94 @@ | ||
import { describe, it, beforeEach, expect, vi } from 'vitest'; | ||
import { render, screen } from '@testing-library/svelte'; | ||
import userEvent from '@testing-library/user-event'; | ||
|
||
// Mocking fetch | ||
global.fetch = vi.fn(); | ||
|
||
const mockedUser = { | ||
group_ids_names: [ | ||
[1, 'All'], | ||
[2, 'Group2'] | ||
] | ||
}; | ||
|
||
// The component to be tested must be imported after the mock setup | ||
import AddSingleTask from '../../src/lib/components/v2/tasks/AddSingleTask.svelte'; | ||
|
||
describe('AddSingleTask', () => { | ||
beforeEach(() => { | ||
fetch.mockClear(); | ||
}); | ||
|
||
it('Add single task associated with specific group', async () => { | ||
const user = userEvent.setup(); | ||
|
||
fetch.mockResolvedValue({ | ||
ok: true, | ||
status: 200, | ||
json: async () => ({}) | ||
}); | ||
|
||
render(AddSingleTask, { | ||
props: { | ||
user: mockedUser, | ||
addNewTasks: vi.fn() | ||
} | ||
}); | ||
|
||
await user.type(screen.getByRole('textbox', { name: 'Task name' }), 'test-task'); | ||
await user.type(screen.getByRole('textbox', { name: 'Command non parallel' }), 'command'); | ||
await user.type(screen.getByRole('textbox', { name: 'Source' }), 'task-source'); | ||
await user.selectOptions(screen.getByRole('combobox', { name: 'Group' }), 'Group2'); | ||
await user.click(screen.getByRole('button', { name: 'Create' })); | ||
|
||
expect(fetch).toHaveBeenCalledWith( | ||
'/api/v2/task?private=false&user_group_id=2', | ||
expect.objectContaining({ | ||
body: JSON.stringify({ | ||
name: 'test-task', | ||
command_non_parallel: 'command', | ||
source: 'task-source', | ||
input_types: {}, | ||
output_types: {} | ||
}) | ||
}) | ||
); | ||
}); | ||
|
||
it('Add private task', async () => { | ||
const user = userEvent.setup(); | ||
|
||
fetch.mockResolvedValue({ | ||
ok: true, | ||
status: 200, | ||
json: async () => ({}) | ||
}); | ||
|
||
render(AddSingleTask, { | ||
props: { | ||
user: mockedUser, | ||
addNewTasks: vi.fn() | ||
} | ||
}); | ||
|
||
await user.type(screen.getByRole('textbox', { name: 'Task name' }), 'test-task'); | ||
await user.type(screen.getByRole('textbox', { name: 'Command non parallel' }), 'command'); | ||
await user.type(screen.getByRole('textbox', { name: 'Source' }), 'task-source'); | ||
await user.click(screen.getByText('Private task')); | ||
await user.click(screen.getByRole('button', { name: 'Create' })); | ||
|
||
expect(fetch).toHaveBeenCalledWith( | ||
'/api/v2/task?private=true', | ||
expect.objectContaining({ | ||
body: JSON.stringify({ | ||
name: 'test-task', | ||
command_non_parallel: 'command', | ||
source: 'task-source', | ||
input_types: {}, | ||
output_types: {} | ||
}) | ||
}) | ||
); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,166 @@ | ||
import { describe, it, beforeEach, expect, vi } from 'vitest'; | ||
import { render, screen, waitFor } from '@testing-library/svelte'; | ||
|
||
// Mocking fetch | ||
global.fetch = vi.fn(); | ||
|
||
// Mocking bootstrap.Modal | ||
class MockModal { | ||
constructor() { | ||
this.show = vi.fn(); | ||
this.hide = vi.fn(); | ||
} | ||
} | ||
MockModal.getInstance = vi.fn(); | ||
|
||
global.window.bootstrap = { | ||
Modal: MockModal | ||
}; | ||
|
||
const mockedWorkflow = { | ||
id: 20, | ||
name: 'test', | ||
project_id: 24, | ||
task_list: [] | ||
}; | ||
|
||
// The component to be tested must be imported after the mock setup | ||
import AddWorkflowTaskModal from '../../src/lib/components/v2/workflow/AddWorkflowTaskModal.svelte'; | ||
|
||
describe('AddWorkflowTaskModal', () => { | ||
beforeEach(() => { | ||
fetch.mockClear(); | ||
}); | ||
|
||
it('Display task with loosely valid version', async () => { | ||
fetch.mockResolvedValue({ | ||
ok: true, | ||
status: 200, | ||
json: async () => [ | ||
{ | ||
id: 1, | ||
task_list: [ | ||
{ | ||
id: 1, | ||
name: 'test_task', | ||
taskgroupv2_id: 1, | ||
category: null, | ||
modality: null, | ||
authors: null, | ||
tags: [] | ||
} | ||
], | ||
user_id: 1, | ||
user_group_id: 1, | ||
pkg_name: 'test_task_package', | ||
version: '0.0.1', | ||
active: true | ||
}, | ||
{ | ||
id: 2, | ||
task_list: [ | ||
{ | ||
id: 2, | ||
name: 'test_task', | ||
taskgroupv2_id: 2, | ||
category: null, | ||
modality: null, | ||
authors: null, | ||
tags: [] | ||
} | ||
], | ||
user_id: 1, | ||
user_group_id: 1, | ||
pkg_name: 'test_task_package', | ||
version: '0.7.10.dev4+g4c8ebe3', | ||
active: true | ||
} | ||
] | ||
}); | ||
|
||
const result = render(AddWorkflowTaskModal, { | ||
props: { | ||
workflow: mockedWorkflow, | ||
onWorkflowTaskAdded: vi.fn() | ||
} | ||
}); | ||
|
||
result.component.show(); | ||
|
||
await waitFor(() => screen.getByText(/Add new workflow task/)); | ||
expect(fetch).toHaveBeenCalledWith('/api/v2/task-group', expect.anything()); | ||
await waitFor(() => screen.getAllByText(/test_task/)); | ||
|
||
const dropdown = screen.getByRole('combobox'); | ||
expect(dropdown.options.length).eq(2); | ||
expect(dropdown.options[0].text).eq('0.7.10.dev4+g4c8ebe3'); | ||
expect(dropdown.options[1].text).eq('0.0.1'); | ||
expect(dropdown.value).eq('0.7.10.dev4+g4c8ebe3'); | ||
}); | ||
|
||
it('Display task with invalid version', async () => { | ||
fetch.mockResolvedValue({ | ||
ok: true, | ||
status: 200, | ||
json: async () => [ | ||
{ | ||
id: 1, | ||
task_list: [ | ||
{ | ||
id: 1, | ||
name: 'test_task', | ||
taskgroupv2_id: 1, | ||
category: null, | ||
modality: null, | ||
authors: null, | ||
tags: [] | ||
} | ||
], | ||
user_id: 1, | ||
user_group_id: 1, | ||
pkg_name: 'test_task_package', | ||
version: '0.0.1', | ||
active: true | ||
}, | ||
{ | ||
id: 2, | ||
task_list: [ | ||
{ | ||
id: 2, | ||
name: 'test_task', | ||
taskgroupv2_id: 2, | ||
category: null, | ||
modality: null, | ||
authors: null, | ||
tags: [] | ||
} | ||
], | ||
user_id: 1, | ||
user_group_id: 1, | ||
pkg_name: 'test_task_package', | ||
version: 'INVALID', | ||
active: true | ||
} | ||
] | ||
}); | ||
|
||
const result = render(AddWorkflowTaskModal, { | ||
props: { | ||
workflow: mockedWorkflow, | ||
onWorkflowTaskAdded: vi.fn() | ||
} | ||
}); | ||
|
||
result.component.show(); | ||
|
||
await waitFor(() => screen.getByText(/Add new workflow task/)); | ||
expect(fetch).toHaveBeenCalledWith('/api/v2/task-group', expect.anything()); | ||
await waitFor(() => screen.getAllByText(/test_task/)); | ||
|
||
const dropdown = screen.getByRole('combobox'); | ||
expect(dropdown.options.length).eq(2); | ||
expect(dropdown.options[0].text).eq('0.0.1'); | ||
expect(dropdown.options[1].text).eq('INVALID'); | ||
expect(dropdown.value).eq('0.0.1'); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
import { describe, it, beforeEach, expect, vi } from 'vitest'; | ||
import { render, screen } from '@testing-library/svelte'; | ||
import userEvent from '@testing-library/user-event'; | ||
|
||
// Mocking fetch | ||
global.fetch = vi.fn(); | ||
|
||
// Mocking public variables | ||
vi.mock('$env/dynamic/public', () => { | ||
return { env: {} }; | ||
}); | ||
|
||
const mockedUser = { | ||
group_ids_names: [ | ||
[1, 'All'], | ||
[2, 'Group2'] | ||
] | ||
}; | ||
|
||
// The component to be tested must be imported after the mock setup | ||
import TaskCollection from '../../src/lib/components/v2/tasks/TaskCollection.svelte'; | ||
|
||
describe('TaskCollection', () => { | ||
beforeEach(() => { | ||
fetch.mockClear(); | ||
}); | ||
|
||
it('Add single task associated with specific group', async () => { | ||
const user = userEvent.setup(); | ||
|
||
fetch.mockResolvedValue({ | ||
ok: true, | ||
status: 200, | ||
json: async () => ({ data: {} }) | ||
}); | ||
|
||
render(TaskCollection, { | ||
props: { | ||
user: mockedUser, | ||
reloadTaskList: vi.fn() | ||
} | ||
}); | ||
|
||
await user.type(screen.getByRole('textbox', { name: 'Package' }), 'test-task'); | ||
await user.selectOptions(screen.getByRole('combobox', { name: 'Group' }), 'Group2'); | ||
await user.click(screen.getByRole('button', { name: 'Collect' })); | ||
|
||
expect(fetch).toHaveBeenCalledWith( | ||
'/api/v2/task/collect/pip?private=false&user_group_id=2', | ||
expect.objectContaining({ | ||
body: JSON.stringify({ package: 'test-task' }) | ||
}) | ||
); | ||
}); | ||
|
||
it('Add private task', async () => { | ||
const user = userEvent.setup(); | ||
|
||
fetch.mockResolvedValue({ | ||
ok: true, | ||
status: 200, | ||
json: async () => ({ data: {} }) | ||
}); | ||
|
||
render(TaskCollection, { | ||
props: { | ||
user: mockedUser, | ||
reloadTaskList: vi.fn() | ||
} | ||
}); | ||
|
||
await user.type(screen.getByRole('textbox', { name: 'Package' }), 'test-task'); | ||
await user.click(screen.getByText('Private task')); | ||
await user.click(screen.getByRole('button', { name: 'Collect' })); | ||
|
||
expect(fetch).toHaveBeenCalledWith( | ||
'/api/v2/task/collect/pip?private=true', | ||
expect.objectContaining({ | ||
body: JSON.stringify({ package: 'test-task' }) | ||
}) | ||
); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.