Example #1
0
test('navigates to correct url', async function(assert) {
  const order = make('sales_order');
  mockFindAll('order').returns({models: [order]});
  mockFind('order').returns({model: order});

  await page.visit({id:order.get('id')});

  assert.equal(currentURL(), `/sales-orders/${order.get('id')}`);
});
Example #2
0
test("should display warning banner when deliveryDate param <= today", async function(assert) {
  mockFindAll("order");
  mockFind("order");

  const deliveryDate = moment().format("YYYY-MM-DD");

  await page.visit({deliveryDate});
  assert.ok(page.bannerIsVisible);
});
    Ember.run(function() {
      let done = assert.async();
      let profile = mockFind('profile', { description: 'dude' });
      let profileId = profile.get('id');

      FactoryGuy.store.find('profile', profileId).then(function(profile) {
        ok(profile.get('description') === 'dude');
        done();
      });
    });
Example #4
0
test('displays the correct sales order', async function(assert) {
  const location = make('location');
  const order = make('order', {location});
  mockFindAll('order').returns({models: [order]});
  mockFind('order').returns({model: order});

  await page.visit({id:order.get('id')});

  assert.equal(orderEditorPO.locationName, `${location.get('code')} - ${location.get('name')}`, 'sales order location name did not match expected');
});
test("Show employee by make(ing) a model and using returns with that model", function () {
  let employee = make('employee', 'with_department_employments');

  mockFind('employee').returns({model: employee});
  visit('/employee/' + employee.get('id'));

  andThen(()=>{
    ok(find('.name').text().match(`${employee.get('name.firstName')} ${employee.get('name.lastName')}`));
    equal(find('.department-employment').length, 2, "fragment array works");
  });
});
    Ember.run(function() {
      let done = assert.async();
      let profile = mockFind('profile');
      let profileId = profile.get('id');

      FactoryGuy.store.find('profile', profileId).then(function(profile) {
        equal(profile.get('id'), profileId);
        equal(profile.get('description'), 'Text goes here');
        done();
      });
    });
    Ember.run(function() {
      let done = assert.async();
      let user = mockFind('user', 'with_hats');
      let userId = user.get('id');

      FactoryGuy.store.find('user', userId).then(function(user) {
        ok(user.get('hats.length') === 2);
        ok(user.get('hats.firstObject.type') === 'BigHat');
        done();
      });
    });
    Ember.run(function() {
      let done = assert.async();
      let profile = mockFind('profile', 'with_company', 'with_bat_man');
      let profileId = profile.get('id');

      FactoryGuy.store.find('profile', profileId).then(function(profile) {
        ok(profile.get('company.name') === 'Silly corp');
        ok(profile.get('superHero.name') === 'BatMan');
        done();
      });
    });
test("Show employee by building(ing) json and using returns with that json", function () {
  let employee = build('employee', 'with_department_employments');

  mockFind('employee').returns({json: employee});
  visit('/employee/' + employee.get('id'));

  andThen(()=>{
    ok(find('.name').text().match(`${employee.get('name').firstName} ${employee.get('name').lastName}`));
    equal(find('.department-employment').length, 2, "fragment array works");
  });
});
    Ember.run(function() {
      let done = assert.async();

      let profile = mockFind('profile');
      let profileId = profile.get('id');

      FactoryGuy.store.find('profile', profileId).then(function(profile) {
        ok(profile.get('camelCaseDescription') === 'textGoesHere');
        ok(profile.get('snake_case_description') === 'text_goes_here');
        done();
      });
    });
  Ember.run(()=> {
    const done = assert.async();

    const response = { errors: { description: ['bad'] } };
    const mock = mockFind('profile', 1).fails({ response });

    FactoryGuy.store.findRecord('profile', 1)
      .catch((res)=> {
        equal(mock.timesCalled, 1);
        ok(true);
        done();
      });
  });
    Ember.run(function() {
      let done = assert.async();

      let model = make('profile', 'with_company', 'with_bat_man');
      let profile = mockFind('profile').returns({model});
      let profileId = profile.get('id');

      FactoryGuy.store.find('profile', profileId).then(function(profile) {
        ok(profile.get('company.name') === 'Silly corp');
        ok(profile.get('superHero.name') === 'BatMan');
        equal(FactoryGuy.store.peekAll('profile').get('content').length, 1, "does not make another profile");
        done();
      });
    });
Example #13
0
test('can delete sales order', async function(assert) {
  const order = make('order');
  mockFindAll('order').returns({models: [order]});
  mockFind('order').returns({model: order});

  await page.visit({id:order.get('id')});

  assert.equal(currentURL(), `/sales-orders/${order.get('id')}`);

  mockDelete('order', order.get('id'));
  await orderEditorPO.deleteOrder();

  assert.equal(currentURL(), `/sales-orders`);
});
test("Show user by make(ing) a model and using returns with that model", function () {
  // make a user with projects ( which will be in the store )
  let user = make('user', 'with_projects');
  let projects = user.get('projects');
  mockFind('user').returns({model: user});

  visit('/user/' + user.get('id'));

  andThen(()=>{
    ok(find('.name').text().match(user.get('name')));
    ok(find('li.project:first').text().match(projects.get('firstObject.title')));
    ok(find('li.project:last').text().match(projects.get('lastObject.title')));
  });
});
test("Show user with projects by build(ing) json and using returns with json", function () {
  // build a user with projects ( which will be in the store )
  let projects = buildList('project', {title: 'Moo'}, {title: 'Zoo'});
  let user = build('user', {projects: projects});
  mockFind('user').returns({json: user});

  visit('/user/' + user.get('id'));

  andThen(()=>{
    ok(find('.name').text().match(user.get('name')));
    ok(find('li.project:first').text().match(projects.get(0).title));
    ok(find('li.project:last').text().match(projects.get(1).title));
  });
});
    Ember.run(function() {
      let done = assert.async();

      let hat1 = build('big-hat');
      let hat2 = build('big-hat');
      let json = build('user', {hats: [hat1, hat2]});

      mockFind('user').returns({json});

      FactoryGuy.store.find('user', json.get('id')).then(function(user) {
        ok(user.get('hats.firstObject.id') === hat1.get('id') +'');
        ok(user.get('hats.lastObject.id')  === hat2.get('id') +'');
        done();
      });
    });
Example #17
0
test('can add order item manually', async function(assert) {
  const order = make('order');
  mockFindAll('order').returns({models: [order]});
  mockFind('order').returns({model: order});
  mockCreate("order-item");
  const items = makeList("product", 10);

  mockFindAll('item').returns({models: items});

  await page.visit({id:order.get('id')});

  assert.equal(orderEditorPO.salesOrderItems().count, 0);

  await orderEditorPO.addProduct(items[0]);

  assert.equal(orderEditorPO.salesOrderItems().count, 1);
  assert.equal(orderEditorPO.salesOrderItems(0).name, items[0].get("name"));
});
  Ember.run(()=> {
    let done = assert.async();

    let response = { errors: { description: ['bad'] } };
    let mock = mockFind('profile', 1).fails({ response });

    FactoryGuy.store.findRecord('profile', 1)
      .catch((res)=> {
        //let errors = profile.get('errors.messages')[0];
        //console.log('AA',invalidError.errors);
        //console.log('BB',profile.get('errors.messages'));
        //console.log(profile.get('errors'))
        //equal(errors.title, 'invalid description');
        //equal(errors.detail, 'bad');
        equal(mock.timesCalled, 1);
        ok(true);
        done();
      });
  });
Example #19
0
test('adding an item manually still uses price-tier price', async function(assert) {
  const item = make("product");
  const priceTier = make("price-tier");
  make("item-price", {item, price:2.5, priceTier});
  
  const company = make("company", {priceTier});
  const location = make("location", {company});
  const order = make('order', {location});

  mockFindAll('order').returns({models: [order]});
  mockFind('order').returns({model: order});
  mockCreate("order-item");

  mockFindAll('item').returns({models: [item]});

  await page.visit({id:order.get('id')});
  await orderEditorPO.addProduct(item);

  assert.equal(orderEditorPO.salesOrderItems(0).total, "$2.50");
});
test("Add a project to a user with mockCreate", function () {
  // mockFind will build a default user for the json payload
  let mock = mockFind('user');

  visit('/user/' + mock.get('id'));

  let newProjectTitle = "Gonzo Project";

  andThen(()=> {
    // should be no projects
    equal(find('li.project').length, 0);

    fillIn('input.project-title', newProjectTitle);

    // Remember, this is for handling an exact match, if you did not care about
    // matching attributes, you could just do: TestHelper.mockCreate('project')
    mockCreate('project').match({title: newProjectTitle});

    /**
     Let's say that clicking this 'button:contains(Add New User)', triggers action in the
     view to create project record and looks something like this:

     actions: {
       addProject: function (user) {
         let title = this.$('input.project-title').val();
         let store = this.get('controller.store');
         store.createRecord('project', {title: title, user: user}).save();
       }
     }

    */
    click('button:contains(Add New User)');

    andThen(()=> {
      let newProjectDiv = find('li.project:contains(' + newProjectTitle + ')');
      ok(newProjectDiv[0]);
    });
  });
});
  // mockUpdate,
  mockFindAll
} from 'ember-data-factory-guy';

let company,
    locations;

moduleForAcceptance('Acceptance | customers/show/location/location address', {
  beforeEach() {
    authenticateSession(this.application);

    company = make('company');
    locations = makeList('location', {company}, 3);

    mockFindAll('company').returns({models: [company]});
    mockFind('company').returns({model: company});
    mockFind('location').returns({model: locations[0]});
    mockFindAll('location').returns({models: locations});
    mockFindAll('item', 5);
    mockFindAll('price-tier', 1);
  }
});

// test('can add address info to location', async function(assert) {
//   const fullAddress = '86 7th Avenue, New York City, New York 11217';
//   const location = locations[0];
//   const address = await location.get('address');
//
//   await page.visit({company_id:company.get('id'), location_id:location.get('id')})
//
//   assert.equal(addressPO.fullAddress, address.get('full'), 'Street address did not match');
test("with json", function() {
  const json = { id: 1, name: "Dan" };
  const mock = mockFind('user').returns({ json });
  equal(mock.getUrl(), '/users/1');
});
test("with proxy", function() {
  const json = build('user');
  const mock = mockFind('user').returns({ json });
  equal(mock.getUrl(), '/users/1');
});
test("#get method to access payload", function() {
  let mock = mockFind('user');
  equal(mock.get('name'), 'User1');
});
test("has access to handler being used by mockjax", function() {
  let mock = mockFind('user');
  ok(mock.handler);
});