Class: Dommy::Clipboard
Overview
‘navigator.clipboard` — an in-memory clipboard for tests. Real OS clipboard access is intentionally not implemented; reads and writes round-trip through Ruby memory only.
Async APIs (‘readText`/`writeText`/`read`/`write`) return PromiseValue so callers’ ‘.await` chains keep working.
Instance Method Summary
collapse
#__deliver_event__, #add_event_listener, #dispatch_event, #invoke_listener, #remove_event_listener
Constructor Details
#initialize(window) ⇒ Clipboard
Returns a new instance of Clipboard.
136
137
138
139
140
|
# File 'lib/dommy/navigator.rb', line 136
def initialize(window)
@window = window
@text = ""
@items = []
end
|
Instance Method Details
#__event_parent__ ⇒ Object
196
197
198
|
# File 'lib/dommy/navigator.rb', line 196
def __event_parent__
nil
end
|
#__js_call__(method, args) ⇒ Object
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
|
# File 'lib/dommy/navigator.rb', line 177
def __js_call__(method, args)
case method
when "readText"
read_text
when "writeText"
write_text(args[0])
when "read"
read
when "write"
write(args[0])
when "addEventListener"
add_event_listener(args[0], args[1], args[2])
when "removeEventListener"
remove_event_listener(args[0], args[1])
when "dispatchEvent"
dispatch_event(args[0])
end
end
|
#__js_get__(_key) ⇒ Object
169
170
171
|
# File 'lib/dommy/navigator.rb', line 169
def __js_get__(_key)
nil
end
|
#__js_set__(_key, _value) ⇒ Object
173
174
175
|
# File 'lib/dommy/navigator.rb', line 173
def __js_set__(_key, _value)
nil
end
|
#read ⇒ Object
160
161
162
|
# File 'lib/dommy/navigator.rb', line 160
def read
PromiseValue.resolve(@window, @items.dup)
end
|
#read_text ⇒ Object
151
152
153
|
# File 'lib/dommy/navigator.rb', line 151
def read_text
PromiseValue.resolve(@window, @text)
end
|
#text ⇒ Object
Sync read for tests that don’t want to await.
143
144
145
|
# File 'lib/dommy/navigator.rb', line 143
def text
@text
end
|
#text=(value) ⇒ Object
147
148
149
|
# File 'lib/dommy/navigator.rb', line 147
def text=(value)
@text = value.to_s
end
|
#write(items) ⇒ Object
164
165
166
167
|
# File 'lib/dommy/navigator.rb', line 164
def write(items)
@items = items.is_a?(Array) ? items : [items]
PromiseValue.resolve(@window, nil)
end
|
#write_text(text) ⇒ Object
155
156
157
158
|
# File 'lib/dommy/navigator.rb', line 155
def write_text(text)
@text = text.to_s
PromiseValue.resolve(@window, nil)
end
|