Update factory-based fs tests to sort properly

This commit is contained in:
Michael Lange 2019-07-31 01:41:00 -07:00
parent 7780713bfa
commit e84604fcdb
2 changed files with 34 additions and 13 deletions

View file

@ -11,6 +11,15 @@ export function findLeader(schema) {
return `${agent.address}:${agent.tags.port}`; return `${agent.address}:${agent.tags.port}`;
} }
export function filesForPath(allocFiles, filterPath) {
return allocFiles.where(
file =>
(!filterPath || file.path.startsWith(filterPath)) &&
file.path.length > filterPath.length &&
!file.path.substr(filterPath.length + 1).includes('/')
);
}
export default function() { export default function() {
this.timing = 0; // delay for each request, automatically set to 0 during testing this.timing = 0; // delay for each request, automatically set to 0 during testing
@ -307,14 +316,7 @@ export default function() {
const clientAllocationFSLsHandler = function({ allocFiles }, { queryParams }) { const clientAllocationFSLsHandler = function({ allocFiles }, { queryParams }) {
// Ignore the task name at the beginning of the path // Ignore the task name at the beginning of the path
const filterPath = queryParams.path.substr(queryParams.path.indexOf('/') + 1); const filterPath = queryParams.path.substr(queryParams.path.indexOf('/') + 1);
const files = filesForPath(allocFiles, filterPath);
const files = allocFiles.where(
file =>
(!filterPath || file.path.startsWith(filterPath)) &&
file.path.length > filterPath.length &&
!file.path.substr(filterPath.length + 1).includes('/')
);
return this.serialize(files); return this.serialize(files);
}; };

View file

@ -6,9 +6,9 @@ import moment from 'moment';
import setupMirage from 'ember-cli-mirage/test-support/setup-mirage'; import setupMirage from 'ember-cli-mirage/test-support/setup-mirage';
import Response from 'ember-cli-mirage/response'; import Response from 'ember-cli-mirage/response';
import moment from 'moment';
import { formatBytes } from 'nomad-ui/helpers/format-bytes'; import { formatBytes } from 'nomad-ui/helpers/format-bytes';
import { filesForPath } from 'nomad-ui/mirage/config';
import FS from 'nomad-ui/tests/pages/allocations/task/fs'; import FS from 'nomad-ui/tests/pages/allocations/task/fs';
@ -16,6 +16,20 @@ let allocation;
let task; let task;
let files; let files;
const fileSort = (prop, files) => {
let dir = [];
let file = [];
files.forEach(f => {
if (f.isDir) {
dir.push(f);
} else {
file.push(f);
}
});
return dir.sortBy(prop).concat(file.sortBy(prop));
};
module('Acceptance | task fs', function(hooks) { module('Acceptance | task fs', function(hooks) {
setupApplicationTest(hooks); setupApplicationTest(hooks);
setupMirage(hooks); setupMirage(hooks);
@ -89,6 +103,8 @@ module('Acceptance | task fs', function(hooks) {
test('navigating allocation filesystem', async function(assert) { test('navigating allocation filesystem', async function(assert) {
await FS.visitPath({ id: allocation.id, name: task.name, path: '/' }); await FS.visitPath({ id: allocation.id, name: task.name, path: '/' });
const sortedFiles = fileSort('name', filesForPath(this.server.schema.allocFiles, '').models);
assert.ok(FS.fileViewer.isHidden); assert.ok(FS.fileViewer.isHidden);
assert.equal(FS.directoryEntries.length, 4); assert.equal(FS.directoryEntries.length, 4);
@ -100,7 +116,7 @@ module('Acceptance | task fs', function(hooks) {
assert.equal(FS.breadcrumbs[0].text, 'task-name'); assert.equal(FS.breadcrumbs[0].text, 'task-name');
FS.directoryEntries[0].as(directory => { FS.directoryEntries[0].as(directory => {
const fileRecord = files[0]; const fileRecord = sortedFiles[0];
assert.equal(directory.name, fileRecord.name, 'directories should come first'); assert.equal(directory.name, fileRecord.name, 'directories should come first');
assert.ok(directory.isDirectory); assert.ok(directory.isDirectory);
assert.equal(directory.size, '', 'directory sizes are hidden'); assert.equal(directory.size, '', 'directory sizes are hidden');
@ -109,7 +125,7 @@ module('Acceptance | task fs', function(hooks) {
}); });
FS.directoryEntries[2].as(file => { FS.directoryEntries[2].as(file => {
const fileRecord = files[4]; const fileRecord = sortedFiles[2];
assert.equal(file.name, fileRecord.name); assert.equal(file.name, fileRecord.name);
assert.ok(file.isFile); assert.ok(file.isFile);
assert.equal(file.size, formatBytes([fileRecord.size])); assert.equal(file.size, formatBytes([fileRecord.size]));
@ -281,9 +297,12 @@ module('Acceptance | task fs', function(hooks) {
test('viewing a file', async function(assert) { test('viewing a file', async function(assert) {
await FS.visitPath({ id: allocation.id, name: task.name, path: '/' }); await FS.visitPath({ id: allocation.id, name: task.name, path: '/' });
await FS.directoryEntries[2].visit();
const fileRecord = files[4]; const sortedFiles = fileSort('name', filesForPath(this.server.schema.allocFiles, '').models);
const fileRecord = sortedFiles.find(f => !f.isDir);
const fileIndex = sortedFiles.indexOf(fileRecord);
await FS.directoryEntries[fileIndex].visit();
assert.equal(FS.breadcrumbsText, `${task.name} ${fileRecord.name}`); assert.equal(FS.breadcrumbsText, `${task.name} ${fileRecord.name}`);