Skip to content

Commit

Permalink
Merge pull request #7 from javierav/feature/tests
Browse files Browse the repository at this point in the history
  • Loading branch information
adrianthedev authored Dec 7, 2023
2 parents 69b9305 + 53a4cfe commit 1b4e700
Show file tree
Hide file tree
Showing 4 changed files with 75 additions and 0 deletions.
21 changes: 21 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
name: CI
on: push
jobs:
tests:
name: Tests
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
ruby:
- '3.0'
- '3.1'
- '3.2'
steps:
- uses: actions/checkout@v3
- name: Setup Ruby ${{ matrix.ruby }}
uses: ruby/setup-ruby@v1
with:
ruby-version: ${{ matrix.ruby }}
- name: Run tests
run: rake test
9 changes: 9 additions & 0 deletions Rakefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
require "rake/testtask"

Rake::TestTask.new(:test) do |t|
t.libs << "test"
t.libs << "lib"
t.test_files = FileList["test/**/*_test.rb"]
end

task default: :test
41 changes: 41 additions & 0 deletions test/class_variants_test.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
require "test_helper"

class ClassVariantsTest < Minitest::Test
def setup
@cv = ClassVariants.build(
"rounded border",
variants: {
size: {
sm: "text-sm",
md: "text-md"
},
color: {
red: "text-red",
green: "text-green"
},
visible: "inline-block",
"!visible": "hidden"
},
defaults: {
size: :md
}
)
end

def test_base_with_defaults
assert_equal "rounded border text-md", @cv.render
end

def test_base_with_defaults_overwrite
assert_equal "rounded border text-sm", @cv.render(size: :sm)
end

def test_base_with_defaults_overwrite_and_add
assert_equal "rounded border text-sm text-green", @cv.render(size: :sm, color: :green)
end

def test_boolean_variants
assert_equal "rounded border text-md inline-block", @cv.render(visible: true)
assert_equal "rounded border text-md hidden", @cv.render(visible: false)
end
end
4 changes: 4 additions & 0 deletions test/test_helper.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
$LOAD_PATH.unshift File.expand_path("../lib", __dir__)
require "class_variants"

require "minitest/autorun"

0 comments on commit 1b4e700

Please sign in to comment.