-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adding tests for object set/sound utils.
- Loading branch information
Showing
7 changed files
with
88 additions
and
24 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
import { describe, expect, it } from "@jest/globals"; | ||
|
||
import { registerObject } from "@/engine/core/database"; | ||
import { setItemCondition, setObjectTeamSquadGroup } from "@/engine/core/utils/object/object_set"; | ||
import { ClientObject, ServerHumanObject } from "@/engine/lib/types"; | ||
import { mockClientGameObject, mockServerAlifeHumanStalker } from "@/fixtures/xray"; | ||
|
||
describe("object_set utils", () => { | ||
it("'setItemCondition' should correctly set condition", () => { | ||
const object: ClientObject = mockClientGameObject(); | ||
|
||
setItemCondition(object, 25); | ||
expect(object.set_condition).toHaveBeenCalledWith(0.25); | ||
|
||
setItemCondition(object, 100); | ||
expect(object.set_condition).toHaveBeenNthCalledWith(2, 1); | ||
|
||
setItemCondition(object, 0); | ||
expect(object.set_condition).toHaveBeenNthCalledWith(3, 0); | ||
}); | ||
|
||
it("'setObjectTeamSquadGroup' should correctly set object group details", () => { | ||
const firstObject: ClientObject = mockClientGameObject(); | ||
const firstServerObject: ServerHumanObject = mockServerAlifeHumanStalker({ id: firstObject.id() }); | ||
|
||
setObjectTeamSquadGroup(firstServerObject, 432, 543, 654); | ||
|
||
expect(firstServerObject.team).toBe(432); | ||
expect(firstServerObject.squad).toBe(543); | ||
expect(firstServerObject.group).toBe(654); | ||
|
||
expect(firstObject.change_team).not.toHaveBeenCalled(); | ||
|
||
const secondObject: ClientObject = mockClientGameObject(); | ||
const secondServerObject: ServerHumanObject = mockServerAlifeHumanStalker({ id: secondObject.id() }); | ||
|
||
registerObject(secondObject); | ||
setObjectTeamSquadGroup(secondServerObject, 443, 444, 445); | ||
|
||
expect(secondServerObject.team).not.toBe(443); | ||
expect(secondServerObject.squad).not.toBe(444); | ||
expect(secondServerObject.group).not.toBe(445); | ||
|
||
expect(secondObject.change_team).toHaveBeenCalledWith(443, 444, 445); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
import { describe, expect, it } from "@jest/globals"; | ||
|
||
import { stopPlayingObjectSound } from "@/engine/core/utils/object/object_sound"; | ||
import { ClientObject } from "@/engine/lib/types"; | ||
import { replaceFunctionMock } from "@/fixtures/utils"; | ||
import { mockClientGameObject } from "@/fixtures/xray"; | ||
|
||
describe("object_sound utils", () => { | ||
it("'stopPlayingObjectSound' should correctly reset object sound play", () => { | ||
const object: ClientObject = mockClientGameObject(); | ||
|
||
replaceFunctionMock(object.alive, () => false); | ||
stopPlayingObjectSound(object); | ||
expect(object.set_sound_mask).not.toHaveBeenCalled(); | ||
|
||
replaceFunctionMock(object.alive, () => true); | ||
stopPlayingObjectSound(object); | ||
expect(object.set_sound_mask).toHaveBeenCalledTimes(2); | ||
expect(object.set_sound_mask).toHaveBeenNthCalledWith(1, -1); | ||
expect(object.set_sound_mask).toHaveBeenNthCalledWith(2, 0); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters