Merge pull request #2039 from davep/new-disabled-snapshot-test

Simplify the disabled widgets snapshot test
This commit is contained in:
Dave Pearson 2023-03-14 08:48:40 +00:00 committed by GitHub
commit cfb8219e44
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 102 additions and 157 deletions

File diff suppressed because one or more lines are too long

View file

@ -1,83 +1,32 @@
from textual.app import App, ComposeResult from textual.app import App, ComposeResult
from textual.containers import Vertical, Horizontal from textual.containers import Horizontal
from textual.widgets import ( from textual.widgets import Button
Header,
Footer,
Button,
DataTable,
Input,
ListView,
ListItem,
Label,
Markdown,
MarkdownViewer,
Tree,
TextLog,
)
class WidgetDisableTestApp(App[None]): class WidgetDisableTestApp(App[None]):
CSS = """ CSS = """
Horizontal { Horizontal {
height: auto; height: auto;
} }
DataTable, ListView, Tree, TextLog {
height: 2;
}
Markdown, MarkdownViewer { Button {
height: 1fr; width: 1fr;
} }
""" """
@property
def data_table(self) -> DataTable:
data_table = DataTable[str]()
data_table.add_columns("Column 1", "Column 2", "Column 3", "Column 4")
data_table.add_rows(
[(str(n), str(n * 10), str(n * 100), str(n * 1000)) for n in range(100)]
)
return data_table
@property
def list_view(self) -> ListView:
return ListView(*[ListItem(Label(f"This is list item {n}")) for n in range(20)])
@property
def test_tree(self) -> Tree:
tree = Tree[None](label="This is a test tree")
for n in range(10):
tree.root.add_leaf(f"Leaf {n}")
tree.root.expand()
return tree
def compose(self) -> ComposeResult: def compose(self) -> ComposeResult:
yield Header() for _ in range(4):
yield Vertical( with Horizontal():
Horizontal( yield Button()
Button(), yield Button(variant="primary")
Button(variant="primary"), yield Button(variant="success")
Button(variant="success"), yield Button(variant="warning")
Button(variant="warning"), yield Button(variant="error")
Button(variant="error"), with Horizontal(disabled=True):
), yield Button()
self.data_table, yield Button(variant="primary")
self.list_view, yield Button(variant="success")
self.test_tree, yield Button(variant="warning")
TextLog(), yield Button(variant="error")
Input(),
Input(placeholder="This is an empty input with a placeholder"),
Input("This is some text in an input"),
Markdown("# Hello, World!"),
MarkdownViewer("# Hello, World!"),
id="test-container",
)
yield Footer()
def on_mount(self) -> None:
self.query_one(TextLog).write("Hello, World!")
self.query_one("#test-container", Vertical).disabled = True
if __name__ == "__main__": if __name__ == "__main__":
WidgetDisableTestApp().run() WidgetDisableTestApp().run()