Document handling
New/Open/Save/Save as and Undo/Redo
This commit is contained in:
37
tests/unit/test_gui_document.py
Normal file
37
tests/unit/test_gui_document.py
Normal file
@@ -0,0 +1,37 @@
|
||||
from __future__ import annotations
|
||||
|
||||
from pathlib import Path
|
||||
|
||||
import pytest
|
||||
from PySide6.QtGui import QUndoCommand
|
||||
|
||||
from bedit_gui.documents import Document
|
||||
|
||||
|
||||
@pytest.mark.unit
|
||||
@pytest.mark.parametrize("suffix", [".beb", ".json"])
|
||||
def test_document_save_and_open(tmp_path: Path, suffix: str) -> None:
|
||||
path = tmp_path / f"document{suffix}"
|
||||
document = Document()
|
||||
original_id = document.model.id
|
||||
|
||||
document.save_as(path)
|
||||
document.new()
|
||||
assert document.model.id != original_id
|
||||
|
||||
document.open(path)
|
||||
|
||||
assert document.model.id == original_id
|
||||
assert document.path == path
|
||||
assert not document.modified
|
||||
|
||||
|
||||
@pytest.mark.unit
|
||||
def test_document_modified_state_uses_undo_stack() -> None:
|
||||
document = Document()
|
||||
|
||||
document.undo_stack.push(QUndoCommand("change"))
|
||||
assert document.modified
|
||||
|
||||
document.undo_stack.setClean()
|
||||
assert not document.modified
|
||||
Reference in New Issue
Block a user