UnitMentionSuggestionTest.swift 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. //
  2. // SPDX-FileCopyrightText: 2024 Nextcloud GmbH and Nextcloud contributors
  3. // SPDX-License-Identifier: GPL-3.0-or-later
  4. //
  5. import XCTest
  6. @testable import NextcloudTalk
  7. final class UnitMentionSuggestionTest: XCTestCase {
  8. func testLocalMention() throws {
  9. let data = [
  10. "id": "my-id",
  11. "label": "My Label",
  12. "source": "users"
  13. ]
  14. let suggestion = MentionSuggestion(dictionary: data)
  15. XCTAssertEqual(suggestion.id, "my-id")
  16. XCTAssertEqual(suggestion.label, "My Label")
  17. XCTAssertEqual(suggestion.source, "users")
  18. XCTAssertEqual(suggestion.getIdForChat(), "my-id")
  19. XCTAssertEqual(suggestion.getIdForAvatar(), "my-id")
  20. }
  21. func testLocalGuestMention() throws {
  22. let data = [
  23. "id": "guest/guest-id"
  24. ]
  25. let suggestion = MentionSuggestion(dictionary: data)
  26. XCTAssertEqual(suggestion.id, "guest/guest-id")
  27. XCTAssertEqual(suggestion.getIdForChat(), "\"guest/guest-id\"")
  28. XCTAssertEqual(suggestion.getIdForAvatar(), "guest/guest-id")
  29. }
  30. func testLocalWhitespaceMention() throws {
  31. let data = [
  32. "id": "my id"
  33. ]
  34. let suggestion = MentionSuggestion(dictionary: data)
  35. XCTAssertEqual(suggestion.id, "my id")
  36. XCTAssertEqual(suggestion.getIdForChat(), "\"my id\"")
  37. XCTAssertEqual(suggestion.getIdForAvatar(), "my id")
  38. }
  39. func testMentionId() throws {
  40. let data = [
  41. "id": "my-id",
  42. "mentionId": "mention-id"
  43. ]
  44. let suggestion = MentionSuggestion(dictionary: data)
  45. XCTAssertEqual(suggestion.id, "my-id")
  46. XCTAssertEqual(suggestion.mentionId, "mention-id")
  47. XCTAssertEqual(suggestion.getIdForChat(), "mention-id")
  48. XCTAssertEqual(suggestion.getIdForAvatar(), "my-id")
  49. }
  50. func testMessageParameter() throws {
  51. let data = [
  52. "id": "my-id",
  53. "mentionId": "mention-id",
  54. "label": "My Label",
  55. "source": "users"
  56. ]
  57. let suggestion = MentionSuggestion(dictionary: data)
  58. let parameter = suggestion.asMessageParameter()
  59. XCTAssertEqual(parameter.parameterId, "my-id")
  60. XCTAssertEqual(parameter.name, "My Label")
  61. XCTAssertEqual(parameter.mentionDisplayName, "@My Label")
  62. XCTAssertEqual(parameter.mentionId, "@mention-id")
  63. XCTAssertEqual(parameter.type, "user")
  64. }
  65. }