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

fix(EMI-1791): Fix unsaving artwork in multiple lists bug #13862

Merged
merged 3 commits into from
May 13, 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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ export const ArtworkActionsSaveButton: FC<ArtworkActionsSaveButtonProps> = ({
internalID: artwork.internalID,
id: artwork.id,
slug: artwork.slug,
title: artwork.title!,
title: artwork.title ?? "",
year: artwork.date,
artistNames: artwork.artistNames,
imageURL: artwork.preview?.url ?? null,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import { useMutation } from "Utils/Hooks/useMutation"
import { AnalyticsCombinedContextProvider } from "System/Analytics/AnalyticsContext"
import { FC } from "react"
import { flushPromiseQueue } from "DevTools/flushPromiseQueue"
import { MockBoot } from "DevTools/MockBoot"

jest.unmock("react-relay")
jest.mock("Utils/Hooks/useMutation")
Expand All @@ -34,19 +35,17 @@ const { renderWithRelay } = setupTestWrapperTL<
SelectArtworkListsModal_Test_Query
>({
Component: props => {
if (!props.me) {
return null
}

return (
<AnalyticsCombinedContextProvider
contextPageOwnerId="page-owner-id"
path="/artist/page-owner-slug"
>
<ManageArtworkForSavesProvider artwork={artwork}>
<TestComponent {...props} />
</ManageArtworkForSavesProvider>
</AnalyticsCombinedContextProvider>
<MockBoot>
<AnalyticsCombinedContextProvider
contextPageOwnerId="page-owner-id"
path="/artist/page-owner-slug"
>
<ManageArtworkForSavesProvider artwork={artwork}>
<TestComponent {...props} />
</ManageArtworkForSavesProvider>
</AnalyticsCombinedContextProvider>
</MockBoot>
)
},
query: graphql`
Expand All @@ -58,21 +57,15 @@ const { renderWithRelay } = setupTestWrapperTL<
`,
})

// FIXME:
describe.skip("SelectArtworkListsModal", () => {
describe("SelectArtworkListsModal", () => {
const mockUseMutation = useMutation as jest.Mock
const mockUseTracking = useTracking as jest.Mock
const trackEvent = jest.fn()
const submitMutation = jest.fn()

beforeEach(() => {
mockUseMutation.mockImplementation(() => {
return { submitMutation }
})

mockUseTracking.mockImplementation(() => ({
trackEvent,
}))
mockUseMutation.mockImplementation(() => ({ submitMutation }))
mockUseTracking.mockImplementation(() => ({ trackEvent }))
})

it("should render artwork data", async () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,11 @@ export const useSelectArtworkLists = (artworkID: string) => {
artwork.setValue(false, "isSaved")
}

// Update `isSavedToList` field to reflect if artwork was saved to any list
const hasBeenSavedToList = addedCounts.custom - removedCounts.custom > 0
// Update `isSavedToList` field to reflect if artwork was saved to any list or it was already saved
const hasBeenSavedToList =
addedCounts.custom - removedCounts.custom > 0 ||
(removedCounts.custom === 0 && artwork.getValue("isSavedToList"))

artwork.setValue(hasBeenSavedToList, "isSavedToList")
},
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ const SaveArtworkToListsButton: FC<SaveArtworkToListsButtonProps> = ({
internalID: artwork.internalID,
id: artwork.id,
slug: artwork.slug,
title: artwork.title!,
title: artwork.title ?? "",
year: artwork.date,
artistNames: artwork.artistNames,
imageURL: artwork.preview?.url ?? null,
Expand Down
4 changes: 2 additions & 2 deletions src/Components/Artwork/SaveButton/useSaveArtwork.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@ export const useSaveArtwork = ({
{
saveArtwork: {
artwork: {
id: artwork.id!,
slug: artwork.slug!,
id: artwork.id ?? "",
slug: artwork.slug ?? "",
isSaved: !isSaved,
},
/**
Expand Down
4 changes: 2 additions & 2 deletions src/Components/Artwork/SaveButton/useSaveArtworkToLists.ts
Original file line number Diff line number Diff line change
Expand Up @@ -83,8 +83,8 @@ export const useSaveArtworkToLists = (options: SaveArtworkToListsOptions) => {
{
saveArtwork: {
artwork: {
id: artwork.id!,
slug: artwork.slug!,
id: artwork.id,
slug: artwork.slug,
isSaved: !artwork.isSavedToDefaultList,
},
/**
Expand Down