-
Notifications
You must be signed in to change notification settings - Fork 89
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(home view): allow section declaration to specify a minimum requi…
…red Eigen version (#6297) * chore(deps): update node types to match current 18.15.0 In order to use Array.at() in the next commit, I need to update our Node types to match the actual version of Node we are using. I also had to tweak one file to conform to the updated types. * feat: add a utility for parsing Eigen version numbers * feat: add a predicate that asserts a minimum version number * feat: allow section declaration to specify a minimum Eigen version * feat: enforce the minimum Eigen version But only if there is an actual Eigen version to consider. Otherwise we are presumably coming from a different client altogether, and would not want to gate this section. * refactor: fix filename casing * test: fix desktop UA string * refactor: assume UA is string, not array * test: add an Android case for good measure
- Loading branch information
1 parent
9cab472
commit 812914b
Showing
9 changed files
with
262 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,124 @@ | ||
import { | ||
SemanticVersionNumber, | ||
getEigenVersionNumber, | ||
isAtLeastVersion, | ||
} from "../semanticVersioning" | ||
|
||
describe("getEigenVersionNumber", () => { | ||
describe("with a typical Eigen user agent string", () => { | ||
it("parses the version number", () => { | ||
expect( | ||
getEigenVersionNumber( | ||
"unknown iOS/18.1.1 Artsy-Mobile/8.59.0 Eigen/2024.12.10.06/8.59.0" | ||
) | ||
).toEqual({ | ||
major: 8, | ||
minor: 59, | ||
patch: 0, | ||
}) | ||
}) | ||
}) | ||
|
||
describe("with a __DEV__ Eigen user agent string", () => { | ||
it("parses the version number from iOS", () => { | ||
expect( | ||
getEigenVersionNumber( | ||
"Artsy-Mobile ios null/null Artsy-Mobile/8.59.0 Eigen/null/8.59.0" | ||
) | ||
).toEqual({ | ||
major: 8, | ||
minor: 59, | ||
patch: 0, | ||
}) | ||
}) | ||
|
||
it("parses the version number from Android", () => { | ||
expect( | ||
getEigenVersionNumber( | ||
"Artsy-Mobile android null/null Artsy-Mobile/8.59.0 Eigen/null/8.59.0" | ||
) | ||
).toEqual({ | ||
major: 8, | ||
minor: 59, | ||
patch: 0, | ||
}) | ||
}) | ||
}) | ||
describe("with a typical mobile browser user agent string", () => { | ||
it("returns null", () => { | ||
expect( | ||
getEigenVersionNumber( | ||
"Mozilla/5.0 (iPhone; CPU iPhone OS 18_1_1 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/18.1.1 Mobile/15E148 Safari/604.1" | ||
) | ||
).toBeNull() | ||
}) | ||
}) | ||
|
||
describe("with a typical desktop browser user agent string", () => { | ||
it("returns null", () => { | ||
expect( | ||
getEigenVersionNumber( | ||
"Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/18.1.1 Safari/605.1.15" | ||
) | ||
).toBeNull() | ||
}) | ||
}) | ||
|
||
describe("with an empty user agent string", () => { | ||
it("returns null", () => { | ||
expect(getEigenVersionNumber("")).toBeNull() | ||
}) | ||
}) | ||
|
||
describe("with a gibberish user agent string", () => { | ||
it("returns null", () => { | ||
expect( | ||
getEigenVersionNumber("It’s 2024 so I'm just going to say: Moo Deng") | ||
).toBeNull() | ||
}) | ||
}) | ||
}) | ||
|
||
describe("isAtLeastVersion", () => { | ||
const candidate: SemanticVersionNumber = { | ||
major: 42, | ||
minor: 42, | ||
patch: 42, | ||
} | ||
|
||
it("returns true if the candidate version is identical to the minimum version", () => { | ||
expect( | ||
isAtLeastVersion(candidate, { major: 42, minor: 42, patch: 42 }) | ||
).toBe(true) | ||
}) | ||
|
||
it("tests the candidate major version", () => { | ||
expect( | ||
isAtLeastVersion(candidate, { major: 41, minor: 42, patch: 42 }) | ||
).toBe(true) | ||
|
||
expect( | ||
isAtLeastVersion(candidate, { major: 43, minor: 42, patch: 42 }) | ||
).toBe(false) | ||
}) | ||
|
||
it("tests the candidate minor version", () => { | ||
expect( | ||
isAtLeastVersion(candidate, { major: 42, minor: 41, patch: 42 }) | ||
).toBe(true) | ||
|
||
expect( | ||
isAtLeastVersion(candidate, { major: 42, minor: 43, patch: 42 }) | ||
).toBe(false) | ||
}) | ||
|
||
it("tests the candidate patch version", () => { | ||
expect( | ||
isAtLeastVersion(candidate, { major: 42, minor: 42, patch: 41 }) | ||
).toBe(true) | ||
|
||
expect( | ||
isAtLeastVersion(candidate, { major: 42, minor: 42, patch: 43 }) | ||
).toBe(false) | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
export type SemanticVersionNumber = { | ||
major: number | ||
minor: number | ||
patch: number | ||
} | ||
|
||
export function getEigenVersionNumber( | ||
userAgent: string | ||
): SemanticVersionNumber | null { | ||
if (!userAgent) return null | ||
if (!userAgent.includes("Artsy-Mobile")) return null | ||
|
||
const parts = userAgent.split("/") | ||
const version = parts.at(-1) | ||
|
||
if (!version) return null | ||
|
||
const [major, minor, patch] = version.split(".").map(Number) | ||
|
||
return { major, minor, patch } | ||
} | ||
|
||
export function isAtLeastVersion( | ||
version: SemanticVersionNumber, | ||
atLeast: SemanticVersionNumber | ||
): boolean { | ||
const { major, minor, patch } = atLeast | ||
|
||
if (version.major > major) return true | ||
if (version.major < major) return false | ||
|
||
if (version.minor > minor) return true | ||
if (version.minor < minor) return false | ||
|
||
return version.patch >= patch | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters