-
Notifications
You must be signed in to change notification settings - Fork 57
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
vanessa
committed
Dec 6, 2024
1 parent
882b72e
commit fb0aa62
Showing
42 changed files
with
1,637 additions
and
560 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
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
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
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
61 changes: 61 additions & 0 deletions
61
client/test/preview/unit/components/asset/AddToCartButton.test.tsx
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,61 @@ | ||
import { fireEvent, render, screen } from '@testing-library/react'; | ||
import AddToCartButton from 'preview/components/asset/AddToCartButton'; | ||
import * as React from 'react'; | ||
import * as cartAccess from 'preview/store/CartAccess'; | ||
import { mockLibraryAsset } from 'test/preview/__mocks__/global_mocks'; | ||
import { useSelector } from 'react-redux'; | ||
import { RootState } from 'store/store'; | ||
import { selectAssetByPathAndPrivacy } from 'preview/store/assets.slice'; | ||
|
||
describe('AddToCartButton', () => { | ||
const addMock = jest.fn(); | ||
const removeMock = jest.fn(); | ||
const clearMock = jest.fn(); | ||
|
||
beforeEach(() => { | ||
(useSelector as jest.MockedFunction<typeof useSelector>).mockImplementation( | ||
(selector: (state: RootState) => unknown) => { | ||
if (selector === selectAssetByPathAndPrivacy('path', true)) { | ||
return mockLibraryAsset; | ||
} | ||
return mockLibraryAsset; | ||
}, | ||
); | ||
}); | ||
|
||
afterEach(() => { | ||
jest.clearAllMocks(); | ||
}); | ||
|
||
it('should add asset to cart when not in cart', () => { | ||
jest.spyOn(cartAccess, 'default').mockReturnValue({ | ||
state: { assets: [] }, | ||
actions: { | ||
add: addMock, | ||
remove: removeMock, | ||
clear: clearMock, | ||
}, | ||
}); | ||
|
||
render(<AddToCartButton assetPath="path" assetPrivacy={true} />); | ||
|
||
fireEvent.click(screen.getByRole('button')); | ||
expect(addMock).toHaveBeenCalled(); | ||
}); | ||
|
||
it('should remove asset to cart when not in cart', () => { | ||
jest.spyOn(cartAccess, 'default').mockReturnValue({ | ||
state: { assets: [mockLibraryAsset] }, | ||
actions: { | ||
add: addMock, | ||
remove: removeMock, | ||
clear: clearMock, | ||
}, | ||
}); | ||
|
||
render(<AddToCartButton assetPath="path" assetPrivacy={true} />); | ||
|
||
fireEvent.click(screen.getByRole('button')); | ||
expect(removeMock).toHaveBeenCalled(); | ||
}); | ||
}); |
Oops, something went wrong.