Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: Add e2e tests for showing clipboard copy button #2025 #2128

Merged
merged 1 commit into from
Sep 7, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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