Skip to content

Commit

Permalink
Organize code (#247)
Browse files Browse the repository at this point in the history
* Rename LayoutAnchoringTests to UIViewControllerTests

* Move code to UIView.AutoresizingMask and test

* Prefix NS
  • Loading branch information
tinder-emanharoutunian authored Dec 7, 2023
1 parent b59a815 commit d69d19f
Show file tree
Hide file tree
Showing 7 changed files with 124 additions and 111 deletions.
23 changes: 0 additions & 23 deletions Sources/Layout/UIView+Frames.swift
Original file line number Diff line number Diff line change
Expand Up @@ -25,26 +25,3 @@ extension UIView {
return self
}
}

extension UIView.AutoresizingMask {

public static var topLeft: Self {
[.flexibleRightMargin, .flexibleBottomMargin]
}

public static var topRight: Self {
[.flexibleLeftMargin, .flexibleBottomMargin]
}

public static var bottomLeft: Self {
[.flexibleTopMargin, .flexibleRightMargin]
}

public static var bottomRight: Self {
[.flexibleTopMargin, .flexibleLeftMargin]
}

public static var scaleWithSuperview: Self {
[.flexibleWidth, .flexibleHeight]
}
}
File renamed without changes.
34 changes: 34 additions & 0 deletions Sources/Layout/UIView-AutoresizingMask.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
// swiftlint:disable:this file_name
//
// All Contributions by Match Group
//
// Copyright © 2023 Tinder (Match Group, LLC)
//
// Licensed under the Match Group Modified 3-Clause BSD License.
// See https://github.com/Tinder/Layout/blob/main/LICENSE for license information.
//

import UIKit

extension UIView.AutoresizingMask {

public static var topLeft: Self {
[.flexibleRightMargin, .flexibleBottomMargin]
}

public static var topRight: Self {
[.flexibleLeftMargin, .flexibleBottomMargin]
}

public static var bottomLeft: Self {
[.flexibleTopMargin, .flexibleRightMargin]
}

public static var bottomRight: Self {
[.flexibleTopMargin, .flexibleLeftMargin]
}

public static var scaleWithSuperview: Self {
[.flexibleWidth, .flexibleHeight]
}
}
101 changes: 15 additions & 86 deletions Tests/LayoutTests/UIView+FramesTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -14,115 +14,44 @@ import XCTest

final class UIViewFramesTests: XCTestCase {

func testDisablingIntrinsicSize() {

// GIVEN

let view: UIView = givenView()

// THEN

expect(view.contentHuggingPriority(for: .horizontal)) == .defaultLow
expect(view.contentHuggingPriority(for: .vertical)) == .defaultLow
expect(view.contentCompressionResistancePriority(for: .horizontal)) == .defaultHigh
expect(view.contentCompressionResistancePriority(for: .vertical)) == .defaultHigh

// WHEN

_ = view.disablingIntrinsicSize()

// THEN

expect(view.contentHuggingPriority(for: .horizontal)) == .disabled
expect(view.contentHuggingPriority(for: .vertical)) == .disabled
expect(view.contentCompressionResistancePriority(for: .horizontal)) == .disabled
expect(view.contentCompressionResistancePriority(for: .vertical)) == .disabled
}

func testUsingFramesTopLeft() {
func testUsingFrames() {

// GIVEN

let view: UIView = givenView()

// WHEN

_ = view.usingFrames(.topLeft)

// THEN

expect(view.autoresizingMask) == [.flexibleRightMargin, .flexibleBottomMargin]
expect(view.translatesAutoresizingMaskIntoConstraints) == true
}

func testUsingFramesTopRight() {

// GIVEN

let view: UIView = givenView()

// WHEN

_ = view.usingFrames(.topRight)

// THEN

expect(view.autoresizingMask) == [.flexibleLeftMargin, .flexibleBottomMargin]
expect(view.translatesAutoresizingMaskIntoConstraints) == true
}

func testUsingFramesBottomLeft() {

// GIVEN

let view: UIView = givenView()
let view: UIView = .init()
view.translatesAutoresizingMaskIntoConstraints = false

// WHEN

_ = view.usingFrames(.bottomLeft)
_ = view.usingFrames()

// THEN

expect(view.autoresizingMask) == [.flexibleTopMargin, .flexibleRightMargin]
expect(view.translatesAutoresizingMaskIntoConstraints) == true
}

func testUsingFramesBottomRight() {
func testDisablingIntrinsicSize() {

// GIVEN

let view: UIView = givenView()

// WHEN

_ = view.usingFrames(.bottomRight)
let view: UIView = .init()

// THEN

expect(view.autoresizingMask) == [.flexibleTopMargin, .flexibleLeftMargin]
expect(view.translatesAutoresizingMaskIntoConstraints) == true
}

func testUsingFramesScaleWithSuperview() {

// GIVEN

let view: UIView = givenView()
expect(view.contentHuggingPriority(for: .horizontal)) == .defaultLow
expect(view.contentHuggingPriority(for: .vertical)) == .defaultLow
expect(view.contentCompressionResistancePriority(for: .horizontal)) == .defaultHigh
expect(view.contentCompressionResistancePriority(for: .vertical)) == .defaultHigh

// WHEN

_ = view.usingFrames(.scaleWithSuperview)
_ = view.disablingIntrinsicSize()

// THEN

expect(view.autoresizingMask) == [.flexibleWidth, .flexibleHeight]
expect(view.translatesAutoresizingMaskIntoConstraints) == true
}

private func givenView() -> UIView {
let view: UIView = .init()
view.autoresizingMask = []
view.translatesAutoresizingMaskIntoConstraints = false
return view
expect(view.contentHuggingPriority(for: .horizontal)) == .disabled
expect(view.contentHuggingPriority(for: .vertical)) == .disabled
expect(view.contentCompressionResistancePriority(for: .horizontal)) == .disabled
expect(view.contentCompressionResistancePriority(for: .vertical)) == .disabled
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import Nimble
import UIKit
import XCTest

final class UIViewLayoutAnchorTests: XCTestCase {
final class UIViewNSLayoutAnchorTests: XCTestCase {

func testAnchorForXAxisAttribute() {

Expand Down
73 changes: 73 additions & 0 deletions Tests/LayoutTests/UIView-AutoresizingMaskTests.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
// swiftlint:disable:this file_name
//
// All Contributions by Match Group
//
// Copyright © 2023 Tinder (Match Group, LLC)
//
// Licensed under the Match Group Modified 3-Clause BSD License.
// See https://github.com/Tinder/Layout/blob/main/LICENSE for license information.
//

import Foundation

@testable import Layout
import Nimble
import XCTest

final class UIViewAutoresizingTests: XCTestCase {

func testTopLeftResizingMask() {

// GIVEN

let topLeftResizingMask: UIView.AutoresizingMask = .topLeft

// THEN

expect(topLeftResizingMask) == [.flexibleRightMargin, .flexibleBottomMargin]
}

func testTopRightResizingMask() {

// GIVEN

let topRightResizingMask: UIView.AutoresizingMask = .topRight

// THEN

expect(topRightResizingMask) == [.flexibleLeftMargin, .flexibleBottomMargin]
}

func testBottomLeftResizingMask() {

// GIVEN

let bottomLeftResizingMask: UIView.AutoresizingMask = .bottomLeft

// THEN

expect(bottomLeftResizingMask) == [.flexibleTopMargin, .flexibleRightMargin]
}

func testBottomRightResizingMask() {

// GIVEN

let bottomRightResizingMask: UIView.AutoresizingMask = .bottomRight

// THEN

expect(bottomRightResizingMask) == [.flexibleTopMargin, .flexibleLeftMargin]
}

func testScaleWithSuperviewResizingMask() {

// GIVEN

let scaleWithSuperviewResizingMask: UIView.AutoresizingMask = .scaleWithSuperview

// THEN

expect(scaleWithSuperviewResizingMask) == [.flexibleWidth, .flexibleHeight]
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import Nimble
import XCTest

@MainActor
final class LayoutAnchoringTests: XCTestCase {
final class UIViewControllerTests: XCTestCase {

func testViewControllerSafeAreaLayoutGuides() {

Expand Down

0 comments on commit d69d19f

Please sign in to comment.