Files
website/test/mod_version.test.coffee
T
Andrew Miner 83868e2760 Massive refactoring to clean up models
* Tweak style of quantity label in output box to be more visible
* Move data files for all mods under a directory for the specific
  version of the mod
* Add a `silent` property to the base model to prevent models which
  shouldn't be observed from emitting events
* Change the term "itemSlug" to just "slug" across the board
* Change all models so that they don't require their parent in their
  constructors and so that they don't automatically add themselves to
  their parents lists
* Remove a bunch of unnecessary event triggering
* Tighten up access to various lists of children across all models
* Refactor the guts of the V2 parser into an abstract base class so
  it can be used for other parsers in the future
* Remove a number of unused methods
2015-01-17 11:49:07 -08:00

65 lines
2.3 KiB
CoffeeScript

###
Crafting Guide - mod_version.test.coffee
Copyright (c) 2014-2015 by Redwood Labs
All rights reserved.
###
Item = require '../src/scripts/models/item'
ModVersion = require '../src/scripts/models/mod_version'
########################################################################################################################
modVersion = null
########################################################################################################################
describe 'ModVersion', ->
beforeEach -> modVersion = new ModVersion name:'Test', version:'0.0'
describe 'constructor', ->
it 'requires a mod name', ->
expect(-> new ModVersion version:'0.0').to.throw Error, 'attributes.name is required'
it 'requires a mod version', ->
expect(-> new ModVersion name:'Test').to.throw Error, 'attributes.version is required'
it 'supplies default values', ->
modVersion.description.should.equal ''
modVersion.enabled.should.be.true
modVersion.slug.should.equal 'test'
describe 'addItem', ->
it 'refuses to add duplicates', ->
modVersion.addItem new Item name:'Wool'
expect(-> modVersion.addItem new Item name:'Wool').to.throw Error, 'duplicate item for Wool'
it 'adds an item indexed by its slug', ->
modVersion.addItem new Item name:'Wool'
modVersion._items.wool.name.should.equal 'Wool'
it 'sets the modVersion', ->
modVersion.addItem new Item name:'Wool'
modVersion._items.wool.modVersion.should.equal modVersion
describe 'compareTo', ->
it 'lists required mods first', ->
minecraft = new ModVersion name:'Minecraft', version:'1.7.10'
modVersion.compareTo(minecraft).should.equal +1
minecraft.compareTo(modVersion).should.equal -1
it 'sorts by name second', ->
buildcraft = new ModVersion name:'Buildcraft', version:'3.0'
modVersion.compareTo(buildcraft).should.equal +1
buildcraft.compareTo(modVersion).should.equal -1
describe 'findItemByName', ->
it 'locates items by slugified name', ->
modVersion.addItem new Item name:'Crafting Table'
modVersion.findItemByName('Crafting Table').slug.should.equal 'crafting_table'