Last active
December 16, 2023 21:07
-
-
Save shankarsridhar/698517f7a0376b25a4094c6b7b3470b3 to your computer and use it in GitHub Desktop.
Exercise Intro - Objects
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Ember from 'ember'; | |
export default Ember.Controller.extend({ | |
appName: 'Ember Twiddle' | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Ember from 'ember'; | |
export default function destroyApp(application) { | |
Ember.run(application, 'destroy'); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Resolver from '../../resolver'; | |
import config from '../../config/environment'; | |
const resolver = Resolver.create(); | |
resolver.namespace = { | |
modulePrefix: config.modulePrefix, | |
podModulePrefix: config.podModulePrefix | |
}; | |
export default resolver; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Ember from 'ember'; | |
import Application from '../../app'; | |
import config from '../../config/environment'; | |
const { run } = Ember; | |
const assign = Ember.assign || Ember.merge; | |
export default function startApp(attrs) { | |
let application; | |
let attributes = assign({rootElement: "#test-root"}, config.APP); | |
attributes = assign(attributes, attrs); // use defaults, but you can override; | |
run(() => { | |
application = Application.create(attributes); | |
application.setupForTesting(); | |
application.injectTestHelpers(); | |
}); | |
return application; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Application from '../app'; | |
import config from '../config/environment'; | |
import { setApplication } from '@ember/test-helpers'; | |
import { start } from 'ember-qunit'; | |
import { assign } from '@ember/polyfills'; | |
let attributes = assign({ rootElement: '#main' }, config.APP); | |
setApplication(Application.create(attributes)); | |
start(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { module, test } from 'qunit'; | |
import Course from '../../../utils/course'; | |
module('Ember.Object | Modeling Data'); | |
// Replace this with your real tests. | |
test('Correct defaults for data', function(assert) { | |
let course = Course.create(); | |
assert.equal(course.get('title'), 'No Title', 'title defaults to "No Title"'); | |
assert.equal(course.get('description'), '', 'description defaults to empty string'); | |
assert.deepEqual(course.get('tags'), [], 'tags defaults to empty array'); | |
}); | |
test('Adding and removing tags', function(assert) { | |
let course = Course.create(); | |
let otherCourse = Course.create(); | |
course.get('tags').addObject('front end'); | |
assert.equal(otherCourse.get('tags').length, 0, 'Adding tags to a course does not result in it being added to all courses\ncourse1.get("tags").addObject("a");\nshould not additionally add the tag "a" to course2'); | |
}); | |
test('Getting a language from a language ID', function(assert) { | |
let course = Course.create(); | |
assert.ok(typeof course.languageName === 'undefined', 'There should NOT be a function "languageName" on the course instance.\nThe proper place for this function is on the course class (using Ember.Object#reopenClass)'); | |
assert.equal(Course.languageName('js'), 'JavaScript', 'Course.languageName("js") returns "JavaScript"'); | |
assert.equal(Course.languageName(null), 'Unknown', 'Course.languageName() returns "Unknown"'); | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"version": "0.12.1", | |
"EmberENV": { | |
"FEATURES": {} | |
}, | |
"options": { | |
"use_pods": false, | |
"enable-testing": true | |
}, | |
"dependencies": { | |
"jquery": "https://cdnjs.cloudflare.com/ajax/libs/jquery/3.0.0/jquery.js" | |
}, | |
"addons": { | |
"ember-source": "3.4.0", | |
"ember-data": "3.4.0", | |
"ember-cli-htmlbars": "2.0.3", | |
"ember-cli-htmlbars-inline-precompile": "1.0.2" | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Ember from 'ember'; | |
/** | |
* Requirements | |
* | |
* I want to be able to create an instance of | |
* this new type of object | |
* | |
* let myCourse = Course.create(); | |
* | |
* and then we should be able to get and set | |
* serveral properties (title, description, tags) | |
* on this instance | |
* | |
* myCourse.set('description', 'In this course, we'll learn about cats!') | |
* | |
* Additionally, you need to make a class method | |
* for taking abbreviated programming language | |
* names, and expanding them. | |
* | |
* Course.languageName('js') // returns "JavaScript" | |
* | |
* Keep in mind that this function needs to be on the | |
* class, not on instances of the class. | |
*/ | |
const Course = Ember.Object.extend({ | |
}); | |
export default Course; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment