2019-06-20 22:20:15 +00:00
|
|
|
import { module, test } from 'qunit';
|
|
|
|
import { setupApplicationTest } from 'ember-qunit';
|
2019-07-02 21:42:38 +00:00
|
|
|
|
2019-06-20 22:20:15 +00:00
|
|
|
import setupMirage from 'ember-cli-mirage/test-support/setup-mirage';
|
2019-07-02 21:42:38 +00:00
|
|
|
import Response from 'ember-cli-mirage/response';
|
|
|
|
|
2020-06-01 13:15:59 +00:00
|
|
|
import browseFilesystem from './behaviors/fs';
|
2019-07-02 21:42:38 +00:00
|
|
|
|
2020-06-01 13:15:59 +00:00
|
|
|
import FS from 'nomad-ui/tests/pages/allocations/fs';
|
2019-06-20 22:20:15 +00:00
|
|
|
|
|
|
|
let allocation;
|
|
|
|
let task;
|
2020-06-01 13:15:59 +00:00
|
|
|
let files, taskDirectory, directory, nestedDirectory;
|
2019-06-20 22:20:15 +00:00
|
|
|
|
|
|
|
module('Acceptance | task fs', function(hooks) {
|
|
|
|
setupApplicationTest(hooks);
|
|
|
|
setupMirage(hooks);
|
|
|
|
|
|
|
|
hooks.beforeEach(async function() {
|
|
|
|
server.create('agent');
|
|
|
|
server.create('node', 'forceIPv4');
|
|
|
|
const job = server.create('job', { createAllocations: false });
|
|
|
|
|
|
|
|
allocation = server.create('allocation', { jobId: job.id, clientStatus: 'running' });
|
|
|
|
task = server.schema.taskStates.where({ allocationId: allocation.id }).models[0];
|
2019-07-02 21:42:38 +00:00
|
|
|
task.name = 'task-name';
|
|
|
|
task.save();
|
2019-07-26 05:44:29 +00:00
|
|
|
|
2020-06-01 13:15:59 +00:00
|
|
|
this.task = task;
|
|
|
|
this.allocation = allocation;
|
|
|
|
|
2019-07-26 05:44:29 +00:00
|
|
|
// Reset files
|
|
|
|
files = [];
|
|
|
|
|
2020-06-01 13:15:59 +00:00
|
|
|
taskDirectory = server.create('allocFile', { isDir: true, name: task.name });
|
|
|
|
files.push(taskDirectory);
|
|
|
|
|
2019-07-26 05:44:29 +00:00
|
|
|
// Nested files
|
2020-06-01 13:15:59 +00:00
|
|
|
directory = server.create('allocFile', { isDir: true, name: 'directory', parent: taskDirectory });
|
|
|
|
files.push(directory);
|
|
|
|
|
|
|
|
nestedDirectory = server.create('allocFile', { isDir: true, name: 'another', parent: directory });
|
|
|
|
files.push(nestedDirectory);
|
|
|
|
|
2019-07-26 05:44:29 +00:00
|
|
|
files.push(
|
|
|
|
server.create('allocFile', 'file', {
|
|
|
|
name: 'something.txt',
|
|
|
|
fileType: 'txt',
|
2020-06-01 13:15:59 +00:00
|
|
|
parent: nestedDirectory,
|
2019-07-26 05:44:29 +00:00
|
|
|
})
|
|
|
|
);
|
|
|
|
|
2020-06-01 13:15:59 +00:00
|
|
|
files.push(server.create('allocFile', { isDir: true, name: 'empty-directory', parent: taskDirectory }));
|
|
|
|
files.push(server.create('allocFile', 'file', { fileType: 'txt', parent: taskDirectory }));
|
|
|
|
files.push(server.create('allocFile', 'file', { fileType: 'txt', parent: taskDirectory }));
|
2019-06-20 22:20:15 +00:00
|
|
|
|
2020-06-01 13:15:59 +00:00
|
|
|
this.files = files;
|
|
|
|
this.directory = directory;
|
|
|
|
this.nestedDirectory = nestedDirectory;
|
2019-06-20 22:20:15 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
test('when the task is not running, an empty state is shown', async function(assert) {
|
2019-09-04 22:38:26 +00:00
|
|
|
// The API 500s on stat when not running
|
|
|
|
this.server.get('/client/fs/stat/:allocation_id', () => {
|
|
|
|
return new Response(500, {}, 'no such file or directory');
|
|
|
|
});
|
|
|
|
|
2019-06-20 22:20:15 +00:00
|
|
|
task.update({
|
|
|
|
finishedAt: new Date(),
|
|
|
|
});
|
|
|
|
|
2020-06-01 13:15:59 +00:00
|
|
|
await FS.visitTask({ id: allocation.id, name: task.name });
|
2019-06-20 22:20:15 +00:00
|
|
|
assert.ok(FS.hasEmptyState, 'Non-running task has no files');
|
|
|
|
assert.ok(
|
|
|
|
FS.emptyState.headline.includes('Task is not Running'),
|
|
|
|
'Empty state explains the condition'
|
|
|
|
);
|
|
|
|
});
|
2019-07-02 21:42:38 +00:00
|
|
|
|
2020-06-01 13:15:59 +00:00
|
|
|
browseFilesystem({
|
|
|
|
visitSegments: ({allocation,task}) => ({ id: allocation.id, name: task.name }),
|
|
|
|
getExpectedPathBase: ({allocation,task}) => `/allocations/${allocation.id}/${task.name}/fs/`,
|
|
|
|
getTitleComponent: ({task}) => `Task ${task.name} filesystem`,
|
|
|
|
getBreadcrumbComponent: ({task}) => task.name,
|
|
|
|
getFilesystemRoot: ({ task }) => task.name,
|
|
|
|
pageObjectVisitFunctionName: 'visitTask',
|
|
|
|
pageObjectVisitPathFunctionName: 'visitTaskPath',
|
2019-07-02 21:42:38 +00:00
|
|
|
});
|
2019-06-20 22:20:15 +00:00
|
|
|
});
|