forked from PhlexyUI/phlexy_ui
-
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdivider_spec.rb
More file actions
150 lines (125 loc) · 3.97 KB
/
divider_spec.rb
File metadata and controls
150 lines (125 loc) · 3.97 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
require "spec_helper"
describe PhlexyUI::Divider do
subject(:output) { render described_class.new }
it "is expected to match the formatted HTML" do
expected_html = html <<~HTML
<div class="divider"></div>
HTML
is_expected.to eq(expected_html)
end
describe "conditions" do
{
vertical: "divider-vertical",
horizontal: "divider-horizontal",
start: "divider-start",
end: "divider-end",
neutral: "divider-neutral",
primary: "divider-primary",
secondary: "divider-secondary",
accent: "divider-accent",
success: "divider-success",
warning: "divider-warning",
info: "divider-info",
error: "divider-error"
}.each do |modifier, css|
context "when given :#{modifier} modifier" do
subject(:output) { render described_class.new(modifier) }
it "renders it apart from the main class" do
expected_html = html <<~HTML
<div class="divider #{css}"></div>
HTML
expect(output).to eq(expected_html)
end
end
end
context "when given multiple conditions" do
subject(:output) { render described_class.new(:vertical, :primary) }
it "renders them separately" do
expected_html = html <<~HTML
<div class="divider divider-vertical divider-primary"></div>
HTML
expect(output).to eq(expected_html)
end
end
end
describe "data" do
subject(:output) do
render described_class.new(data: {foo: "bar"})
end
it "renders it correctly" do
expected_html = html <<~HTML
<div class="divider" data-foo="bar"></div>
HTML
expect(output).to eq(expected_html)
end
end
describe "responsiveness" do
%i[sm md lg xl @sm @md @lg @xl].each do |viewport|
context "when given an :#{viewport} responsive option" do
subject(:output) do
render described_class.new(:vertical, responsive: {viewport => :horizontal})
end
it "renders it separately with a responsive prefix" do
expected_html = html <<~HTML
<div class="divider divider-vertical #{viewport}:divider-horizontal"></div>
HTML
expect(output).to eq(expected_html)
end
end
end
end
describe "passing :as option" do
subject(:output) { render described_class.new(as: :hr) }
it "renders as the given tag" do
expected_html = html <<~HTML
<hr class="divider">
HTML
expect(output).to eq(expected_html)
end
end
describe "rendering via Kit" do
subject(:output) do
Divider :horizontal, data: {foo: "bar"}, class: "my-divider"
end
it "renders it correctly" do
expected_html = html <<~HTML
<div class="divider divider-horizontal my-divider" data-foo="bar"></div>
HTML
expect(output).to eq(expected_html)
end
end
describe "rendering a full divider" do
let(:component) do
Class.new(Phlex::HTML) do
def view_template(&)
div(class: "flex w-full") do
render PhlexyUI::Divider.new(:horizontal, data: {foo: "bar"}, class: "my-divider")
render PhlexyUI::Divider.new(:horizontal, :start) do
"Start"
end
render PhlexyUI::Divider.new(:horizontal) do
"Default"
end
render PhlexyUI::Divider.new(:horizontal, :end) do
"End"
end
end
end
end
end
subject(:output) do
render component.new
end
it "renders it correctly" do
expected_html = html <<~HTML
<div class="flex w-full">
<div class="divider divider-horizontal my-divider" data-foo="bar"></div>
<div class="divider divider-horizontal divider-start">Start</div>
<div class="divider divider-horizontal">Default</div>
<div class="divider divider-horizontal divider-end">End</div>
</div>
HTML
expect(output).to eq(expected_html)
end
end
end