Skip to content

Instantly share code, notes, and snippets.

@MartijnHols
Created October 3, 2017 19:41
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save MartijnHols/69e5dae5cd08a4f6a28e8a552cefab41 to your computer and use it in GitHub Desktop.
Save MartijnHols/69e5dae5cd08a4f6a28e8a552cefab41 to your computer and use it in GitHub Desktop.
oldCooldownUsable.test.js
import SPELLS from 'common/SPELLS';
import CooldownUsable from './CooldownUsable';
describe('Core/Modules/CooldownUsable', () => {
let instance;
let combatantsMock;
let castEfficiencyMock;
let hasteMock;
beforeEach(() => {
// Reset mocks:
combatantsMock = {
selected: {
},
};
castEfficiencyMock = {
constructor: {
CPM_ABILITIES: [],
},
};
hasteMock = {
current: 0,
};
instance = new CooldownUsable({
toPlayer: () => true,
byPlayer: () => true,
toPlayerPet: () => false,
byPlayerPet: () => false,
}, {
combatants: combatantsMock,
castEfficiency: castEfficiencyMock,
haste: hasteMock,
});
});
it('calculates the cooldown duration using the cooldown calculation set in Cast Efficiency to calculate the cooldown', () => {
const getCooldown = jest.fn();
castEfficiencyMock.constructor.CPM_ABILITIES = [
{
spell: SPELLS.HOLY_SHOCK_CAST,
getCooldown,
},
];
instance.getExpectedCooldownDuration(SPELLS.HOLY_SHOCK_CAST.id);
expect(getCooldown).toHaveBeenCalledWith(hasteMock.current, combatantsMock.selected);
});
it('calculates the cooldown duration using the current Haste value to calculate the cooldown', () => {
const getCooldown = jest.fn();
castEfficiencyMock.constructor.CPM_ABILITIES = [
{
spell: SPELLS.HOLY_SHOCK_CAST,
getCooldown,
},
];
hasteMock.current = 0;
instance.getExpectedCooldownDuration(SPELLS.HOLY_SHOCK_CAST.id);
expect(getCooldown.mock.calls[getCooldown.mock.calls.length - 1][0]).toBe(0);
hasteMock.current = 0.12;
instance.getExpectedCooldownDuration(SPELLS.HOLY_SHOCK_CAST.id);
expect(getCooldown.mock.calls[getCooldown.mock.calls.length - 1][0]).toBe(0.12);
hasteMock.current = 0.5;
instance.getExpectedCooldownDuration(SPELLS.HOLY_SHOCK_CAST.id);
expect(getCooldown.mock.calls[getCooldown.mock.calls.length - 1][0]).toBe(0.5);
});
it('returns the cooldown duration provided by Cast Efficiency in milliseconds', () => {
castEfficiencyMock.constructor.CPM_ABILITIES = [
{
spell: SPELLS.HOLY_SHOCK_CAST,
getCooldown: () => 8.4,
},
];
expect(instance.getExpectedCooldownDuration(SPELLS.HOLY_SHOCK_CAST.id)).toBe(8400);
});
it('ignores inactive spells', () => {
const getCooldown = jest.fn();
castEfficiencyMock.constructor.CPM_ABILITIES = [
{
spell: SPELLS.HOLY_SHOCK_CAST,
getCooldown: () => 8.4,
isActive: () => false,
},
{
spell: SPELLS.HOLY_SHOCK_CAST,
getCooldown,
isActive: () => true,
},
];
instance.getExpectedCooldownDuration(SPELLS.HOLY_SHOCK_CAST.id);
expect(getCooldown).toHaveBeenCalled();
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment