Skip to content

Commit

Permalink
Added tests for alert
Browse files Browse the repository at this point in the history
  • Loading branch information
kamaroly committed Jun 11, 2024
1 parent d29762f commit 031168b
Show file tree
Hide file tree
Showing 2 changed files with 66 additions and 33 deletions.
4 changes: 4 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"terminal.integrated.accessibleViewFocusOnCommandExecution": true,
"terminal.integrated.accessibleViewPreserveCursorPosition": true
}
95 changes: 62 additions & 33 deletions test/salad_ui/alert_test.exs
Original file line number Diff line number Diff line change
@@ -1,49 +1,78 @@
defmodule SaladUI.AlertTest do
use ComponentCase

import SaladUI.Alert

test "it renders default alert correctly" do
assigns = %{}
describe "Test Alerting" do
test "it renders default alert correctly" do
assigns = %{}

html =
rendered_to_string(~H"""
<.alert>
<.alert_title>Heads up!</.alert_title>
html =
rendered_to_string(
~H"""
<.alert>
<.alert_title>Heads up!</.alert_title>
<.alert_description>Alert Descriptions</.alert_description>
</.alert>
""")
<.alert_description>Alert Descriptions</.alert_description>
</.alert>
"""
)

# Assert the style rendering
assert html =~
"<div class=\"relative p-4 rounded-lg bg-background text-foreground w-full [&amp;&gt;span+div]:translate-y-[-3px] [&amp;&gt;span]:absolute [&amp;&gt;span]:left-4 [&amp;&gt;span]:top-4 [&amp;&gt;span~*]:pl-7 border\">"
assert html =~
"<div class=\"relative p-4 rounded-lg bg-background text-foreground w-full [&amp;&gt;span+div]:translate-y-[-3px] [&amp;&gt;span]:absolute [&amp;&gt;span]:left-4 [&amp;&gt;span]:top-4 [&amp;&gt;span~*]:pl-7 border\">"
assert html =~ "<h5 class=\"mb-1 tracking-tight font-medium leading-none\">"

assert html =~ "<h5 class=\"mb-1 tracking-tight font-medium leading-none\">"
assert html =~ "Heads up!"
assert html =~ "Alert Descriptions"
end

# Confirm that the text is displayed on the screen
assert html =~ "Heads up!"
assert html =~ "Alert Descriptions"
end
test "It renders destructive alert correctly" do
assigns = %{}

html =
rendered_to_string(
~H"""
<.alert variant="destructive">
<.alert_title>Heads up!</.alert_title>
<.alert_description>
You can add components to your app using the cli
</.alert_description>
</.alert>
"""
)

# Confirm the style rendering
assert html =~ "relative p-4 rounded-lg border-destructive/50 text-destructive w-full dark:border-destructive"

assert html =~ "Heads up!"
assert html =~ "You can add components to your app using the cli"
end

test "It renders alert title correctly" do
assigns = %{}

test "It renders Destructive alert correctly" do
assigns = %{}
html = rendered_to_string(
~H"""
<.alert_title>Alert title</.alert_title>
"""
)

html =
rendered_to_string(~H"""
<.alert variant="destructive">
<.alert_title>Heads up!</.alert_title>
assert html =~ "<h5 class=\"mb-1"
assert html =~ "Alert title"
assert html =~ "</h5>"
end

<.alert_description>
You can add components to your app using the cli
</.alert_description>
</.alert>
""")
test "it renders alert description correctly" do
assigns = %{}

# Confirm the style rendering
assert html =~ "relative p-4 rounded-lg border-destructive/50 text-destructive w-full dark:border-destructive"
html = rendered_to_string(
~H"""
<.alert_description>Alert description</.alert_description>
"""
)

assert html =~ "Heads up!"
assert html =~ "You can add components to your app using the cli"
assert html =~ "Alert description"
assert html =~ "<div class=\"text-sm [&amp;_p]:leading-relaxed\">"
end
end
end

0 comments on commit 031168b

Please sign in to comment.