Skip to content

Commit

Permalink
test: Prevent using fixed title
Browse files Browse the repository at this point in the history
  • Loading branch information
PhilippeWeidmann committed Feb 27, 2024
1 parent 5dd38a7 commit 1f5939a
Showing 1 changed file with 8 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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)")

Expand Down Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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)
Expand All @@ -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
Expand All @@ -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)
Expand All @@ -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")
Expand All @@ -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)")
Expand All @@ -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")
Expand All @@ -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)")
Expand All @@ -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
Expand All @@ -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")
Expand All @@ -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
Expand All @@ -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")
Expand All @@ -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)")

Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 1f5939a

Please sign in to comment.