Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add getAspectRatio method to collection config #335

Merged
merged 5 commits into from
Nov 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.gu.facia.api.models

import com.gu.facia.api.models.CollectionConfig.AspectRatio.{Landscape53, Landscape54, Landscape54Collections, Portrait45, PortraitCollections, Square}
import com.gu.facia.client.models.{AnyPlatform, Backfill, CollectionConfigJson, CollectionPlatform, DisplayHintsJson, FrontsToolSettings, Metadata, TargetedTerritory}

case class Groups(groups: List[String])
Expand Down Expand Up @@ -88,4 +89,48 @@ object CollectionConfig {
collectionJson.platform.getOrElse(AnyPlatform),
collectionJson.frontsToolSettings,
collectionJson.suppressImages.exists(identity))

sealed trait AspectRatio {
def label: String
}

object AspectRatio {
case object Portrait45 extends AspectRatio {
val label = "4:5"
}

case object Landscape53 extends AspectRatio {
val label = "5:3"
}

case object Landscape54 extends AspectRatio {
val label = "5:4"
}

case object Square extends AspectRatio {
val label = "1:1"
}

val Landscape54Collections = List(
"flexible/special",
"flexible/general",
"scrollable/small",
"scrollable/medium",
"static/medium/4",
)

val PortraitCollections = List(
"scrollable/feature",
"static/feature/2",
)
}

def getAspectRatio(collectionConfig: CollectionConfig): AspectRatio = {
collectionConfig.collectionType match {
case _ if PortraitCollections.contains(collectionConfig.collectionType) => Portrait45
case _ if Landscape54Collections.contains(collectionConfig.collectionType) => Landscape54
case "scrollable/highlights" => Square
case _ => Landscape53
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package com.gu.facia.api.models
import com.gu.contentapi.client.model.v1.{Content, ContentFields, ContentType}
import com.gu.facia.api.utils.ContentApiUtils._
import com.gu.facia.api.utils._
import com.gu.facia.client.models.CollectionConfigJson.emptyConfig.collectionType
import com.gu.facia.client.models.{Branded, CollectionConfigJson, CollectionJson, Trail, TrailMetaData}
import org.joda.time.DateTime
import org.mockito.Mockito._
Expand Down Expand Up @@ -473,5 +474,17 @@ class CollectionTest extends AnyFreeSpec with Matchers with MockitoSugar with On
)
FaciaContentUtils.headline(FaciaContentUtils.supporting(result.head).head) should be ("straight banana")
}
"AspectRatio.getAspectRatio" in {
val defaultCollectionType = collectionConfig.collectionType
val defaultCollectionConfig = CollectionConfig.empty.copy(collectionType = defaultCollectionType)
val scrollableFeatureConfig = CollectionConfig.empty.copy(collectionType ="scrollable/feature")
val scrollableSmallConfig = CollectionConfig.empty.copy(collectionType ="scrollable/small")
val scrollableHighlightsConfig = CollectionConfig.empty.copy(collectionType ="scrollable/highlights")

CollectionConfig.getAspectRatio(defaultCollectionConfig) should be (CollectionConfig.AspectRatio.Landscape53)
CollectionConfig.getAspectRatio(scrollableFeatureConfig) should be (CollectionConfig.AspectRatio.Portrait45)
CollectionConfig.getAspectRatio(scrollableSmallConfig) should be (CollectionConfig.AspectRatio.Landscape54)
CollectionConfig.getAspectRatio(scrollableHighlightsConfig) should be (CollectionConfig.AspectRatio.Square)
}
}
}
Loading