Skip to content

Commit

Permalink
Use TestEZ instead of Nexus Unit Testing.
Browse files Browse the repository at this point in the history
  • Loading branch information
TheNexusAvenger committed Jan 4, 2023
1 parent fa79295 commit f7b41a9
Show file tree
Hide file tree
Showing 8 changed files with 187 additions and 248 deletions.
2 changes: 2 additions & 0 deletions src/Factory/TextButtonFactory.lua
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ local BORDER_COLOR_OFFSET = Color3.new(-30 / 255, -30 / 255, -30 / 255)

local RootModule = script.Parent.Parent

local NexusButton = require(RootModule)
local ButtonFactory = require(RootModule:WaitForChild("Factory"):WaitForChild("ButtonFactory"))

local TextButtonFactory = ButtonFactory:Extend()
Expand All @@ -22,6 +23,7 @@ export type TextButtonFactory = {
Extend: (self: TextButtonFactory) -> TextButtonFactory,
CreateDefault: (Color: Color3) -> TextButtonFactory,

Create: (self: TextButtonFactory) -> (NexusButton.NexusButton, TextLabel),
SetTextDefault: (self: TextButtonFactory, PropertyName: string, Property: any) -> (),
UnsetTextDefault: (self: TextButtonFactory, PropertyName: string) -> (),
} & ButtonFactory.ButtonFactory
Expand Down
1 change: 1 addition & 0 deletions src/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ export type NexusButton = {
new: () -> NexusButton,
Extend: (self: NexusButton) -> NexusButton,

BorderSizeScale: number,
TweenDuration: number,
Theme: string,
OverrideButtonProperty: (self: NexusButton, PropertyName: string, SetFunction: (any) -> ()) -> (),
Expand Down
41 changes: 41 additions & 0 deletions test/ControllerIcon.spec.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
--[[
TheNexusAvenger
Tests the ControllerIcon class.
--]]
--!strict

local ControllerIcon = require(game:GetService("ReplicatedStorage"):WaitForChild("NexusButton"):WaitForChild("ControllerIcon"))

return function()
local TestControllerIcon = nil
beforeEach(function()
TestControllerIcon = ControllerIcon.new()
end)
afterEach(function()
TestControllerIcon:Destroy()
end)

describe("A controller icon", function()
it("should set an icon.", function()
expect(TestControllerIcon.Icon).to.equal(nil)

TestControllerIcon:SetIcon(Enum.KeyCode.ButtonA)
expect(TestControllerIcon.Icon.Size).to.equal(UDim2.new(0.9, 0, 0.9, 0))
TestControllerIcon:SetIcon(Enum.KeyCode.ButtonL1)
expect(TestControllerIcon.Icon.Size).to.equal(UDim2.new(0.9, 0, 0.45, 0))

TestControllerIcon:SetIcon(nil)
expect(TestControllerIcon.Icon).to.equal(nil)
end)

it("should set a scale.", function()
TestControllerIcon:SetIcon(Enum.KeyCode.ButtonA)

TestControllerIcon:SetScale(0.6)
expect(TestControllerIcon.Icon.Size).to.equal(UDim2.new(0.6, 0, 0.6, 0))
TestControllerIcon:SetIcon(Enum.KeyCode.ButtonL1)
expect(TestControllerIcon.Icon.Size).to.equal(UDim2.new(0.6, 0, 0.3, 0))
end)
end)
end
40 changes: 40 additions & 0 deletions test/Factory/ButtonFactory.spec.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
--[[
TheNexusAvenger
Tests the ButtonFactory class.
--]]
--!strict

_G.EnsureNexusWrappedInstanceSingleton = false
local ButtonFactory = require(game:GetService("ReplicatedStorage"):WaitForChild("NexusButton"):WaitForChild("Factory"):WaitForChild("ButtonFactory"))

return function()
describe("A button factory", function()
it("should set default properties.", function()
local TestButtonFactory = ButtonFactory.new()
TestButtonFactory:SetDefault("Name", "TestButton")
TestButtonFactory:SetDefault("Size", UDim2.new(1, 2, 3, 4))

local Button1 = TestButtonFactory:Create()
expect(Button1.Name).to.equal("TestButton")
expect(Button1.Size).to.equal(UDim2.new(1, 2, 3, 4))
Button1:Destroy()

TestButtonFactory:UnsetDefault("Name")
local Button2 = TestButtonFactory:Create()
expect(Button2.Name).never.to.equal("TestButton")
expect(Button2.Size).to.equal(UDim2.new(1, 2, 3, 4))
Button2:Destroy()
end)

it("should be created from a default preset.", function()
local TestButtonFactory = ButtonFactory.CreateDefault(Color3.new(0, 170 / 255, 1))

local Button = TestButtonFactory:Create()
expect(Button.BackgroundColor3).to.equal(Color3.new(0, 170 / 255, 1))
expect(Button.BorderColor3).to.equal(Color3.new(0, 140 / 255, 225 / 255))
expect(Button.BorderTransparency).to.equal(0.25)
Button:Destroy()
end)
end)
end
77 changes: 0 additions & 77 deletions test/Factory/ButtonFactoryTests.nexusspec.lua

This file was deleted.

45 changes: 45 additions & 0 deletions test/Factory/TextButtonFactory.spec.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
--[[
TheNexusAvenger
Tests the TextButtonFactory class.
--]]
--!strict

_G.EnsureNexusWrappedInstanceSingleton = false
local TextButtonFactory = require(game:GetService("ReplicatedStorage"):WaitForChild("NexusButton"):WaitForChild("Factory"):WaitForChild("TextButtonFactory"))

return function()
describe("A text button factory", function()
it("should set default properties.", function()
local TestButtonFactory = TextButtonFactory.new()
TestButtonFactory:SetTextDefault("Text", "TestLabel")
TestButtonFactory:SetTextDefault("Font", Enum.Font.Arcade)

local Button1, TextLabel1 = TestButtonFactory:Create()
expect(TextLabel1.Text).to.equal("TestLabel")
expect(TextLabel1.Font).to.equal(Enum.Font.Arcade)
Button1:Destroy()

TestButtonFactory:UnsetTextDefault("Text")
local Button2, TextLabel2 = TestButtonFactory:Create()
expect(TextLabel2.Text).never.to.equal("TestLabel")
expect(TextLabel2.Font).to.equal(Enum.Font.Arcade)
Button2:Destroy()
end)

it("should be created from a default preset.", function()
local TestButtonFactory = TextButtonFactory.CreateDefault(Color3.new(0, 170 / 255, 1))

local Button, TextLabel = TestButtonFactory:Create()
expect(Button.BackgroundColor3).to.equal(Color3.new(0, 170 / 255, 1))
expect(Button.BorderColor3).to.equal(Color3.new(0, 140 / 255, 225 / 255))
expect(Button.BorderTransparency).to.equal(0.25)
expect(TextLabel.Font).to.equal(Enum.Font.SourceSans)
expect(TextLabel.TextColor3).to.equal(Color3.new(1, 1, 1))
expect(TextLabel.TextStrokeColor3).to.equal(Color3.new(0,0,0))
expect(TextLabel.TextStrokeTransparency).to.equal(0)
expect(TextLabel.TextScaled).to.equal(true)
Button:Destroy()
end)
end)
end
82 changes: 0 additions & 82 deletions test/Factory/TextButtonFactoryTests.nexusspec.lua

This file was deleted.

Loading

0 comments on commit f7b41a9

Please sign in to comment.