diff --git a/js-jasmine/spec/shop_spec.js b/js-jasmine/spec/shop_spec.js index 8fec1b9f..072281ac 100644 --- a/js-jasmine/spec/shop_spec.js +++ b/js-jasmine/spec/shop_spec.js @@ -8,84 +8,96 @@ describe('Shop', () => { }; const gildedRose = new Shop([item]); describe('.updateQuality', () => { - it("keeps name the same", () => { - item.name = 'foo'; - items = gildedRose.updateQuality(); - expect(items[0].name).toEqual('foo'); + describe('Standard item', () => { + beforeEach(() => { + item.name = 'foo'; + }); + it("keeps name the same", () => { + items = gildedRose.updateQuality(); + expect(items[0].name).toEqual('foo'); + }); + it('decreases sellIn by 1', () => { + item.sellIn = 5; + const items = gildedRose.updateQuality(); + expect(items[0].sellIn).toEqual(5 - 1); + }); + it('decreases qualtiy by 1', () => { + item.sellIn = 5; + item.quality = 5; + const items = gildedRose.updateQuality(); + expect(items[0].quality).toEqual(5 - 1); + }); + it('when sell by passed, decreases quality by 2', () => { + item.sellIn = 0; + item.quality = 5; + const items = gildedRose.updateQuality(); + expect(items[0].quality).toEqual(5 - 2); + }); + it('will not reduce quality below 0', () => { + item.quality = 0; + const items = gildedRose.updateQuality(); + expect(items[0].quality).toEqual(0); + }); }); - it('decreases sellIn by 1', () => { - item.name = 'foo'; - item.sellIn = 5; - const items = gildedRose.updateQuality(); - expect(items[0].sellIn).toEqual(5 - 1); + + describe('Aged Brie', () => { + beforeEach(() => { + item.name = 'Aged Brie'; + }); + it('will increase the quality by 1', () => { + item.sellIn = 5; + item.quality = 5; + const items = gildedRose.updateQuality(); + expect(items[0].quality).toEqual(5 + 1); + }); + it('will not increase quality above 50', () => { + item.quality = 50; + const items = gildedRose.updateQuality(); + expect(items[0].quality).toEqual(50); + }); }); - it('decreases qualtiy by 1', () => { - item.name = 'foo'; - item.sellIn = 5; - item.quality = 5; - const items = gildedRose.updateQuality(); - expect(items[0].quality).toEqual(5 - 1); + + describe('Sulfuras', () => { + beforeEach(() => { + item.name = 'Sulfuras, Hand of Ragnaros'; + }); + it('will not change the sellIn or quality', () => { + item.sellIn = 5; + item.quality = 5; + const items = gildedRose.updateQuality(); + expect(items[0].sellIn).toEqual(5); + expect(items[0].quality).toEqual(5); + }); }); - it('when sell by passed, decreases quality by 2', () => { - item.name = 'foo'; - item.sellIn = 0; - item.quality = 5; - const items = gildedRose.updateQuality(); - expect(items[0].quality).toEqual(5 - 2); - }); - it('will not reduce quality below 0', () => { - item.name = 'foo'; - item.quality = 0; - const items = gildedRose.updateQuality(); - expect(items[0].quality).toEqual(0); - }); - it('will increase the quality of Aged Brie by 1', () => { - item.name = 'Aged Brie'; - item.quality = 5; - const items = gildedRose.updateQuality(); - expect(items[0].quality).toEqual(5 + 1); - }); - it('will not increase quality above 50', () => { - item.name = 'Aged Brie'; - item.quality = 50; - const items = gildedRose.updateQuality(); - expect(items[0].quality).toEqual(50); - }); - it('will not change the sellIn or quality of Sulfuras', () => { - item.name = 'Sulfuras, Hand of Ragnaros'; - item.sellIn = 5; - item.quality = 5; - const items = gildedRose.updateQuality(); - expect(items[0].sellIn).toEqual(5); - expect(items[0].quality).toEqual(5); - }); - it('will increase the quality of backstage passes by 1, more than 10 days before the concert', () => { - item.name = 'Backstage passes to a TAFKAL80ETC concert'; - item.sellIn = 11; - item.quality = 5; - const items = gildedRose.updateQuality(); - expect(items[0].quality).toEqual(6); - }); - it('will increase the quality of backstage passes by 2, 10 - 6 days before the concert', () => { - item.name = 'Backstage passes to a TAFKAL80ETC concert'; - item.sellIn = 8; - item.quality = 5; - const items = gildedRose.updateQuality(); - expect(items[0].quality).toEqual(7); - }); - it('will increase the quality of backstage passes by 3, 5 or less days before the concert', () => { - item.name = 'Backstage passes to a TAFKAL80ETC concert'; - item.sellIn = 5; - item.quality = 5; - const items = gildedRose.updateQuality(); - expect(items[0].quality).toEqual(8); - }); - it('will decrease the quality of backstage passes to 0 after concert.', () => { - item.name = 'Backstage passes to a TAFKAL80ETC concert'; - item.sellIn = 0; - item.quality = 5; - const items = gildedRose.updateQuality(); - expect(items[0].quality).toEqual(0); + + describe('Backstage passes', () => { + beforeEach(() => { + item.name = 'Backstage passes to a TAFKAL80ETC concert'; + }); + it('will increase the quality by 1, more than 10 days before the concert', () => { + item.sellIn = 11; + item.quality = 5; + const items = gildedRose.updateQuality(); + expect(items[0].quality).toEqual(6); + }); + it('will increase the quality by 2, 10 - 6 days before the concert', () => { + item.sellIn = 8; + item.quality = 5; + const items = gildedRose.updateQuality(); + expect(items[0].quality).toEqual(7); + }); + it('will increase the quality by 3, 5 or less days before the concert', () => { + item.sellIn = 5; + item.quality = 5; + const items = gildedRose.updateQuality(); + expect(items[0].quality).toEqual(8); + }); + it('will decrease the quality to 0 after concert.', () => { + item.sellIn = 0; + item.quality = 5; + const items = gildedRose.updateQuality(); + expect(items[0].quality).toEqual(0); + }); }); }); });