From 1f5939a0a3b2fef3bad0d7c529c80a0289c80a79 Mon Sep 17 00:00:00 2001 From: Philippe Weidmann Date: Tue, 27 Feb 2024 10:55:04 +0100 Subject: [PATCH] test: Prevent using fixed title --- .../UTItemProviderFileRepresentation.swift | 24 +++++++------------ 1 file changed, 8 insertions(+), 16 deletions(-) diff --git a/Tests/InfomaniakCoreTests/UTItemProviderFileRepresentation/UTItemProviderFileRepresentation.swift b/Tests/InfomaniakCoreTests/UTItemProviderFileRepresentation/UTItemProviderFileRepresentation.swift index 8e41c26..2402ca5 100644 --- a/Tests/InfomaniakCoreTests/UTItemProviderFileRepresentation/UTItemProviderFileRepresentation.swift +++ b/Tests/InfomaniakCoreTests/UTItemProviderFileRepresentation/UTItemProviderFileRepresentation.swift @@ -51,7 +51,6 @@ final class UTItemProviderFileRepresentation: XCTestCase { func testFile() async { // GIVEN - let expectedTitle = "text" let someText: NSString = "Some Text" // for NSCoding let item = NSItemProvider(item: someText, typeIdentifier: "\(UTI.text.rawValue)") @@ -79,7 +78,7 @@ final class UTItemProviderFileRepresentation: XCTestCase { // THEN XCTAssertTrue(progress.isFinished, "Expecting the progress to reflect that the task is finished") - XCTAssertEqual(success.title, expectedTitle) + XCTAssertNotEqual(NSString(string: success.title).pathExtension , UTI.text.preferredFilenameExtension) XCTAssertEqual(success.url.pathExtension.lowercased(), "txt") let stringResult = try String(contentsOf: success.url, encoding: .utf8) as NSString // for NSCoding @@ -96,7 +95,6 @@ final class UTItemProviderFileRepresentation: XCTestCase { func testJPGImageNoChange() async { // GIVEN - let expectedTitle = "JPEG image" guard let imgUrlJpg = Bundle.module.url(forResource: Self.imageFile, withExtension: "jpg") else { XCTFail("unexpected") return @@ -117,7 +115,7 @@ final class UTItemProviderFileRepresentation: XCTestCase { // THEN XCTAssertTrue(progress.isFinished, "Expecting the progress to reflect that the task is finished") - XCTAssertEqual(success.title, expectedTitle) + XCTAssertNotEqual(NSString(string: success.title).pathExtension , "jpeg") XCTAssertEqual(success.url.pathExtension.lowercased(), "jpeg") let imageData = try Data(contentsOf: success.url) @@ -129,7 +127,6 @@ final class UTItemProviderFileRepresentation: XCTestCase { func testHEICImageNoChange() async { // GIVEN - let expectedTitle = "HEIF Image" guard let imgUrlHeic = Bundle.module.url(forResource: Self.imageFile, withExtension: "heic") else { XCTFail("unexpected") return @@ -150,7 +147,7 @@ final class UTItemProviderFileRepresentation: XCTestCase { // THEN XCTAssertTrue(progress.isFinished, "Expecting the progress to reflect that the task is finished") - XCTAssertEqual(success.title, expectedTitle) + XCTAssertNotEqual(NSString(string: success.title).pathExtension , "heic") XCTAssertEqual(success.url.pathExtension.lowercased(), "heic") let imageData = try Data(contentsOf: success.url) @@ -164,7 +161,6 @@ final class UTItemProviderFileRepresentation: XCTestCase { func testHEICtoJPEG_success() async { // GIVEN - let expectedTitle = "JPEG image" guard let imgUrlHeic = Bundle.module.url(forResource: Self.imageFile, withExtension: "heic"), let imgUrlJpg = Bundle.module.url(forResource: Self.imageFile, withExtension: "jpg") else { XCTFail("unexpected") @@ -189,7 +185,7 @@ final class UTItemProviderFileRepresentation: XCTestCase { // THEN XCTAssertTrue(progress.isFinished, "Expecting the progress to reflect that the task is finished") - XCTAssertEqual(success.title, expectedTitle) + XCTAssertNotEqual(NSString(string: success.title).pathExtension , "jpeg") XCTAssertEqual(success.url.pathExtension.lowercased(), "jpeg") } catch { XCTFail("Unexpected \(error)") @@ -198,7 +194,6 @@ final class UTItemProviderFileRepresentation: XCTestCase { func testJPEGtoHEIC_success() async { // GIVEN - let expectedTitle = "JPEG image" guard let imgUrlHeic = Bundle.module.url(forResource: Self.imageFile, withExtension: "heic"), let imgUrlJpg = Bundle.module.url(forResource: Self.imageFile, withExtension: "jpg") else { XCTFail("unexpected") @@ -223,7 +218,7 @@ final class UTItemProviderFileRepresentation: XCTestCase { // THEN XCTAssertTrue(progress.isFinished, "Expecting the progress to reflect that the task is finished") - XCTAssertEqual(success.title, expectedTitle) + XCTAssertNotEqual(NSString(string: success.title).pathExtension , "jpeg") XCTAssertEqual(success.url.pathExtension.lowercased(), "jpeg") } catch { XCTFail("Unexpected \(error)") @@ -234,7 +229,6 @@ final class UTItemProviderFileRepresentation: XCTestCase { func testHEICtoJPG_fallbackToHEIC() async { // GIVEN - let expectedTitle = "HEIF Image" guard let imgUrlHeic = Bundle.module.url(forResource: Self.imageFile, withExtension: "heic") else { XCTFail("unexpected") return @@ -258,7 +252,7 @@ final class UTItemProviderFileRepresentation: XCTestCase { // THEN XCTAssertTrue(progress.isFinished, "Expecting the progress to reflect that the task is finished") - XCTAssertEqual(success.title, expectedTitle) + XCTAssertNotEqual(NSString(string: success.title).pathExtension , "heic") // We expect a HEIC fallback when no JPG is available XCTAssertEqual(success.url.pathExtension.lowercased(), "heic") @@ -269,7 +263,6 @@ final class UTItemProviderFileRepresentation: XCTestCase { func testJPGtoHEIC_fallbackToJPEG() async { // GIVEN - let expectedTitle = "JPEG image" guard let imgUrlJpg = Bundle.module.url(forResource: Self.imageFile, withExtension: "jpg") else { XCTFail("unexpected") return @@ -293,7 +286,7 @@ final class UTItemProviderFileRepresentation: XCTestCase { // THEN XCTAssertTrue(progress.isFinished, "Expecting the progress to reflect that the task is finished") - XCTAssertEqual(success.title, expectedTitle) + XCTAssertNotEqual(NSString(string: success.title).pathExtension , "jpeg") // We expect a JPEG fallback when no HEIC is available XCTAssertEqual(success.url.pathExtension.lowercased(), "jpeg") @@ -306,7 +299,6 @@ final class UTItemProviderFileRepresentation: XCTestCase { func testJPGfromText_fallback() async { // GIVEN - let expectedTitle = "text" let someText: NSString = "Some Text" // for NSCoding let item = NSItemProvider(item: someText, typeIdentifier: "\(UTI.text.rawValue)") @@ -334,7 +326,7 @@ final class UTItemProviderFileRepresentation: XCTestCase { // THEN we still get an unchanged TXT file XCTAssertTrue(progress.isFinished, "Expecting the progress to reflect that the task is finished") - XCTAssertEqual(success.title, expectedTitle) + XCTAssertNotEqual(NSString(string: success.title).pathExtension , UTI.text.preferredFilenameExtension) XCTAssertEqual(success.url.pathExtension.lowercased(), "txt") let stringResult = try String(contentsOf: success.url, encoding: .utf8) as NSString // for NSCoding