How to use the ember-cli-mirage.trait function in ember-cli-mirage

To help you get started, we’ve selected a few ember-cli-mirage examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github hashicorp / levant / vendor / github.com / hashicorp / nomad / ui / mirage / factories / job.js View on Github external
// serializer update for bool vs details object
    parameterizedDetails: () => ({
      MetaOptional: null,
      MetaRequired: null,
      Payload: Math.random() > 0.5 ? 'required' : null,
    }),
  }),

  periodicChild: trait({
    // Periodic children need a parent job,
    // It is the Periodic job's responsibility to create
    // periodicChild jobs and provide a parent job.
    type: 'batch',
  }),

  parameterizedChild: trait({
    // Parameterized children need a parent job,
    // It is the Parameterized job's responsibility to create
    // parameterizedChild jobs and provide a parent job.
    type: 'batch',
    parameterized: true,
    dispatched: true,
    payload: window.btoa(faker.lorem.sentence()),
  }),

  createIndex: i => i,
  modifyIndex: () => faker.random.number({ min: 10, max: 2000 }),

  // Directive used to control sub-resources

  // When false, no allocations are made
  createAllocations: true,
github hashicorp / nomad / ui / mirage / factories / alloc-file.js View on Github external
dir: trait({
    isDir: true,
    afterCreate(allocFile, server) {
      // create files for the directory
      if (allocFile.depth > 0) {
        server.create('allocFile', 'dir', { parent: allocFile, depth: allocFile.depth - 1 });
      }

      server.createList('allocFile', faker.random.number({ min: 1, max: 3 }), 'file', {
        parent: allocFile,
      });
    },
  }),

  file: trait({
    isDir: false,
  }),
});
github hashicorp / levant / vendor / github.com / hashicorp / nomad / ui / mirage / factories / job-summary.js View on Github external
import { Factory, faker, trait } from 'ember-cli-mirage';

export default Factory.extend({
  // Hidden property used to compute the Summary hash
  groupNames: [],

  JobID: '',
  namespace: null,

  withSummary: trait({
    Summary: function() {
      return this.groupNames.reduce((summary, group) => {
        summary[group] = {
          Queued: faker.random.number(10),
          Complete: faker.random.number(10),
          Failed: faker.random.number(10),
          Running: faker.random.number(10),
          Starting: faker.random.number(10),
          Lost: faker.random.number(10),
        };
        return summary;
      }, {});
    },
  }),

  withChildren: trait({
github CenterForOpenScience / ember-osf-web / mirage / factories / node.ts View on Github external
const identifier = server.create('identifier', { referent: node });
            // eslint-disable-next-line no-param-reassign
            node.identifiers = [identifier] as unknown as Collection;
            node.save();
        },
    }),

    withLicense: trait({
        afterCreate(node, server) {
            const license = faker.random.arrayElement(server.schema.licenses.all().models);
            node.license = license; // eslint-disable-line no-param-reassign
            node.save();
        },
    }),

    withAffiliatedInstitutions: trait({
        afterCreate(node, server) {
            const affiliatedInstitutionCount = faker.random.number({ min: 4, max: 5 });
            server.createList('institution', affiliatedInstitutionCount, {
                nodes: [node],
            });
        },
    }),

    withManyAffiliatedInstitutions: trait({
        afterCreate(node, server) {
            server.createList('institution', 15, {
                nodes: [node],
            });
        },
    }),
github hashicorp / nomad / ui / mirage / factories / allocation.js View on Github external
allocation,
          name: task.name,
          resources: generateResources({
            CPU: task.resources.CPU,
            MemoryMB: task.resources.MemoryMB,
            DiskMB: task.resources.DiskMB,
            networks: { minPorts: 1 },
          }),
        });
      });

      allocation.update({ taskResourceIds: resources.mapBy('id') });
    },
  }),

  withoutTaskWithPorts: trait({
    afterCreate(allocation, server) {
      const taskGroup = server.db.taskGroups.findBy({ name: allocation.taskGroup });
      const resources = taskGroup.taskIds.map(id => {
        const task = server.db.tasks.find(id);
        return server.create('task-resource', {
          allocation,
          name: task.name,
          resources: generateResources({
            CPU: task.resources.CPU,
            MemoryMB: task.resources.MemoryMB,
            DiskMB: task.resources.DiskMB,
            networks: { minPorts: 0, maxPorts: 0 },
          }),
        });
      });
github CenterForOpenScience / ember-osf-web / mirage / factories / registration.ts View on Github external
'comment', 3,
                { node: registration, targetID: registration.id, targetType: 'registrations' },
                'withReplies',
            );
        },
    }),
    isPendingApproval: trait({
        ...stateAttrs.pendingApproval,
    }),
    isArchiving: trait({
        ...stateAttrs.archiving,
    }),
    isEmbargoed: trait({
        ...stateAttrs.embargoed,
    }),
    isPendingEmbargoApproval: trait({
        ...stateAttrs.pendingEmbargoApproval,
    }),
    isPendingWithdrawal: trait({
        ...stateAttrs.pendingWithdrawal,
    }),
    isPendingEmbargoTerminationApproval: trait({
        ...stateAttrs.pendingEmbargoTerminationApproval,
    }),
    isWithdrawn: trait({
        ...stateAttrs.withdrawn,
    }),
    isPublic: trait({
        ...stateAttrs.normal,
    }),
    withAffiliatedInstitutions: trait({
        afterCreate(registration, server) {