Example component test from Skylight
// from https://www.skylight.io | |
import Ember from "ember"; | |
import { test, moduleForComponent } from 'ember-qunit'; | |
import Util from "app/system/util"; | |
var run = Ember.run; | |
moduleForComponent("billing-trial-status", "billing-trial-status component", { | |
needs: [ | |
'component:calendar-date', | |
'template:components/calendar-date', | |
'helper:format-date' | |
] | |
}); | |
function trim(str) { | |
return str.trim().replace(/\s+/g, ' '); | |
} | |
function dateFor(str) { | |
return window.moment(str).toDate(); | |
} | |
function setNow(str) { | |
Util.adjustedNow = function() { | |
return window.moment(str).toDate(); | |
}; | |
} | |
test("it should show a calendar if there's a trial end date", function() { | |
var component = this.subject(); | |
run(function() { | |
component.set('trialEnd', dateFor("2013-02-08")); | |
}); | |
equal(trim(this.$('.month').text()), "Feb"); | |
equal(trim(this.$('.day-of-month').text()), "08"); | |
}); | |
test("it should state when the trial expires if it has started", function() { | |
var component = this.subject(); | |
run(function() { | |
setNow("2013-02-06"); | |
component.set('trialEnd', dateFor("2013-02-08")); | |
component.set('trialDuration', 30); | |
}); | |
equal(trim(this.$('h3').text()), "Your 30-day trial expires in 2 days on February 8, 2013."); | |
}); | |
test("it should provide instructions if the trial has not yet started", function() { | |
var component = this.subject(); | |
run(function() { | |
setNow("2013-02-06"); | |
component.set('trialDuration', 30); | |
}); | |
equal(trim(this.$('h3').text()), "Your 30-day trial will begin once you create your first application or add a credit card."); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment