Skip to content

Instantly share code, notes, and snippets.

@caryfitzhugh
Created August 7, 2014 14:00
Show Gist options
  • Save caryfitzhugh/d0b577c6d7ceb4ab6953 to your computer and use it in GitHub Desktop.
Save caryfitzhugh/d0b577c6d7ceb4ab6953 to your computer and use it in GitHub Desktop.
JS Test
test("Test that added_recipes will toggle the detail state", function () {
// Get our recipe
var recipe = Factories.make_recipe({in_box: false});
var other_recipe = Factories.make_recipe();
// Spying -- not needed.
$(document).trigger('recipes.show_recipe', recipe);
// Now make sure that it is showing the "Save Recipe" button
// Meaning the 'in-box' class is not present
ok(this.$node.find('.controls .recipe.in-box').length === 0);
ok(this.$node.find('.controls .recipe').length === 1);
// Now we emit the "recipe" was added
$(document).trigger('recipes.added_recipe', recipe);
// Should now say "in box"
ok(this.$node.find('.controls .recipe.in-box').length === 1);
ok(this.$node.find('.controls .recipe').length === 0);
});
test("Test that added_recipes with a different recipe will NOT toggle the detail state", function () {
// Get our recipe
var recipe = Factories.make_recipe({in_box: false});
var other_recipe = Factories.make_recipe();
// Spying -- not needed.
$(document).trigger('recipes.show_recipe', recipe);
// Now make sure that it is showing the "Save Recipe" button
// Meaning the 'in-box' class is not present
ok(this.$node.find('.controls .recipe.in-box').length === 0);
ok(this.$node.find('.controls .recipe').length === 1);
// Now we emit the "other_recipe" was added, nothing should change
$(document).trigger('recipes.added_recipe', other_recipe);
// Nothing should change, still Save Recipe
ok(this.$node.find('.controls .recipe.in-box').length === 0);
ok(this.$node.find('.controls .recipe').length === 1);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment