Skip to content

Commit

Permalink
Merge branch 'main' into gkartalis/bump-rn-74
Browse files Browse the repository at this point in the history
  • Loading branch information
gkartalis authored Nov 7, 2024
2 parents 11d63c1 + 4610421 commit a351c81
Show file tree
Hide file tree
Showing 6 changed files with 26 additions and 123 deletions.
32 changes: 11 additions & 21 deletions src/app/Components/ArtworkGrids/LotProgressBar.tests.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { ProgressBar } from "@artsy/palette-mobile"
import { DurationProvider } from "app/Components/Countdown"
import { renderWithWrappers } from "app/utils/tests/renderWithWrappers"
import { DateTime } from "luxon"
import moment from "moment"
import { LotProgressBar, LotProgressBarProps } from "./LotProgressBar"

Expand All @@ -25,9 +24,9 @@ describe("LotProgressBar", () => {
duration: null,
}

const wrapper = getWrapper(props)
const { UNSAFE_queryAllByType } = getWrapper(props)

expect(wrapper.UNSAFE_queryAllByType(ProgressBar).length).toBe(1)
expect(UNSAFE_queryAllByType(ProgressBar).length).toBe(1)
})
})

Expand All @@ -36,7 +35,7 @@ describe("LotProgressBar", () => {
jest.clearAllMocks()
})

it("Does not show if extendedBiddingEndAt or endAt is past", () => {
it("Does not show if extendedBiddingEndAt or endAt is past", () => {
const props = {
extendedBiddingPeriodMinutes: 2,
extendedBiddingIntervalMinutes: 2,
Expand All @@ -46,34 +45,25 @@ describe("LotProgressBar", () => {
duration: null,
}

const wrapper = getWrapper(props)
const { UNSAFE_queryAllByType } = getWrapper(props)

expect(wrapper.UNSAFE_queryAllByType(ProgressBar).length).toBe(0)
expect(UNSAFE_queryAllByType(ProgressBar).length).toBe(0)
})

it("ProgressBar disappears when time elapses", () => {
// 2 mins
const biddingEndAt = new Date(Date.now() + 1000 * 60 * 60 * 2).toISOString()
const now = new Date(Date.now()).toISOString()
const props = {
extendedBiddingPeriodMinutes: 2,
extendedBiddingIntervalMinutes: 2,
startAt: new Date(Date.now()).toISOString(),
biddingEndAt,
startAt: now,
biddingEndAt: now,
hasBeenExtended: true,
duration: moment.duration(DateTime.fromISO(biddingEndAt).toMillis()),
duration: moment.duration(),
}

jest.useFakeTimers({
legacyFakeTimers: true,
})

const wrapper = getWrapper(props)

expect(wrapper.UNSAFE_queryAllByType(ProgressBar).length).toBe(1)

jest.advanceTimersByTime(1000 * 60 * 60 * 2)
const { UNSAFE_queryAllByType } = getWrapper(props)

expect(wrapper.UNSAFE_queryAllByType(ProgressBar).length).toBe(0)
expect(UNSAFE_queryAllByType(ProgressBar).length).toBe(0)
})
})
})
2 changes: 2 additions & 0 deletions src/app/Components/ArtworkGrids/LotProgressBar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,11 @@ export interface LotProgressBarProps extends ArtworkAuctionProgressBarProps {

export const LotProgressBar: React.FC<LotProgressBarProps> = (props) => {
const { duration } = props

if (!duration) {
return null
}

const time = {
days: duration.asDays(),
hours: duration.hours(),
Expand Down
9 changes: 7 additions & 2 deletions src/app/Components/Lists/AuctionResultListItem.tests.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Touchable } from "@artsy/palette-mobile"
import { AuctionResultListItemTestsQuery } from "__generated__/AuctionResultListItemTestsQuery.graphql"
import { navigate } from "app/system/navigation/navigate"
import * as navigation from "app/system/navigation/navigate"
import { extractNodes } from "app/utils/extractNodes"
import { extractText } from "app/utils/tests/extractText"
import { renderWithWrappersLEGACY } from "app/utils/tests/renderWithWrappers"
Expand All @@ -12,7 +12,12 @@ import { AuctionResultListItemFragmentContainer } from "./AuctionResultListItem"

describe("AuctionResults", () => {
let mockEnvironment: ReturnType<typeof createMockEnvironment>
beforeEach(() => (mockEnvironment = createMockEnvironment()))
const navigate = jest.spyOn(navigation, "navigate")

beforeEach(() => {
mockEnvironment = createMockEnvironment()
jest.clearAllMocks()
})

const TestRenderer = ({ onPress }: { onPress?: () => void }) => (
<QueryRenderer<AuctionResultListItemTestsQuery>
Expand Down
4 changes: 3 additions & 1 deletion src/app/Scenes/Activity/ActivityItem.tests.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { fireEvent, screen, waitFor } from "@testing-library/react-native"
import { ActivityItem_Test_Query } from "__generated__/ActivityItem_Test_Query.graphql"
import { ActivityItem_notification$key } from "__generated__/ActivityItem_notification.graphql"
import { navigate } from "app/system/navigation/navigate"
import * as navigation from "app/system/navigation/navigate"
import { extractNodes } from "app/utils/extractNodes"
import { mockTrackEvent } from "app/utils/tests/globallyMockedStuff"
import { setupTestWrapper } from "app/utils/tests/setupTestWrapper"
Expand Down Expand Up @@ -34,9 +34,11 @@ const TestRenderer = () => {

describe("ActivityItem", () => {
let mockEnvironment: ReturnType<typeof createMockEnvironment>
const navigate = jest.spyOn(navigation, "navigate")

beforeEach(() => {
mockEnvironment = createMockEnvironment()
jest.clearAllMocks()
})

const { renderWithRelay } = setupTestWrapper({
Expand Down
4 changes: 3 additions & 1 deletion src/app/Scenes/PriceDatabase/PriceDatabase.tests.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { act, fireEvent } from "@testing-library/react-native"
import { ArtistAutosuggestResultsPaginationQuery } from "__generated__/ArtistAutosuggestResultsPaginationQuery.graphql"
import { __globalStoreTestUtils__ } from "app/store/GlobalStore"
import { navigate } from "app/system/navigation/navigate"
import * as navigation from "app/system/navigation/navigate"
import { getMockRelayEnvironment } from "app/system/relay/defaultEnvironment"
import { mockTrackEvent } from "app/utils/tests/globallyMockedStuff"
import { renderWithHookWrappersTL, renderWithWrappers } from "app/utils/tests/renderWithWrappers"
Expand All @@ -10,9 +10,11 @@ import { PriceDatabase } from "./PriceDatabase"

describe(PriceDatabase, () => {
let mockEnvironment: ReturnType<typeof createMockEnvironment>
const navigate = jest.spyOn(navigation, "navigate")

beforeEach(() => {
mockEnvironment = getMockRelayEnvironment()
jest.clearAllMocks()
})

it("renders the price database", () => {
Expand Down
98 changes: 0 additions & 98 deletions src/setupJest.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,6 @@ import { mockPostEventToProviders, mockTrackEvent } from "app/utils/tests/global
import { mockNavigate } from "app/utils/tests/navigationMocks"
import chalk from "chalk"
import * as matchers from "jest-extended"

import { isPlainObject } from "lodash"
import { NativeModules } from "react-native"
import "react-native-gesture-handler/jestSetup"
// @ts-ignore-next-line
Expand Down Expand Up @@ -170,10 +168,6 @@ jest.mock("react-native-blob-util", () => ({

jest.mock("@react-native-cookies/cookies", () => ({ clearAll: jest.fn() }))

beforeEach(() => {
require("@react-native-cookies/cookies").clearAll.mockReset()
})

jest.mock("react-native-fbsdk-next", () => ({
LoginManager: {
logOut: jest.fn(),
Expand Down Expand Up @@ -266,40 +260,6 @@ jest.mock("react-native-localize", () => ({

require("react-native-reanimated").setUpTests()

// @ts-expect-error
global.__reanimatedWorkletInit = () => {}

jest.mock("react-native-reanimated", () => {
const animationMock = {
duration: () => {
return jest.fn()
},
}

return {
...require("react-native-reanimated/mock"),
useEvent: jest.fn(),
FadeInRight: animationMock,
FadeInLeft: animationMock,
FadeIn: {
duration: () => {
return { easing: jest.fn() }
},
},
FadeInDown: {
duration: () => {
return { easing: jest.fn() }
},
},
FadeOut: {
duration: () => {
return { easing: jest.fn() }
},
},
FadeOutRight: animationMock,
}
})

jest.mock("react-native/Libraries/LayoutAnimation/LayoutAnimation", () => ({
...jest.requireActual("react-native/Libraries/LayoutAnimation/LayoutAnimation"),
configureNext: jest.fn((_config, callback) => callback?.()),
Expand All @@ -309,46 +269,6 @@ jest.mock("react-native/Libraries/LayoutAnimation/LayoutAnimation", () => ({
spring: jest.fn(),
}))

jest.mock("react-native-gesture-handler", () => {
const actual = jest.requireActual("react-native-gesture-handler")
const View = require("react-native/Libraries/Components/View/View")
const TouchableWithoutFeedback = require("react-native/Libraries/Components/Touchable/TouchableWithoutFeedback")
const TouchableHighlight = require("react-native/Libraries/Components/Touchable/TouchableHighlight")

return {
...actual,
Swipeable: View,
DrawerLayout: View,
State: {},
ScrollView: View,
Slider: View,
Switch: View,
TextInput: View,
ViewPagerAndroid: View,
DrawerLayoutAndroid: View,
WebView: View,
NativeViewGestureHandler: View,
TapGestureHandler: View,
FlingGestureHandler: View,
ForceTouchGestureHandler: View,
LongPressGestureHandler: View,
PanGestureHandler: View,
PinchGestureHandler: View,
RotationGestureHandler: View,
/* Buttons */
RawButton: View,
BaseButton: View,
RectButton: View,
BorderlessButton: View,
/* Other */
FlatList: View,
gestureHandlerRootHOC: jest.fn(),
Directions: {},
TouchableHighlight,
TouchableWithoutFeedback,
}
})

jest.mock("react-native-image-crop-picker", () => ({
openPicker: jest.fn(),
openCamera: jest.fn(),
Expand Down Expand Up @@ -559,24 +479,6 @@ jest.mock("app/NativeModules/LegacyNativeModules", () => ({

Object.assign(NativeModules, getNativeModules())

beforeEach(() => {
function reset(a: any, b: any) {
Object.keys(a).forEach((k) => {
if (isPlainObject(a[k])) {
reset(a[k], b[k])
} else {
if (a[k]?.mockReset) {
a[k].mockReset()
} else {
a[k] = b?.[k] ?? a[k]
}
}
})
}
reset(NativeModules, getNativeModules())
reset(require("app/system/navigation/navigate"), {})
})

const mockedModule = (path: string, mockModuleName: string) => jest.mock(path, () => mockModuleName)
mockedModule("./app/Components/Gene/Header.tsx", "Header")

Expand Down

0 comments on commit a351c81

Please sign in to comment.