From 4778cd2609433670ccabd76e45234e5497373c4d Mon Sep 17 00:00:00 2001 From: Toni Sevener Date: Fri, 15 Dec 2023 14:58:56 -0600 Subject: [PATCH] Add tests --- ...urceEditorFormatterButtonActionTests.swift | 10 ++++++++ ...urceEditorTextFrameworkMediatorTests.swift | 24 +++++++++++++++++++ 2 files changed, 34 insertions(+) diff --git a/Components/Tests/ComponentsTests/WKSourceEditorFormatterButtonActionTests.swift b/Components/Tests/ComponentsTests/WKSourceEditorFormatterButtonActionTests.swift index ee99fe49cd6..35d8f3b5a64 100644 --- a/Components/Tests/ComponentsTests/WKSourceEditorFormatterButtonActionTests.swift +++ b/Components/Tests/ComponentsTests/WKSourceEditorFormatterButtonActionTests.swift @@ -122,4 +122,14 @@ final class WKSourceEditorFormatterButtonActionTests: XCTestCase { mediator.templateFormatter?.toggleTemplateFormatting(action: .remove, in: mediator.textView) XCTAssertEqual(mediator.textView.attributedText.string, "One Two Three Four") } + + func testStrikethroughInsertAndRemove() throws { + let text = "One Two Three Four" + mediator.textView.attributedText = NSAttributedString(string: text) + mediator.textView.selectedRange = NSRange(location: 4, length:3) + mediator.strikethroughFormatter?.toggleStrikethroughFormatting(action: .add, in: mediator.textView) + XCTAssertEqual(mediator.textView.attributedText.string, "One Two Three Four") + mediator.strikethroughFormatter?.toggleStrikethroughFormatting(action: .remove, in: mediator.textView) + XCTAssertEqual(mediator.textView.attributedText.string, "One Two Three Four") + } } diff --git a/Components/Tests/ComponentsTests/WKSourceEditorTextFrameworkMediatorTests.swift b/Components/Tests/ComponentsTests/WKSourceEditorTextFrameworkMediatorTests.swift index 5f01b4b4c71..183d81456fb 100644 --- a/Components/Tests/ComponentsTests/WKSourceEditorTextFrameworkMediatorTests.swift +++ b/Components/Tests/ComponentsTests/WKSourceEditorTextFrameworkMediatorTests.swift @@ -121,4 +121,28 @@ final class WKSourceEditorTextFrameworkMediatorTests: XCTestCase { let selectionStates1 = mediator.selectionState(selectedDocumentRange: NSRange(location: 1, length: 0)) XCTAssertFalse(selectionStates1.isHorizontalTemplate) } + + func testStrikethroughSelectionState() throws { + let text = "Testing Strikethrough Testing." + mediator.textView.attributedText = NSAttributedString(string: text) + + let selectionStates1 = mediator.selectionState(selectedDocumentRange: NSRange(location: 0, length: 7)) + let selectionStates2 = mediator.selectionState(selectedDocumentRange: NSRange(location: 11, length: 13)) + let selectionStates3 = mediator.selectionState(selectedDocumentRange: NSRange(location: 29, length: 7)) + XCTAssertFalse(selectionStates1.isStrikethrough) + XCTAssertTrue(selectionStates2.isStrikethrough) + XCTAssertFalse(selectionStates3.isStrikethrough) + } + + func testStrikethroughSelectionStateCursor() throws { + let text = "Testing Strikethrough Testing." + mediator.textView.attributedText = NSAttributedString(string: text) + + let selectionStates1 = mediator.selectionState(selectedDocumentRange: NSRange(location: 3, length: 0)) + let selectionStates2 = mediator.selectionState(selectedDocumentRange: NSRange(location: 17, length: 0)) + let selectionStates3 = mediator.selectionState(selectedDocumentRange: NSRange(location: 33, length: 0)) + XCTAssertFalse(selectionStates1.isStrikethrough) + XCTAssertTrue(selectionStates2.isStrikethrough) + XCTAssertFalse(selectionStates3.isStrikethrough) + } }