Skip to content

Instantly share code, notes, and snippets.

@phillipkregg
Last active July 18, 2016 21:32
Show Gist options
  • Save phillipkregg/e48f406138bba9a5d70960a4a78da71f to your computer and use it in GitHub Desktop.
Save phillipkregg/e48f406138bba9a5d70960a4a78da71f to your computer and use it in GitHub Desktop.
Shopping Cart Test
import Ember from 'ember';
export default Ember.Controller.extend({
appName: 'Ember Twiddle'
});
import Ember from 'ember';
export default Ember.Service.extend({
items: [],
add(item) {
var items = this.get('items');
debugger;
items.push(item);
//return item;
}
});
body {
margin: 12px 16px;
font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif;
font-size: 12pt;
}
<h1>Welcome to {{appName}}</h1>
<br>
<br>
{{outlet}}
<br>
<br>
import Resolver from '../../resolver';
import config from '../../config/environment';
const resolver = Resolver.create();
resolver.namespace = {
modulePrefix: config.modulePrefix,
podModulePrefix: config.podModulePrefix
};
export default resolver;
import resolver from './helpers/resolver';
import {
setResolver
} from 'ember-qunit';
setResolver(resolver);
import { moduleFor, test } from 'ember-qunit';
moduleFor('service:shopping-cart', 'Unit | Service | cart', {
beforeEach() {
var cart = this.subject();
cart.set('items', []);
}
});
// Replace this with your real tests.
test('it exists', function(assert) {
let service = this.subject();
assert.ok(service);
});
test('add() adds item to cart', function(assert) {
var cart = this.subject();
cart.add({ id: 1, product: 'movie 1', quantity: 1 });
cart.add({ id: 2, product: 'movie 2', quantity: 1 });
console.log(cart.get('items'));
assert.deepEqual(cart.get('items'), [
{ id: 1, product: 'movie 1', quantity: 1 },
{ id: 2, product: 'movie 2', quantity: 1 }
])
});
test('add() - updates the quantity by 1 when a duplicate item is added to the cart', function() {
var cart = this.subject();
var items;
cart.add({ id: 1, product: 'movie 1' });
cart.add({ id: 1, product: 'movie 1' });
items = JSON.parse(window.sessionStorage.getItem('cart-test'));
});
{
"version": "0.10.1",
"EmberENV": {
"FEATURES": {}
},
"options": {
"use_pods": false,
"enable-testing": true
},
"dependencies": {
"jquery": "https://cdnjs.cloudflare.com/ajax/libs/jquery/1.11.3/jquery.js",
"ember": "2.6.0",
"ember-data": "2.6.1",
"ember-template-compiler": "2.6.0"
},
"addons": {}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment