Skip to content

Commit

Permalink
test: Add copy to clipboard hover visibility e2e tests (#2128)
Browse files Browse the repository at this point in the history
  • Loading branch information
marek-mihok authored Sep 7, 2023
1 parent fd85b07 commit 741e8a0
Show file tree
Hide file tree
Showing 3 changed files with 68 additions and 3 deletions.
65 changes: 65 additions & 0 deletions e2e/test_copy_button.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
import os
import signal
from utils import start_waved, AppRunner
import pytest

from playwright.sync_api import Page, expect


@pytest.fixture(scope='module', autouse=True)
def setup_teardown():
waved_p = None
expect.set_options(timeout=10_000)
try:
waved_p = start_waved()
yield
finally:
if waved_p:
os.killpg(os.getpgid(waved_p.pid), signal.SIGTERM)

def test_show_on_hover_copyable_text(page: Page):
code = f'''
from h2o_wave import main, app, Q, ui
@app('/')
async def serve(q: Q):
q.page['example'] = ui.form_card(box='1 1 3 5', items=[
ui.copyable_text(label='Multiline Copyable text', value='Sample text.', multiline=True),
])
await q.page.save()
'''
with AppRunner(code):
page.goto('http://localhost:10101')
textfield = page.locator('text=Sample text.')
button = page.locator('button')
expect(button).to_be_hidden()
textfield.hover()
expect(button).to_be_visible()



def test_show_on_hover_markdown_code_block(page: Page):
code = f'''
from h2o_wave import main, app, Q, ui
@app('/')
async def serve(q: Q):
q.page['example'] = ui.markdown_card(
box='1 1 3 5',
title='I was made using markdown!',
content=\'\'\'
```py
print('Hello World!')
\'\'\'
)
await q.page.save()
'''
with AppRunner(code):
page.goto('http://localhost:10101')
codeblock = page.get_by_role('code').first
button = page.locator('button')
expect(button).to_be_hidden()
codeblock.hover()
expect(button).to_be_visible()
2 changes: 1 addition & 1 deletion ui/src/copyable_text.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ export const XCopyableText = ({ model }: { model: CopyableText }) => {
root: {
...heightStyle,
textFieldRoot: { position: 'relative', width: pc(100) },
textFieldMultiline: multiline ? { '& button': { opacity: 0 }, '&:hover button': { opacity: 1 } } : undefined
textFieldMultiline: multiline ? { '& button': { visibility: 'hidden' }, '&:hover button': { visibility: 'visible' } } : undefined
},
wrapper: heightStyle,
fieldGroup: heightStyle || { minHeight: height },
Expand Down
4 changes: 2 additions & 2 deletions ui/src/markdown.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ const
position: 'relative',
$nest: {
'&:hover button': {
opacity: 1,
visibility: 'visible',
},
}
},
Expand All @@ -83,7 +83,7 @@ const
top: 4,
$nest: {
button: {
opacity: 0,
visibility: 'hidden',
},
}
},
Expand Down

0 comments on commit 741e8a0

Please sign in to comment.