This repository has been archived by the owner on Oct 31, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 103
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(default-theme): show wish-list items qty in badge of header icon (…
- Loading branch information
Showing
7 changed files
with
169 additions
and
15 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
14 changes: 14 additions & 0 deletions
14
docs/landing/resources/api/composables.iusewishlist.count.md
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,14 @@ | ||
<!-- Do not edit this file. It is automatically generated by API Documenter. --> | ||
|
||
[Home](./index.md) > [@shopware-pwa/composables](./composables.md) > [IUseWishlist](./composables.iusewishlist.md) > [count](./composables.iusewishlist.count.md) | ||
|
||
## IUseWishlist.count property | ||
|
||
> This API is provided as a preview for developers and may change based on feedback that we receive. Do not use this API in a production environment. | ||
> | ||
<b>Signature:</b> | ||
|
||
```typescript | ||
count: Ref<number>; | ||
``` |
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,119 @@ | ||
import Vue from "vue"; | ||
|
||
// Mock Vue Composition API onMounted method | ||
import VueCompositionApi, * as vueComp from "@vue/composition-api"; | ||
(vueComp.onMounted as any) = jest.fn(); | ||
Vue.use(VueCompositionApi); | ||
import { useWishlist } from "@shopware-pwa/composables"; | ||
|
||
describe("Composables - useWishlist", () => { | ||
const rootContextMock: any = { | ||
$shopwareApiInstance: jest.fn(), | ||
}; | ||
beforeEach(() => { | ||
jest.clearAllMocks(); | ||
}); | ||
|
||
describe("computed", () => { | ||
it("should return an empty array on frist useWishlist usage", () => { | ||
const { items, count } = useWishlist(rootContextMock); | ||
expect(items.value).toHaveLength(0); | ||
expect(count.value).toBe(0); | ||
}); | ||
it("should return false if the provided product does not exist or isn't in wishlist yet", () => { | ||
const { isInWishlist } = useWishlist(rootContextMock); | ||
expect(isInWishlist.value).toBe(false); | ||
}); | ||
}); | ||
describe("methods", () => { | ||
const product = { | ||
id: "some-id", | ||
}; | ||
|
||
describe("addToWishlist", () => { | ||
it("should add to wishlist current product if id exists", () => { | ||
const { addToWishlist, items, isInWishlist } = useWishlist( | ||
rootContextMock, | ||
product as any | ||
); | ||
addToWishlist(); | ||
|
||
expect(items.value[0]).toBe("some-id"); | ||
expect(isInWishlist.value).toBe(true); | ||
}); | ||
it("should not add to wishlist current product if id does not exist or product is falsy", () => { | ||
const { addToWishlist, isInWishlist } = useWishlist( | ||
rootContextMock, | ||
undefined as any | ||
); | ||
addToWishlist(); | ||
|
||
expect(isInWishlist.value).toBe(false); | ||
}); | ||
}); | ||
describe("removeFromWishlist", () => { | ||
it("should remove an item if it's included", () => { | ||
const { addToWishlist, isInWishlist, removeFromWishlist } = useWishlist( | ||
rootContextMock, | ||
product as any | ||
); | ||
addToWishlist(); | ||
|
||
expect(isInWishlist.value).toBe(true); | ||
removeFromWishlist(product.id); | ||
expect(isInWishlist.value).toBe(false); | ||
}); | ||
it("should remove an item without providing its id directly", () => { | ||
const { addToWishlist, isInWishlist, removeFromWishlist } = useWishlist( | ||
rootContextMock, | ||
product as any | ||
); | ||
addToWishlist(); | ||
|
||
expect(isInWishlist.value).toBe(true); | ||
removeFromWishlist(undefined as any); | ||
expect(isInWishlist.value).toBe(false); | ||
}); | ||
it("should not do anything when there is no product id", () => { | ||
const { addToWishlist, isInWishlist, removeFromWishlist } = useWishlist( | ||
rootContextMock, | ||
{} as any | ||
); | ||
addToWishlist(); | ||
|
||
removeFromWishlist(undefined as any); | ||
expect(isInWishlist.value).toBe(false); | ||
}); | ||
it("should remove an item without providing its id directly", () => { | ||
const { addToWishlist, isInWishlist, removeFromWishlist } = useWishlist( | ||
rootContextMock, | ||
product as any | ||
); | ||
addToWishlist(); | ||
|
||
expect(isInWishlist.value).toBe(true); | ||
removeFromWishlist(undefined as any); | ||
expect(isInWishlist.value).toBe(false); | ||
}); | ||
}); | ||
describe("clearWishlist", () => { | ||
it("should remove all items from wishlist", () => { | ||
const { addToWishlist, items, clearWishlist } = useWishlist( | ||
rootContextMock, | ||
product as any | ||
); | ||
addToWishlist(); | ||
|
||
expect(items.value).toHaveLength(1); | ||
clearWishlist(); | ||
expect(items.value).toHaveLength(0); | ||
}); | ||
}); | ||
describe("onMounted", () => { | ||
it("should invoke onMounted callback on composable init", () => { | ||
useWishlist(rootContextMock); | ||
expect(vueComp.onMounted).toBeCalled(); | ||
}); | ||
}); | ||
}); | ||
}); |
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
4d4cc78
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Successfully deployed to the following URLs: