local G=require("\105\110\118\111\107\097\116\105\111\110\046\099\111\109\098\111\115\046\115\111\117\110\100")local z=require("\105\110\118\111\107\097\116\105\111\110\046\100\111\116\097\050\046\115\111\117\110\100\095\101\118\101\110\116\115")describe("\099\111\109\098\111\115\046\115\111\117\110\100",function()local f=CDOTAPlayer({})local u={}local p={entity=u}local q local c local w local g before_each(function()q=stub.new(_G,"\082\097\110\100\111\109\073\110\116",1)c=spy.on(z,"\069\109\105\116\079\110\069\110\116\105\116\121")w=spy.on(z,"\069\109\105\116\079\110\080\108\097\121\101\114")g=spy.on(f,"\083\101\116\077\117\115\105\099\083\116\097\116\117\115")end)after_each(function()q:revert()c:revert()w:revert()g:revert()end)describe("\046\101\109\105\116\082\097\110\100\111\109\069\118\101\110\116\079\110\069\110\116\105\116\121",function()it("\101\109\105\116\115 \114\097\110\100\111\109 \115\111\117\110\100 \101\118\101\110\116 \111\110 \101\110\116\105\116\121",function()local z={"\097","\098";"\099"}G.emitRandomEventOnEntity(u,z);(assert.stub(q)).was.called_with(1,3);(assert.spy(c)).was.called_with("\097",u)end)end)describe("\046\101\109\105\116\082\097\110\100\111\109\069\118\101\110\116\079\110\080\108\097\121\101\114",function()it("\101\109\105\116\115 \114\097\110\100\111\109 \115\111\117\110\100 \101\118\101\110\116 \111\110 \112\108\097\121\101\114",function()local z={"\097","\098","\099"}G.emitRandomEventOnPlayer(f,z);(assert.stub(q)).was.called_with(1,3);(assert.spy(w)).was.called_with("\097",f)end)end)describe("\046\111\110\068\117\109\109\121\067\114\101\097\116\101",function()it("\101\109\105\116\115 \114\097\110\100\111\109 \100\117\109\109\121 \099\114\101\097\116\101 \115\111\117\110\100 \101\118\101\110\116 \111\110 \100\117\109\109\121 \101\110\116\105\116\121",function()G.onDummyCreate(p);(assert.stub(q)).was.called_with(1,#z.SNDEVTS_DUMMY_CREATE);(assert.spy(c)).was.called_with(z.SNDEVTS_DUMMY_CREATE[1],p.entity)end)end)describe("\046\111\110\067\111\109\098\111\083\116\097\114\116",function()it("\115\101\116\115 \116\104\101 \109\117\115\105\099 \115\116\097\116\117\115 \111\110 \116\104\101 \112\108\097\121\101\114",function()G.onComboStart(f);(assert.spy(g)).was_called(1)end)end)describe("\046\111\110\067\111\109\098\111\083\116\111\112",function()it("\115\101\116\115 \116\104\101 \109\117\115\105\099 \115\116\097\116\117\115 \111\110 \116\104\101 \112\108\097\121\101\114",function()G.onComboStop(f);(assert.spy(g)).was_called(1)end)end)describe("\046\111\110\067\111\109\098\111\083\116\101\112\069\114\114\111\114",function()it("\115\101\116\115 \116\104\101 \109\117\115\105\099 \115\116\097\116\117\115 \111\110 \116\104\101 \112\108\097\121\101\114",function()G.onComboStepError(f);(assert.spy(g)).was_called(1)end)end)describe("\046\111\110\067\111\109\098\111\070\105\110\105\115\104\101\100",function()it("\115\101\116\115 \116\104\101 \109\117\115\105\099 \115\116\097\116\117\115 \111\110 \116\104\101 \112\108\097\121\101\114",function()G.onComboFinished(f);(assert.spy(g)).was_called(1)end)end)end)
local CombosSound = require("invokation.combos.sound")
local SoundEvents = require("invokation.dota2.sound_events")

describe("combos.sound", function()
  local player = CDOTAPlayer({})
  local entity = {}
  local dummy = { entity = entity }

  local stubRandomInt
  local spyEmitOnEntity
  local spyEmitOnPlayer
  local spySetMusicStatus

  before_each(function()
    -- selene: allow(global_usage)
    stubRandomInt = stub.new(_G, "RandomInt", 1)
    spyEmitOnEntity = spy.on(SoundEvents, "EmitOnEntity")
    spyEmitOnPlayer = spy.on(SoundEvents, "EmitOnPlayer")
    spySetMusicStatus = spy.on(player, "SetMusicStatus")
  end)

  after_each(function()
    stubRandomInt:revert()
    spyEmitOnEntity:revert()
    spyEmitOnPlayer:revert()
    spySetMusicStatus:revert()
  end)

  describe(".emitRandomEventOnEntity", function()
    it("emits random sound event on entity", function()
      local events = { "a", "b", "c" }

      CombosSound.emitRandomEventOnEntity(entity, events)

      assert.stub(stubRandomInt).was.called_with(1, 3)
      assert.spy(spyEmitOnEntity).was.called_with("a", entity)
    end)
  end)

  describe(".emitRandomEventOnPlayer", function()
    it("emits random sound event on player", function()
      local events = { "a", "b", "c" }

      CombosSound.emitRandomEventOnPlayer(player, events)

      assert.stub(stubRandomInt).was.called_with(1, 3)
      assert.spy(spyEmitOnPlayer).was.called_with("a", player)
    end)
  end)

  describe(".onDummyCreate", function()
    it("emits random dummy create sound event on dummy entity", function()
      CombosSound.onDummyCreate(dummy)

      assert.stub(stubRandomInt).was.called_with(1, #SoundEvents.SNDEVTS_DUMMY_CREATE)
      assert.spy(spyEmitOnEntity).was.called_with(SoundEvents.SNDEVTS_DUMMY_CREATE[1], dummy.entity)
    end)
  end)

  describe(".onComboStart", function()
    it("sets the music status on the player", function()
      CombosSound.onComboStart(player)

      assert.spy(spySetMusicStatus).was_called(1)
    end)
  end)

  describe(".onComboStop", function()
    it("sets the music status on the player", function()
      CombosSound.onComboStop(player)

      assert.spy(spySetMusicStatus).was_called(1)
    end)
  end)

  describe(".onComboStepError", function()
    it("sets the music status on the player", function()
      CombosSound.onComboStepError(player)

      assert.spy(spySetMusicStatus).was_called(1)
    end)
  end)

  describe(".onComboFinished", function()
    it("sets the music status on the player", function()
      CombosSound.onComboFinished(player)

      assert.spy(spySetMusicStatus).was_called(1)
    end)
  end)
end)
