-
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.
- Loading branch information
Maciej Kucmus
committed
Nov 7, 2019
1 parent
e5807d0
commit 8cecf72
Showing
9 changed files
with
154 additions
and
8 deletions.
There are no files selected for viewing
23 changes: 23 additions & 0 deletions
23
packages/shopware-6-client/__tests__/services/PageService/getPage.spec.ts
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,23 @@ | ||
import { getPage } from "@shopware-pwa/shopware-6-client"; | ||
import { apiService } from "../../../src/apiService"; | ||
|
||
jest.mock("../../../src/apiService"); | ||
const mockedAxios = apiService as jest.Mocked<typeof apiService>; | ||
|
||
describe("PageService - getPage", () => { | ||
beforeEach(() => { | ||
jest.resetAllMocks(); | ||
}); | ||
it("should return cmsPage for given path", async () => { | ||
mockedAxios.post.mockResolvedValueOnce({ | ||
data: { cmsPage: { id: "b218f861361042f3a58a2a9d1b3575b5" } } | ||
}); | ||
const result = await getPage("Sports/Grocery-Garden"); | ||
expect(mockedAxios.post).toBeCalledTimes(1); | ||
expect(mockedAxios.post).toBeCalledWith("/vsf/page", { | ||
path: "Sports/Grocery-Garden" | ||
}); | ||
expect(result).toHaveProperty("cmsPage"); | ||
expect(result.cmsPage.id).toEqual("b218f861361042f3a58a2a9d1b3575b5"); | ||
}); | ||
}); |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,50 @@ | ||
interface cmsService {} | ||
import { Category } from "../interfaces/models/content/category/Category"; | ||
import { getNavigationEndpoint } from "../endpoints"; | ||
import { SearchResult } from "../interfaces/response/SearchResult"; | ||
import { apiService } from "../apiService"; | ||
import { getCategories } from "./categoryService"; | ||
import { SearchFilterType } from "../interfaces/search/SearchFilter"; | ||
|
||
export async function getNavigation(): Promise<SearchResult<Category[]>> { | ||
const resp = await apiService.post(getNavigationEndpoint()); | ||
|
||
return resp.data; | ||
} | ||
/** | ||
* remove when https://github.com/elkmod/SwagVueStorefront/issues/15 is done | ||
*/ | ||
export async function getNavigationTemp( | ||
parentId: string | ||
): Promise< | ||
Array<{ | ||
header: string | null; | ||
items: Array<{ | ||
label: string | null; | ||
count: number; | ||
}>; | ||
}> | ||
> { | ||
const resp = await getCategories({ | ||
filters: [ | ||
{ | ||
type: SearchFilterType.EQUALS, | ||
field: "parentId", | ||
value: parentId | ||
} | ||
], | ||
configuration: { associations: [{ name: "children" }] } | ||
}); | ||
|
||
const navigation = resp.data.map(category => ({ | ||
header: category.name, | ||
id: category.id, | ||
items: category.children | ||
? category.children.map(child => ({ | ||
label: child.name, | ||
count: child.childrenCount | ||
})) | ||
: [] | ||
})); | ||
|
||
return navigation; | ||
} |
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
69 changes: 69 additions & 0 deletions
69
test-page/src/components/cms/elements/SwCategoryNavigationSlot.vue
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,69 @@ | ||
<template> | ||
<div class="sw-category-navigation"> | ||
<SfAccordion :firstOpen="true" :showChevron="false"> | ||
<SfAccordionItem | ||
v-for="accordion in navigation" | ||
:key="accordion.id" | ||
:header="accordion.header" | ||
> | ||
<template v-if="accordion.items.length > 0 "> | ||
<SfList> | ||
<SfListItem v-for="(item, j) in accordion.items" :key="j"> | ||
<SfMenuItem :label="item.label" :count="item.count" /> | ||
</SfListItem> | ||
</SfList> | ||
</template> | ||
</SfAccordionItem> | ||
</SfAccordion> | ||
</div> | ||
</template> | ||
|
||
<script> | ||
import { | ||
SfSidebar, | ||
SfButton, | ||
SfList, | ||
SfIcon, | ||
SfMenuItem, | ||
SfFilter, | ||
SfProductCard, | ||
SfPagination, | ||
SfAccordion, | ||
SfSelect, | ||
SfBottomNavigation, | ||
SfCircleIcon | ||
} from "@storefront-ui/vue"; | ||
import { getNavigationTemp } from "@shopware-pwa/shopware-6-client"; | ||
export default { | ||
components: { | ||
SfAccordion, | ||
SfList, | ||
SfMenuItem | ||
}, | ||
data() { | ||
return { | ||
navigationResponse: [] | ||
} | ||
}, | ||
props: { | ||
content: { | ||
type: Object, | ||
default: () => ({}) | ||
} | ||
}, | ||
async mounted() { | ||
// TODO get the current category id from state management | ||
this.navigationResponse = await getNavigationTemp("3f637f17cd9f4891a2d7625d19fb37c9") | ||
}, | ||
computed: { | ||
navigation() { | ||
return this.navigationResponse | ||
} | ||
} | ||
}; | ||
</script> | ||
|
||
<style lang="scss" scoped> | ||
</style> |
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