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.
73
74
75
76
77
|
# File 'lib/dommy/navigator.rb', line 73
def initialize(window)
@window = window
@text = ""
@items = []
end
|
Instance Method Details
#__event_parent__ ⇒ Object
133
134
135
|
# File 'lib/dommy/navigator.rb', line 133
def __event_parent__
nil
end
|
#__js_call__(method, args) ⇒ Object
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
|
# File 'lib/dommy/navigator.rb', line 114
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
106
107
108
|
# File 'lib/dommy/navigator.rb', line 106
def __js_get__(_key)
nil
end
|
#__js_set__(_key, _value) ⇒ Object
110
111
112
|
# File 'lib/dommy/navigator.rb', line 110
def __js_set__(_key, _value)
nil
end
|
#read ⇒ Object
97
98
99
|
# File 'lib/dommy/navigator.rb', line 97
def read
PromiseValue.resolve(@window, @items.dup)
end
|
#read_text ⇒ Object
88
89
90
|
# File 'lib/dommy/navigator.rb', line 88
def read_text
PromiseValue.resolve(@window, @text)
end
|
#text ⇒ Object
Sync read for tests that don’t want to await.
80
81
82
|
# File 'lib/dommy/navigator.rb', line 80
def text
@text
end
|
#text=(value) ⇒ Object
84
85
86
|
# File 'lib/dommy/navigator.rb', line 84
def text=(value)
@text = value.to_s
end
|
#write(items) ⇒ Object
101
102
103
104
|
# File 'lib/dommy/navigator.rb', line 101
def write(items)
@items = items.is_a?(Array) ? items : [items]
PromiseValue.resolve(@window, nil)
end
|
#write_text(text) ⇒ Object
92
93
94
95
|
# File 'lib/dommy/navigator.rb', line 92
def write_text(text)
@text = text.to_s
PromiseValue.resolve(@window, nil)
end
|