@salesforcedevs/dx-components 0.26.2 → 0.28.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lwc.config.json +2 -1
- package/package.json +2 -6
- package/src/modules/{utils-internal → base-elements}/archiveCard/archiveCard.ts +0 -0
- package/src/modules/{utils-internal → base-elements}/headerBase/headerBase.ts +0 -0
- package/src/modules/dx/cardBlogPostProvider/cardBlogPostProvider.ts +1 -1
- package/src/modules/dx/cardCallout/cardCallout.ts +1 -1
- package/src/modules/dx/cardContent/cardContent.ts +2 -2
- package/src/modules/dx/cardDocs/cardDocs.ts +1 -1
- package/src/modules/dx/cardExpanded/cardExpanded.ts +1 -1
- package/src/modules/dx/cardMinimal/cardMinimal.ts +1 -1
- package/src/modules/dx/cardNews/cardNews.ts +1 -1
- package/src/modules/dx/cardPodcastEpisodeProvider/cardPodcastEpisodeProvider.ts +1 -1
- package/src/modules/dx/cardSmall/cardSmall.ts +1 -1
- package/src/modules/dx/codeBlock/codeBlock.ts +1 -1
- package/src/modules/dx/dropdown/dropdown.ts +1 -1
- package/src/modules/dx/featuredContentHeader/featuredContentHeader.ts +1 -1
- package/src/modules/dx/groupText/groupText.ts +1 -1
- package/src/modules/dx/header/header.ts +1 -1
- package/src/modules/dx/headerMobileNavMenu/headerMobileNavMenu.ts +1 -1
- package/src/modules/dx/headerSearch/headerSearch.ts +1 -1
- package/src/modules/dx/icon/icon.ts +1 -1
- package/src/modules/dx/iconBadge/iconBadge.ts +1 -1
- package/src/modules/dx/input/input.ts +1 -1
- package/src/modules/dx/modalDrawer/modalDrawer.css +40 -0
- package/src/modules/dx/modalDrawer/modalDrawer.html +11 -0
- package/src/modules/dx/modalDrawer/modalDrawer.ts +27 -0
- package/src/modules/dx/popover/popover.ts +1 -1
- package/src/modules/dx/section/section.ts +1 -1
- package/src/modules/dx/sidebar/sidebar.ts +1 -1
- package/src/modules/dx/sidebarSearch/sidebarSearch.ts +2 -5
- package/src/modules/dx/slackCta/slackCta.css +1 -1
- package/src/modules/dx/tooltip/tooltip.css +1 -0
- package/src/modules/dx/typeBadge/typeBadge.ts +1 -1
- package/src/modules/{utils-internal → utils}/coveo/coveo.ts +0 -0
- package/src/modules/{utils-internal → utils}/css/css.ts +0 -0
- package/src/modules/{utils-internal → utils}/devices/devices.ts +0 -0
- package/src/modules/utils/highlight/highlight.ts +1 -1
- package/src/modules/{utils-internal → utils}/options/options.ts +0 -0
- package/src/modules/{utils-internal → utils}/prismjs/prismjs.html +0 -0
- package/src/modules/{utils-internal → utils}/prismjs/prismjs.ts +0 -0
- package/src/modules/{utils-internal → utils}/recentSearches/recentSearches.ts +0 -0
- package/src/modules/{utils-internal → utils}/regexps/regexps.ts +0 -0
- package/src/modules/{utils-internal → utils}/seo/seo.ts +0 -0
- package/src/modules/{utils-internal → utils}/slot/slot.ts +0 -0
- package/src/modules/{utils-internal → utils}/wordpress/wordpress.ts +0 -0
- package/src/modules/dx/banner/__tests__/banner.test.ts +0 -33
- package/src/modules/dx/brandThemeProvider/__tests__/brandThemeProvider.test.ts +0 -49
- package/src/modules/dx/brandThemeProvider/brandThemeProvider.stories.ts +0 -321
- package/src/modules/dx/breadcrumbs/__tests__/breadcrumbs.test.ts +0 -140
- package/src/modules/dx/breadcrumbs/__tests__/mockProps.ts +0 -28
- package/src/modules/dx/breadcrumbs/breadcrumbs.stories.ts +0 -39
- package/src/modules/dx/button/__tests__/button.test.ts +0 -107
- package/src/modules/dx/button/button.stories.ts +0 -150
- package/src/modules/dx/cardBlogPost/__tests__/cardBlogPost.test.ts +0 -26
- package/src/modules/dx/cardBlogPost/__tests__/mockProps.ts +0 -12
- package/src/modules/dx/cardBlogPost/cardBlogPost.stories.ts +0 -164
- package/src/modules/dx/cardBlogPostProvider/__tests__/cardBlogPostProvider.test.ts +0 -34
- package/src/modules/dx/cardBlogPostProvider/__tests__/mockWordpressPosts.ts +0 -44
- package/src/modules/dx/cardCallout/__tests__/cardCallout.test.ts +0 -20
- package/src/modules/dx/cardCallout/__tests__/mockProps.ts +0 -7
- package/src/modules/dx/cardCallout/cardCallout.stories.ts +0 -33
- package/src/modules/dx/cardContent/__tests__/cardContent.test.ts +0 -100
- package/src/modules/dx/cardContent/__tests__/mockProps.ts +0 -13
- package/src/modules/dx/cardContent/cardContent.stories.ts +0 -127
- package/src/modules/dx/cardDemo/cardDemo.stories.ts +0 -115
- package/src/modules/dx/cardDocs/__tests__/cardDocs.test.ts +0 -48
- package/src/modules/dx/cardDocs/__tests__/mockProps.ts +0 -9
- package/src/modules/dx/cardDocs/cardDocs.stories.ts +0 -299
- package/src/modules/dx/cardEvent/__tests__/cardEvent.test.ts +0 -95
- package/src/modules/dx/cardEvent/__tests__/mockProps.ts +0 -10
- package/src/modules/dx/cardEvent/cardEvent.stories.ts +0 -153
- package/src/modules/dx/cardExpanded/__tests__/cardExpanded.test.ts +0 -193
- package/src/modules/dx/cardExpanded/__tests__/mockProps.ts +0 -21
- package/src/modules/dx/cardExpanded/cardExpanded.stories.ts +0 -59
- package/src/modules/dx/cardGrid/__tests__/cardMockProps.ts +0 -431
- package/src/modules/dx/cardGrid/__tests__/mockProps.ts +0 -15
- package/src/modules/dx/cardGrid/cardGrid.stories.ts +0 -111
- package/src/modules/dx/cardMinimal/__tests__/cardMinimal.test.ts +0 -87
- package/src/modules/dx/cardMinimal/__tests__/mockProps.ts +0 -10
- package/src/modules/dx/cardMinimal/cardMinimal.stories.ts +0 -32
- package/src/modules/dx/cardNews/__tests__/cardNews.test.ts +0 -58
- package/src/modules/dx/cardNews/__tests__/mockProps.ts +0 -7
- package/src/modules/dx/cardNews/cardNews.stories.ts +0 -115
- package/src/modules/dx/cardPodcastEpisode/__tests__/cardPodcastEpisode.test.ts +0 -68
- package/src/modules/dx/cardPodcastEpisode/cardPodcastEpisode.stories.ts +0 -31
- package/src/modules/dx/cardPodcastEpisodeProvider/__tests__/cardPodcastEpisodeProvider.test.ts +0 -36
- package/src/modules/dx/cardPodcastEpisodeProvider/__tests__/mockWordpressEpisodes.ts +0 -50
- package/src/modules/dx/cardSmall/__tests__/cardSmall.test.ts +0 -66
- package/src/modules/dx/cardSmall/__tests__/mockProps.ts +0 -8
- package/src/modules/dx/cardSmall/cardSmall.stories.ts +0 -166
- package/src/modules/dx/cardTitle/__tests__/cardTitle.test.ts +0 -46
- package/src/modules/dx/cardTrailheadModule/__tests__/cardTrailheadModule.test.ts +0 -18
- package/src/modules/dx/cardTrailheadModule/__tests__/mockProps.ts +0 -11
- package/src/modules/dx/cardTrailheadModule/cardTrailheadModule.stories.ts +0 -122
- package/src/modules/dx/cardVideoPreview/__tests__/cardVideoPreview.test.ts +0 -22
- package/src/modules/dx/cardVideoPreview/__tests__/mockProps.ts +0 -11
- package/src/modules/dx/cardVideoPreview/cardVideoPreview.stories.ts +0 -147
- package/src/modules/dx/checkbox/__tests__/checkbox.test.ts +0 -85
- package/src/modules/dx/checkbox/__tests__/mockProps.ts +0 -5
- package/src/modules/dx/checkbox/checkbox.stories.ts +0 -38
- package/src/modules/dx/checkboxGroup/__tests__/checkboxGroup.test.ts +0 -80
- package/src/modules/dx/checkboxGroup/__tests__/mockProps.ts +0 -14
- package/src/modules/dx/checkboxGroup/checkboxGroup.stories.ts +0 -33
- package/src/modules/dx/codeBlock/__tests__/codeBlock.test.ts +0 -238
- package/src/modules/dx/codeBlock/__tests__/mockProps.ts +0 -160
- package/src/modules/dx/codeBlock/codeBlock.stories.ts +0 -143
- package/src/modules/dx/dropdown/__tests__/dropdown.test.ts +0 -165
- package/src/modules/dx/dropdown/__tests__/mockNestedOptions.ts +0 -96
- package/src/modules/dx/dropdown/__tests__/mockOptions.ts +0 -10
- package/src/modules/dx/dropdown/__tests__/mockProps.ts +0 -6
- package/src/modules/dx/dropdown/dropdown.stories.ts +0 -89
- package/src/modules/dx/dropdownOption/__tests__/dropdownOption.test.ts +0 -112
- package/src/modules/dx/dropdownOption/__tests__/mockProps.ts +0 -20
- package/src/modules/dx/emptyState/__tests__/emptyState.test.ts +0 -52
- package/src/modules/dx/emptyState/__tests__/mockProps.ts +0 -4
- package/src/modules/dx/emptyState/emptyState.stories.ts +0 -45
- package/src/modules/dx/feature/__tests__/feature.test.ts +0 -51
- package/src/modules/dx/feature/__tests__/mockProps.ts +0 -8
- package/src/modules/dx/featureGrid/__tests__/featureGrid.test.ts +0 -21
- package/src/modules/dx/featureGrid/featureGrid.stories.ts +0 -120
- package/src/modules/dx/featuredContentHeader/__tests__/featuredContentHeader.test.ts +0 -178
- package/src/modules/dx/featuredContentHeader/__tests__/mockProps.ts +0 -73
- package/src/modules/dx/featuredContentHeader/featuredContentHeader.stories.ts +0 -153
- package/src/modules/dx/featuresList/__tests__/featuresList.test.ts +0 -43
- package/src/modules/dx/featuresList/__tests__/mockProps.ts +0 -17
- package/src/modules/dx/featuresList/featuresList.stories.ts +0 -30
- package/src/modules/dx/footer/__tests__/footer.test.ts +0 -147
- package/src/modules/dx/footer/__tests__/mockLocales.ts +0 -7
- package/src/modules/dx/footer/footer.stories.ts +0 -88
- package/src/modules/dx/footerOption/__tests__/footerOption.test.ts +0 -34
- package/src/modules/dx/footerOption/__tests__/mockProps.ts +0 -7
- package/src/modules/dx/formattedDateTime/__tests__/formattedDateTime.test.ts +0 -25
- package/src/modules/dx/formattedDateTime/__tests__/mockProps.ts +0 -13
- package/src/modules/dx/formattedDateTime/formattedDateTime.stories.ts +0 -103
- package/src/modules/dx/grid/__tests__/grid.test.ts +0 -32
- package/src/modules/dx/grid/grid.stories.ts +0 -134
- package/src/modules/dx/groupBio/__tests__/groupBio.test.ts +0 -82
- package/src/modules/dx/groupBio/__tests__/mockProps.ts +0 -15
- package/src/modules/dx/groupBio/groupBio.stories.ts +0 -66
- package/src/modules/dx/groupText/__tests__/groupText.test.ts +0 -69
- package/src/modules/dx/groupText/__tests__/mockProps.ts +0 -35
- package/src/modules/dx/groupText/groupText.stories.ts +0 -81
- package/src/modules/dx/header/__tests__/header.test.ts +0 -236
- package/src/modules/dx/header/__tests__/mockNavArchitects.ts +0 -169
- package/src/modules/dx/header/__tests__/mockNavDevelopers.ts +0 -419
- package/src/modules/dx/header/__tests__/mockNavs.ts +0 -115
- package/src/modules/dx/header/__tests__/mockProps.ts +0 -164
- package/src/modules/dx/header/header.stories.ts +0 -172
- package/src/modules/dx/headerMobileNavMenu/__tests__/headerMobileNavMenu.test.ts +0 -123
- package/src/modules/dx/headerMobileNavMenuOption/__tests__/headerMobileNavMenuOption.test.ts +0 -38
- package/src/modules/dx/headerNav/__tests__/headerNav.test.ts +0 -49
- package/src/modules/dx/headerSearch/__tests__/headerSearch.test.ts +0 -182
- package/src/modules/dx/headerSearch/__tests__/mockData.ts +0 -11
- package/src/modules/dx/headerSearch/__tests__/mockProps.ts +0 -6
- package/src/modules/dx/helmet/__tests__/helmet.test.ts +0 -52
- package/src/modules/dx/helmet/helmet.stories.ts +0 -53
- package/src/modules/dx/hr/__tests__/hr.test.ts +0 -53
- package/src/modules/dx/hr/__tests__/mockProps.ts +0 -16
- package/src/modules/dx/hr/hr.stories.ts +0 -50
- package/src/modules/dx/icon/__tests__/icon.test.ts +0 -54
- package/src/modules/dx/icon/icon.stories.ts +0 -100
- package/src/modules/dx/iconBadge/__tests__/iconBadge.test.ts +0 -17
- package/src/modules/dx/iconBadge/iconBadge.stories.ts +0 -32
- package/src/modules/dx/imageAndLabel/__tests__/imageAndLabel.test.ts +0 -39
- package/src/modules/dx/imageAndLabel/__tests__/mockProps.ts +0 -6
- package/src/modules/dx/imageAndLabel/imageAndLabel.stories.ts +0 -48
- package/src/modules/dx/input/__tests__/input.test.ts +0 -357
- package/src/modules/dx/input/input.stories.ts +0 -102
- package/src/modules/dx/instrumentation/__tests__/instrumentation.test.ts +0 -86
- package/src/modules/dx/interactiveImage/__tests__/interactiveImage.test.ts +0 -83
- package/src/modules/dx/interactiveImage/__tests__/mockProps.ts +0 -39
- package/src/modules/dx/interactiveImage/interactiveImage.stories.ts +0 -31
- package/src/modules/dx/lazy/__tests__/lazy.test.ts +0 -43
- package/src/modules/dx/lazy/lazy.stories.ts +0 -132
- package/src/modules/dx/pagination/__tests__/pagination.test.ts +0 -121
- package/src/modules/dx/pagination/pagination.stories.ts +0 -88
- package/src/modules/dx/podcastHost/__tests__/mockProps.ts +0 -8
- package/src/modules/dx/podcastHost/__tests__/podcastHost.test.ts +0 -21
- package/src/modules/dx/podcastHost/podcastHost.stories.ts +0 -17
- package/src/modules/dx/podcastPlayer/__tests__/podcastPlayer.test.ts +0 -20
- package/src/modules/dx/podcastPlayer/podcastPlayer.stories.ts +0 -13
- package/src/modules/dx/podcastSubscription/__tests__/podcastSubscription.test.ts +0 -16
- package/src/modules/dx/podcastSubscription/podcastSubscription.stories.ts +0 -23
- package/src/modules/dx/popover/__tests__/mockProps.ts +0 -8
- package/src/modules/dx/popover/__tests__/popover.test.ts +0 -313
- package/src/modules/dx/popover/popover.stories.ts +0 -82
- package/src/modules/dx/radioGroup/__tests__/mockProps.ts +0 -12
- package/src/modules/dx/radioGroup/__tests__/radioGroup.test.ts +0 -42
- package/src/modules/dx/radioGroup/radioGroup.stories.ts +0 -25
- package/src/modules/dx/relativeDateTime/__tests__/mockProps.ts +0 -55
- package/src/modules/dx/relativeDateTime/__tests__/relativeDateTime.test.ts +0 -52
- package/src/modules/dx/relativeDateTime/relativeDateTime.stories.ts +0 -83
- package/src/modules/dx/searchResults/searchResults.stories.ts +0 -36
- package/src/modules/dx/section/__tests__/section.test.ts +0 -17
- package/src/modules/dx/section/section.stories.ts +0 -381
- package/src/modules/dx/sectionSignup/__tests__/sectionSignup.test.ts +0 -66
- package/src/modules/dx/sectionSignup/sectionSignup.stories.ts +0 -49
- package/src/modules/dx/select/select.stories.ts +0 -59
- package/src/modules/dx/sidebar/__tests__/mockProps.ts +0 -181
- package/src/modules/dx/sidebar/__tests__/mockSearchChangeEmptyEvent.ts +0 -6
- package/src/modules/dx/sidebar/__tests__/mockSearchChangeEvent.ts +0 -527
- package/src/modules/dx/sidebar/__tests__/sidebar.test.ts +0 -568
- package/src/modules/dx/sidebar/sidebar.stories.ts +0 -188
- package/src/modules/dx/sidebarOld/__tests__/mockProps.ts +0 -178
- package/src/modules/dx/sidebarOld/__tests__/sidebarOld.test.ts +0 -570
- package/src/modules/dx/sidebarOld/sidebarOld.stories.ts +0 -139
- package/src/modules/dx/sidebarSearch/__tests__/mockPreloadedState.ts +0 -1686
- package/src/modules/dx/sidebarSearch/__tests__/sidebarSearch.test.ts +0 -175
- package/src/modules/dx/sidebarSearchResult/__tests__/sidebarSearchResult.test.ts +0 -96
- package/src/modules/dx/slackCta/__tests__/slackCta.test.ts +0 -36
- package/src/modules/dx/slackCta/slackCta.stories.ts +0 -25
- package/src/modules/dx/socials/__tests__/socials.test.ts +0 -114
- package/src/modules/dx/socials/socials.stories.ts +0 -24
- package/src/modules/dx/spinner/__tests__/spinner.test.ts +0 -37
- package/src/modules/dx/spinner/spinner.stories.ts +0 -69
- package/src/modules/dx/tab/__tests__/tab.test.ts +0 -129
- package/src/modules/dx/tab/tab.stories.ts +0 -57
- package/src/modules/dx/toc/__tests__/mockProps.ts +0 -28
- package/src/modules/dx/toc/__tests__/toc.test.ts +0 -109
- package/src/modules/dx/toc/toc.stories.ts +0 -26
- package/src/modules/dx/tooltip/__tests__/tooltip.test.ts +0 -22
- package/src/modules/dx/tooltip/tooltip.stories.ts +0 -46
- package/src/modules/dx/topics/__tests__/mockProps.ts +0 -3
- package/src/modules/dx/topics/__tests__/topics.test.ts +0 -31
- package/src/modules/dx/tree/__tests__/mockProps.ts +0 -215
- package/src/modules/dx/tree/__tests__/tree.test.ts +0 -346
- package/src/modules/dx/tree/__tests__/treeHandler.test.ts +0 -194
- package/src/modules/dx/tree/tree.stories.ts +0 -65
- package/src/modules/dx/treeItem/__tests__/mockProps.ts +0 -46
- package/src/modules/dx/treeItem/__tests__/treeItem.test.ts +0 -377
- package/src/modules/dx/treeTile/__tests__/mockProps.ts +0 -16
- package/src/modules/dx/treeTile/__tests__/treeTile.test.ts +0 -168
- package/src/modules/dx/typeBadge/__tests__/typeBadge.test.ts +0 -77
- package/src/modules/dx/typeBadge/typeBadge.stories.ts +0 -114
- package/src/modules/dx/typeBadgeGroup/__tests__/mockProps.ts +0 -11
- package/src/modules/dx/typeBadgeGroup/__tests__/typeBadgeGroup.test.ts +0 -72
- package/src/modules/dx/typeBadgeGroup/typeBadgeGroup.stories.ts +0 -19
- package/src/modules/test-components/buttonTest/buttonTest.html +0 -3
- package/src/modules/test-components/buttonTest/buttonTest.ts +0 -3
- package/src/modules/test-components/codeBlockTest/codeBlockTest.js +0 -4
- package/src/modules/test-components/featureGridTest/featureGridTest.html +0 -7
- package/src/modules/test-components/featureGridTest/featureGridTest.ts +0 -5
- package/src/modules/test-components/instrumentationTest/instrumentationTest.html +0 -4
- package/src/modules/test-components/instrumentationTest/instrumentationTest.ts +0 -8
- package/src/modules/test-components/popoverTest/popoverTest.html +0 -6
- package/src/modules/test-components/popoverTest/popoverTest.ts +0 -5
- package/src/modules/test-components/slackCtaTest/slackCtaTest.html +0 -3
- package/src/modules/test-components/slackCtaTest/slackCtaTest.ts +0 -3
- package/src/modules/utils/highlight/__tests__/highlight.test.ts +0 -108
- package/src/modules/utils/highlight/__tests__/mockProps.ts +0 -45
- package/src/modules/utils-internal/jest/jest.ts +0 -58
- package/src/modules/utils-internal/recentSearches/__tests__/recentSearches.test.ts +0 -83
- package/src/modules/utils-internal/storybook/storybook.ts +0 -32
- package/src/modules/utils-internal/tests/tests.ts +0 -38
- package/src/modules/utils-internal/wordpress/__tests__/wordpress.test.ts +0 -15
|
@@ -1,238 +0,0 @@
|
|
|
1
|
-
import CodeBlock from "../codeBlock";
|
|
2
|
-
import { createRenderComponent } from "utils-internal/tests";
|
|
3
|
-
import mockProps from "./mockProps";
|
|
4
|
-
import { track as gtmTrack } from "dx/instrumentation";
|
|
5
|
-
//import Prism from "utils-internal/prismjs";
|
|
6
|
-
|
|
7
|
-
const TAG = "dx-code-block";
|
|
8
|
-
const render = createRenderComponent(TAG, CodeBlock);
|
|
9
|
-
|
|
10
|
-
jest.mock("dx/instrumentation");
|
|
11
|
-
|
|
12
|
-
const GTM_EVENT_NAME = "custEv_codeBlock";
|
|
13
|
-
/*
|
|
14
|
-
const mockPrismHighlight = jest.fn();
|
|
15
|
-
jest.mock("utils-internal/prismjs", () =>
|
|
16
|
-
jest.fn().mockImplementation(() => {
|
|
17
|
-
return {
|
|
18
|
-
highlightAllUnder: mockPrismHighlight
|
|
19
|
-
};
|
|
20
|
-
})
|
|
21
|
-
);
|
|
22
|
-
*/
|
|
23
|
-
|
|
24
|
-
describe(TAG, () => {
|
|
25
|
-
const oldNavigator = window.navigator;
|
|
26
|
-
const oldError = console.error;
|
|
27
|
-
|
|
28
|
-
afterAll(() => {
|
|
29
|
-
Object.assign(window.navigator, oldNavigator);
|
|
30
|
-
Object.assign(console.error, oldError);
|
|
31
|
-
});
|
|
32
|
-
|
|
33
|
-
it("renders the codeblock in dark mode", async () => {
|
|
34
|
-
const element = render({
|
|
35
|
-
codeBlock: mockProps.apex,
|
|
36
|
-
title: "Apex Example",
|
|
37
|
-
defaultTheme: "dark",
|
|
38
|
-
language: "apex"
|
|
39
|
-
});
|
|
40
|
-
expect(window.localStorage.getItem("dx-codeblock-theme")).toBe(null);
|
|
41
|
-
const dxThemeDark = element.shadowRoot.querySelector(".dx-theme-dark");
|
|
42
|
-
expect(dxThemeDark).not.toContain(null);
|
|
43
|
-
expect(element.shadowRoot.querySelector(".source-btn")).toBe(null);
|
|
44
|
-
|
|
45
|
-
await expect(element).toBeAccessible();
|
|
46
|
-
});
|
|
47
|
-
|
|
48
|
-
it("renders the codeblock in light mode", async () => {
|
|
49
|
-
const element = render({
|
|
50
|
-
codeBlock: mockProps.java,
|
|
51
|
-
title: "Java Example",
|
|
52
|
-
language: "java"
|
|
53
|
-
});
|
|
54
|
-
const dxThemeLight =
|
|
55
|
-
element.shadowRoot.querySelector(".dx-theme-light");
|
|
56
|
-
expect(dxThemeLight).not.toContain(null);
|
|
57
|
-
|
|
58
|
-
expect(element.shadowRoot.querySelector(".source-btn")).toBe(null);
|
|
59
|
-
|
|
60
|
-
await expect(element).toBeAccessible();
|
|
61
|
-
});
|
|
62
|
-
|
|
63
|
-
it("changes between themes", async () => {
|
|
64
|
-
const element = render({
|
|
65
|
-
codeBlock: mockProps.java,
|
|
66
|
-
title: "Java Example",
|
|
67
|
-
language: "java"
|
|
68
|
-
});
|
|
69
|
-
|
|
70
|
-
//expect light
|
|
71
|
-
const divTheme = element.shadowRoot.querySelector(".dx-theme-light");
|
|
72
|
-
expect(divTheme).not.toBeNull();
|
|
73
|
-
|
|
74
|
-
const updateThemeBtn = element.shadowRoot.querySelector(
|
|
75
|
-
"dx-button.update-theme-btn"
|
|
76
|
-
);
|
|
77
|
-
|
|
78
|
-
//update light -> dark
|
|
79
|
-
updateThemeBtn.click();
|
|
80
|
-
|
|
81
|
-
//gtm event
|
|
82
|
-
expect(gtmTrack).toBeCalled();
|
|
83
|
-
|
|
84
|
-
return Promise.resolve()
|
|
85
|
-
.then(() => {
|
|
86
|
-
//expect -> dark
|
|
87
|
-
expect(divTheme.classList).toContain("dx-theme-dark");
|
|
88
|
-
element.shadowRoot
|
|
89
|
-
.querySelector("dx-button.update-theme-btn")
|
|
90
|
-
.click();
|
|
91
|
-
|
|
92
|
-
//expect gtm event for dark mode
|
|
93
|
-
expect(gtmTrack).toBeCalledWith(
|
|
94
|
-
updateThemeBtn,
|
|
95
|
-
GTM_EVENT_NAME,
|
|
96
|
-
{
|
|
97
|
-
codeBlockAction: "darkmode"
|
|
98
|
-
}
|
|
99
|
-
);
|
|
100
|
-
})
|
|
101
|
-
.then(() => {
|
|
102
|
-
//expect -> light
|
|
103
|
-
expect(divTheme.classList).toContain("dx-theme-light");
|
|
104
|
-
|
|
105
|
-
//expect gtm event for dark mode
|
|
106
|
-
expect(gtmTrack).toBeCalledWith(
|
|
107
|
-
updateThemeBtn,
|
|
108
|
-
GTM_EVENT_NAME,
|
|
109
|
-
{
|
|
110
|
-
codeBlockAction: "lightmode"
|
|
111
|
-
}
|
|
112
|
-
);
|
|
113
|
-
});
|
|
114
|
-
});
|
|
115
|
-
|
|
116
|
-
it("renders source button", async () => {
|
|
117
|
-
const element = render({
|
|
118
|
-
codeBlock: mockProps.java,
|
|
119
|
-
title: "Java Example",
|
|
120
|
-
language: "java",
|
|
121
|
-
sourceLink: "http://www.salesforce.com"
|
|
122
|
-
});
|
|
123
|
-
|
|
124
|
-
const sourceBtn = element.shadowRoot.querySelector(".source-btn");
|
|
125
|
-
expect(sourceBtn).not.toBe(null);
|
|
126
|
-
expect(sourceBtn.href).toBe("http://www.salesforce.com");
|
|
127
|
-
|
|
128
|
-
await expect(element).toBeAccessible();
|
|
129
|
-
});
|
|
130
|
-
|
|
131
|
-
it("renders custom markup with text code content", async () => {
|
|
132
|
-
const element = render({
|
|
133
|
-
codeBlock: mockProps.text,
|
|
134
|
-
title: "Text Code Content",
|
|
135
|
-
language: "text"
|
|
136
|
-
});
|
|
137
|
-
|
|
138
|
-
const sourceContent = element.shadowRoot.querySelector(
|
|
139
|
-
".code-block-content"
|
|
140
|
-
);
|
|
141
|
-
const titleElement = element.shadowRoot.querySelector(
|
|
142
|
-
".dx-code-block-heading"
|
|
143
|
-
);
|
|
144
|
-
|
|
145
|
-
expect(sourceContent).not.toBe(null);
|
|
146
|
-
expect(sourceContent.textContent).toContain(
|
|
147
|
-
"Connected to Salesforce Functions"
|
|
148
|
-
);
|
|
149
|
-
expect(titleElement).not.toBe(null);
|
|
150
|
-
expect(titleElement.textContent).toBe("Text Code Content");
|
|
151
|
-
|
|
152
|
-
await expect(element).toBeAccessible();
|
|
153
|
-
});
|
|
154
|
-
|
|
155
|
-
it("Test copy functionality", async () => {
|
|
156
|
-
const element = render({
|
|
157
|
-
codeBlock: mockProps.java,
|
|
158
|
-
title: "Java Example",
|
|
159
|
-
language: "java",
|
|
160
|
-
sourceLink: "http://www.salesforce.com"
|
|
161
|
-
});
|
|
162
|
-
|
|
163
|
-
Object.assign(window.navigator, {
|
|
164
|
-
clipboard: { writeText: jest.fn() }
|
|
165
|
-
});
|
|
166
|
-
Object.assign(console, { error: jest.fn() });
|
|
167
|
-
|
|
168
|
-
const sourceBtn = element.shadowRoot.querySelector(".copy-btn");
|
|
169
|
-
expect(sourceBtn).not.toBe(null);
|
|
170
|
-
sourceBtn.click();
|
|
171
|
-
|
|
172
|
-
//gtm event
|
|
173
|
-
expect(gtmTrack).toBeCalled();
|
|
174
|
-
|
|
175
|
-
expect(gtmTrack).toBeCalledWith(sourceBtn, GTM_EVENT_NAME, {
|
|
176
|
-
codeBlockAction: "copy"
|
|
177
|
-
});
|
|
178
|
-
|
|
179
|
-
expect(window.navigator.clipboard.writeText).toBeCalledTimes(1);
|
|
180
|
-
expect(window.navigator.clipboard.writeText).toBeCalledWith(
|
|
181
|
-
element.shadowRoot.querySelector(".code-block-content").textContent
|
|
182
|
-
);
|
|
183
|
-
expect(console.error).toBeCalledTimes(0);
|
|
184
|
-
|
|
185
|
-
await expect(element).toBeAccessible();
|
|
186
|
-
});
|
|
187
|
-
|
|
188
|
-
it("Test Theme update Wire functionality", async () => {
|
|
189
|
-
window.localStorage.removeItem("dx-codeblock-theme");
|
|
190
|
-
const element = render({
|
|
191
|
-
codeBlock: mockProps.java,
|
|
192
|
-
title: "Java Example",
|
|
193
|
-
language: "java",
|
|
194
|
-
sourceLink: "http://www.salesforce.com"
|
|
195
|
-
});
|
|
196
|
-
expect(window.localStorage.getItem("dx-codeblock-theme")).toBeNull();
|
|
197
|
-
const divTheme = element.shadowRoot.querySelector(".dx-theme-light");
|
|
198
|
-
expect(divTheme).not.toBeNull();
|
|
199
|
-
|
|
200
|
-
element.shadowRoot.querySelector("dx-button.update-theme-btn").click();
|
|
201
|
-
|
|
202
|
-
return Promise.resolve().then(() => {
|
|
203
|
-
expect(window.localStorage.getItem("dx-codeblock-theme")).toBe(
|
|
204
|
-
"dark"
|
|
205
|
-
);
|
|
206
|
-
//expect -> dark
|
|
207
|
-
expect(divTheme.classList).toContain("dx-theme-dark");
|
|
208
|
-
});
|
|
209
|
-
});
|
|
210
|
-
|
|
211
|
-
it("Test if new code-blocks render with dark theme if the localstorage has dx-codeblock-theme key set", async () => {
|
|
212
|
-
window.localStorage.setItem("dx-codeblock-theme", "dark");
|
|
213
|
-
const element = render({
|
|
214
|
-
codeBlock: mockProps.java,
|
|
215
|
-
title: "Java Example",
|
|
216
|
-
language: "java",
|
|
217
|
-
sourceLink: "http://www.salesforce.com"
|
|
218
|
-
});
|
|
219
|
-
const dxThemeDark = element.shadowRoot.querySelector(".dx-theme-dark");
|
|
220
|
-
expect(dxThemeDark).not.toContain(null);
|
|
221
|
-
});
|
|
222
|
-
|
|
223
|
-
it("Test if new code-blocks render with light theme if the localstorage has ivalid theme against dx-codeblock-theme key", async () => {
|
|
224
|
-
window.localStorage.setItem("dx-codeblock-theme", "not-valid-theme");
|
|
225
|
-
const element = render({
|
|
226
|
-
codeBlock: mockProps.java,
|
|
227
|
-
title: "Java Example",
|
|
228
|
-
language: "java",
|
|
229
|
-
sourceLink: "http://www.salesforce.com"
|
|
230
|
-
});
|
|
231
|
-
|
|
232
|
-
const divTheme = element.shadowRoot.querySelector(".dx-theme-light");
|
|
233
|
-
expect(divTheme).not.toBeNull();
|
|
234
|
-
expect(window.localStorage.getItem("dx-codeblock-theme")).toBe(
|
|
235
|
-
element.defaultTheme
|
|
236
|
-
);
|
|
237
|
-
});
|
|
238
|
-
});
|
|
@@ -1,160 +0,0 @@
|
|
|
1
|
-
export default {
|
|
2
|
-
preTagApex: `<pre class="codeblock brush:apex">
|
|
3
|
-
trigger AccountTrigger on Account (after update) {
|
|
4
|
-
Map<ID, Account> acctMapToUpdate = new Map<Id, Account>();
|
|
5
|
-
for(Integer i = 0 ; i < trigger.new.size() ; i++){
|
|
6
|
-
Account old = trigger.old[i];
|
|
7
|
-
Account nw = trigger.new[i];
|
|
8
|
-
if(old.TickerSymbol != nw.TickerSymbol){
|
|
9
|
-
Account a = new Account(Id = nw.Id, Rating = 'Needs Evaluation');
|
|
10
|
-
acctMapToUpdate.put(nw.Id, a);
|
|
11
|
-
}
|
|
12
|
-
}
|
|
13
|
-
if(acctMapToUpdate.size() > 0){
|
|
14
|
-
update acctMapToUpdate.values();
|
|
15
|
-
}
|
|
16
|
-
}
|
|
17
|
-
</pre>`,
|
|
18
|
-
|
|
19
|
-
xml: `
|
|
20
|
-
<rsp stat="ok" version="1.0">
|
|
21
|
-
<result>
|
|
22
|
-
<total_results>...</total_results>
|
|
23
|
-
<form>...</form>
|
|
24
|
-
<form>...</form>
|
|
25
|
-
<form>...</form>
|
|
26
|
-
</result>
|
|
27
|
-
</rsp>`,
|
|
28
|
-
|
|
29
|
-
apex: `trigger AccountTrigger on Account (after update) {
|
|
30
|
-
Map<ID, Account> acctMapToUpdate = new Map<Id, Account>();
|
|
31
|
-
for(Integer i = 0 ; i < trigger.new.size() ; i++){
|
|
32
|
-
Account old = trigger.old[i];
|
|
33
|
-
Account nw = trigger.new[i];
|
|
34
|
-
if(old.TickerSymbol != nw.TickerSymbol){
|
|
35
|
-
Account a = new Account(Id = nw.Id, Rating = 'Needs Evaluation');
|
|
36
|
-
acctMapToUpdate.put(nw.Id, a);
|
|
37
|
-
}
|
|
38
|
-
}
|
|
39
|
-
if(acctMapToUpdate.size() > 0){
|
|
40
|
-
update acctMapToUpdate.values();
|
|
41
|
-
}
|
|
42
|
-
}`,
|
|
43
|
-
|
|
44
|
-
java: `
|
|
45
|
-
/* HelloWorld.java */
|
|
46
|
-
public class HelloWorld {
|
|
47
|
-
char oneChar = 'C';
|
|
48
|
-
public static void main(String[] args) {
|
|
49
|
-
System.out.println("Hello World");
|
|
50
|
-
}
|
|
51
|
-
}
|
|
52
|
-
`,
|
|
53
|
-
|
|
54
|
-
javascript: `
|
|
55
|
-
function swap(array, i, j) {
|
|
56
|
-
var temp = array[i];
|
|
57
|
-
array[i] = array[j];
|
|
58
|
-
array[j] = temp;
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
function getRandomInt(min, max) {
|
|
62
|
-
return Math.floor(Math.random() * (max - min + 1)) + min;
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
console.log("Sorted array: ");
|
|
66
|
-
console.log(arr);
|
|
67
|
-
`,
|
|
68
|
-
|
|
69
|
-
css: `
|
|
70
|
-
p {
|
|
71
|
-
border-style: solid;
|
|
72
|
-
border-left: thick double #ff0000;
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
div {
|
|
76
|
-
border: 1px solid black;
|
|
77
|
-
margin: 25px;
|
|
78
|
-
background-color: lightblue;
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
.toolbar-item:first-child {
|
|
82
|
-
flex-basis: 95%;
|
|
83
|
-
}
|
|
84
|
-
|
|
85
|
-
dx-button {
|
|
86
|
-
--dx-c-button-primary-color: var(--dx-g-hot-orange-vibrant-95);
|
|
87
|
-
}`,
|
|
88
|
-
|
|
89
|
-
visualforce: `
|
|
90
|
-
<apex:column value="{! ct.FirstName }">
|
|
91
|
-
<apex:facet name="header">
|
|
92
|
-
<apex:commandLink action="{! sortByFirstName }"
|
|
93
|
-
reRender="contacts_list">First Name
|
|
94
|
-
</apex:commandLink>
|
|
95
|
-
</apex:facet>
|
|
96
|
-
</apex:column>
|
|
97
|
-
<apex:column value="{! ct.LastName }">
|
|
98
|
-
<apex:facet name="header">
|
|
99
|
-
<apex:commandLink action="{! sortByLastName }"
|
|
100
|
-
reRender="contacts_list">Last Name
|
|
101
|
-
</apex:commandLink>
|
|
102
|
-
</apex:facet>
|
|
103
|
-
</apex:column>
|
|
104
|
-
`,
|
|
105
|
-
|
|
106
|
-
html: `
|
|
107
|
-
<!DOCTYPE html>
|
|
108
|
-
<html>
|
|
109
|
-
<head>
|
|
110
|
-
<script src="vendor/prism.js"></script>
|
|
111
|
-
<style>
|
|
112
|
-
h1 {color: red}
|
|
113
|
-
</style>
|
|
114
|
-
</head>
|
|
115
|
-
<body>
|
|
116
|
-
<dx-button>I am a Button</dx-button>
|
|
117
|
-
<!-- This is
|
|
118
|
-
a multiline
|
|
119
|
-
comment -->
|
|
120
|
-
|
|
121
|
-
<h2>Unordered List with Circle Bullets</h2>
|
|
122
|
-
<ul style="list-style-type : circle;">
|
|
123
|
-
<li>Coffee</li>
|
|
124
|
-
|
|
125
|
-
<!-- This is a one line comment -->
|
|
126
|
-
|
|
127
|
-
<li>Tea</li>
|
|
128
|
-
<li>Milk</li>
|
|
129
|
-
</ul>
|
|
130
|
-
</body>
|
|
131
|
-
</html>
|
|
132
|
-
`,
|
|
133
|
-
|
|
134
|
-
TypeScript: `
|
|
135
|
-
export default class CodeBlock {
|
|
136
|
-
overrideWidth?: boolean = false;
|
|
137
|
-
title: string = 'title';
|
|
138
|
-
variant?: CodeBlockVariant = 'card';
|
|
139
|
-
|
|
140
|
-
get isCard(): boolean {
|
|
141
|
-
return this.variant === 'card';
|
|
142
|
-
}
|
|
143
|
-
}
|
|
144
|
-
`,
|
|
145
|
-
|
|
146
|
-
php: `
|
|
147
|
-
function makeItBIG($a_lot_of_names) {
|
|
148
|
-
foreach($a_lot_of_names as $the_simpsons) {
|
|
149
|
-
$BIG[] = strtoupper($the_simpsons);
|
|
150
|
-
}
|
|
151
|
-
return $BIG;
|
|
152
|
-
}
|
|
153
|
-
|
|
154
|
-
$a_lot_of_names = ['Homer', 'Marge', 'Bart', 'Maggy', 'Lisa'];
|
|
155
|
-
var_dump(makeItBIG($a_lot_of_names));
|
|
156
|
-
`,
|
|
157
|
-
text: `
|
|
158
|
-
Connected to Salesforce Functions account:\nAccount ID: <ID>\nLogin Org Domain: <org domain>\nLogin Org ID: <org ID>
|
|
159
|
-
`
|
|
160
|
-
};
|
|
@@ -1,143 +0,0 @@
|
|
|
1
|
-
import mockProps from "./__tests__/mockProps";
|
|
2
|
-
import "../../helpers/code/code.css";
|
|
3
|
-
import "../../helpers/text/text.css";
|
|
4
|
-
import "../../helpers/reset/reset.css";
|
|
5
|
-
|
|
6
|
-
export default {
|
|
7
|
-
title: "dx/dx-code-block",
|
|
8
|
-
component: "dx-code-block"
|
|
9
|
-
};
|
|
10
|
-
|
|
11
|
-
const styles = `
|
|
12
|
-
<style>
|
|
13
|
-
dx-code-block {
|
|
14
|
-
display:block;
|
|
15
|
-
margin-bottom:12px;
|
|
16
|
-
}
|
|
17
|
-
</style>`;
|
|
18
|
-
|
|
19
|
-
export const Base = (args: any) => `${styles}
|
|
20
|
-
|
|
21
|
-
<span class="dx-text-heading-7 dx-code-block-heading">XML Example - Dark Theme</span>
|
|
22
|
-
<dx-code-block
|
|
23
|
-
title="XML example"
|
|
24
|
-
code-block="${args.xml}"
|
|
25
|
-
language="xml"
|
|
26
|
-
default-theme="dark"
|
|
27
|
-
></dx-code-block>
|
|
28
|
-
|
|
29
|
-
<span class="dx-text-heading-7 dx-code-block-heading">Dark Theme</span>
|
|
30
|
-
<dx-code-block
|
|
31
|
-
title="Apex Example"
|
|
32
|
-
code-block="${args.apex}"
|
|
33
|
-
language="apex"
|
|
34
|
-
default-theme="dark"
|
|
35
|
-
></dx-code-block>
|
|
36
|
-
|
|
37
|
-
<span class="dx-text-heading-7 dx-code-block-heading">Visualforce Example - Dark Theme</span>
|
|
38
|
-
<dx-code-block
|
|
39
|
-
title="Visualforce example"
|
|
40
|
-
code-block="${args.visualforce}"
|
|
41
|
-
language="visualforce"
|
|
42
|
-
default-theme="dark"
|
|
43
|
-
></dx-code-block>
|
|
44
|
-
|
|
45
|
-
<span class="dx-text-heading-7 dx-code-block-heading">Javascript Example - Dark Theme</span>
|
|
46
|
-
<dx-code-block
|
|
47
|
-
title="Javascript example"
|
|
48
|
-
code-block="${args.javascript}"
|
|
49
|
-
language="javascript"
|
|
50
|
-
default-theme="dark"
|
|
51
|
-
></dx-code-block>
|
|
52
|
-
|
|
53
|
-
<span class="dx-text-heading-7 dx-code-block-heading">Dark Theme - Source Button</span>
|
|
54
|
-
<dx-code-block
|
|
55
|
-
title="Java Example"
|
|
56
|
-
code-block="${args.java}"
|
|
57
|
-
language="java"
|
|
58
|
-
source-link="http://www.salesforce.com"
|
|
59
|
-
default-theme="dark"
|
|
60
|
-
></dx-code-block>
|
|
61
|
-
|
|
62
|
-
<span class="dx-text-heading-7 dx-code-block-heading">Dark Theme - No Language</span>
|
|
63
|
-
<dx-code-block
|
|
64
|
-
title="No Language Example"
|
|
65
|
-
code-block="${args.java}"
|
|
66
|
-
source-link="http://www.salesforce.com"
|
|
67
|
-
default-theme="dark"
|
|
68
|
-
></dx-code-block>
|
|
69
|
-
|
|
70
|
-
<span class="dx-text-heading-7 dx-code-block-heading">HTML Example - Dark Theme</span>
|
|
71
|
-
<dx-code-block
|
|
72
|
-
title="HTML Example"
|
|
73
|
-
code-block="${args.html}"
|
|
74
|
-
language="html"
|
|
75
|
-
default-theme="dark"
|
|
76
|
-
></dx-code-block>
|
|
77
|
-
|
|
78
|
-
<span class="dx-text-heading-7 dx-code-block-heading">Dark Theme</span>
|
|
79
|
-
<dx-code-block
|
|
80
|
-
title="TypeScript Example"
|
|
81
|
-
code-block="${args.TypeScript}"
|
|
82
|
-
language="TypeScript"
|
|
83
|
-
default-theme="dark"
|
|
84
|
-
></dx-code-block>
|
|
85
|
-
|
|
86
|
-
<span class="dx-text-heading-7 dx-code-block-heading">CSS Example - Dark Theme</span>
|
|
87
|
-
<dx-code-block
|
|
88
|
-
title="CSS Example"
|
|
89
|
-
code-block="${args.css}"
|
|
90
|
-
language="css"
|
|
91
|
-
default-theme="dark"
|
|
92
|
-
></dx-code-block>
|
|
93
|
-
|
|
94
|
-
<span class="dx-text-heading-7 dx-code-block-heading">PHP Example - Dark Theme</span>
|
|
95
|
-
<dx-code-block
|
|
96
|
-
title="PHP Example"
|
|
97
|
-
code-block="${args.php}"
|
|
98
|
-
language="php"
|
|
99
|
-
default-theme="dark"
|
|
100
|
-
></dx-code-block>`;
|
|
101
|
-
Base.args = mockProps;
|
|
102
|
-
|
|
103
|
-
export const PreTag = (args: any) => `${styles}
|
|
104
|
-
<span class="dx-text-heading-7 dx-code-block-heading">Dark Theme</span>
|
|
105
|
-
<dx-code-block
|
|
106
|
-
title="Pre Tag Apex Example"
|
|
107
|
-
code-block="${args.preTagApex}"
|
|
108
|
-
language="apex"
|
|
109
|
-
default-theme="dark"
|
|
110
|
-
></dx-code-block>
|
|
111
|
-
`;
|
|
112
|
-
PreTag.args = mockProps;
|
|
113
|
-
|
|
114
|
-
export const LangParameterAsText = (args: any) => `${styles}
|
|
115
|
-
<span class="dx-text-heading-7 dx-code-block-heading">Fallback lang parameter as 'text' - XML example</span>
|
|
116
|
-
<dx-code-block
|
|
117
|
-
title="XML example"
|
|
118
|
-
code-block="${args.xml}"
|
|
119
|
-
language="text"
|
|
120
|
-
></dx-code-block>
|
|
121
|
-
|
|
122
|
-
<span class="dx-text-heading-7 dx-code-block-heading">Fallback lang parameter as 'text' - Javascript example</span>
|
|
123
|
-
<dx-code-block
|
|
124
|
-
title="XML example"
|
|
125
|
-
code-block="${args.javascript}"
|
|
126
|
-
language="text"
|
|
127
|
-
></dx-code-block>
|
|
128
|
-
|
|
129
|
-
<span class="dx-text-heading-7 dx-code-block-heading">Fallback lang parameter as 'text' - Apex example</span>
|
|
130
|
-
<dx-code-block
|
|
131
|
-
title="XML example"
|
|
132
|
-
code-block="${args.apex}"
|
|
133
|
-
language="text"
|
|
134
|
-
></dx-code-block>
|
|
135
|
-
|
|
136
|
-
<span class="dx-text-heading-7 dx-code-block-heading"> Passed lang parameter as 'text' - Text example</span>
|
|
137
|
-
<dx-code-block
|
|
138
|
-
title="Text example with markup"
|
|
139
|
-
code-block="${args.text}"
|
|
140
|
-
language="text"
|
|
141
|
-
></dx-code-block>`;
|
|
142
|
-
|
|
143
|
-
LangParameterAsText.args = mockProps;
|
|
@@ -1,165 +0,0 @@
|
|
|
1
|
-
import Dropdown from "dx/dropdown";
|
|
2
|
-
import DropdownOption from "dx/dropdownOption";
|
|
3
|
-
import Popover from "dx/popover";
|
|
4
|
-
import { getOptionsCount } from "utils-internal/options";
|
|
5
|
-
import { createRenderComponent } from "utils-internal/tests";
|
|
6
|
-
import mockNestedOptions from "./mockNestedOptions";
|
|
7
|
-
import mockProps from "./mockProps";
|
|
8
|
-
|
|
9
|
-
const TAG = "dx-dropdown";
|
|
10
|
-
const render = createRenderComponent(TAG, Dropdown);
|
|
11
|
-
|
|
12
|
-
describe(TAG, () => {
|
|
13
|
-
describe("render", () => {
|
|
14
|
-
it("renders all options when open", () => {
|
|
15
|
-
const component = render({ ...mockProps, open: true });
|
|
16
|
-
|
|
17
|
-
const menuDiv: HTMLElement =
|
|
18
|
-
component.shadowRoot.querySelector(".menu_list");
|
|
19
|
-
expect(menuDiv).not.toBeNull();
|
|
20
|
-
expect(menuDiv.getAttribute("role")).toBe("menu");
|
|
21
|
-
|
|
22
|
-
const options =
|
|
23
|
-
component.shadowRoot.querySelectorAll("dx-dropdown-option");
|
|
24
|
-
expect(options.length).toEqual(mockProps.options.length);
|
|
25
|
-
return expect(component).toBeAccessible();
|
|
26
|
-
});
|
|
27
|
-
|
|
28
|
-
it("renders all nested options and the callout link when open", () => {
|
|
29
|
-
const component = render({
|
|
30
|
-
...mockProps,
|
|
31
|
-
options: mockNestedOptions,
|
|
32
|
-
open: true
|
|
33
|
-
});
|
|
34
|
-
|
|
35
|
-
const options: Array<DropdownOption> = Array.from(
|
|
36
|
-
component.shadowRoot.querySelectorAll("dx-dropdown-option")
|
|
37
|
-
);
|
|
38
|
-
const link = component.shadowRoot.querySelector(".callout_link");
|
|
39
|
-
const count = getOptionsCount(mockNestedOptions);
|
|
40
|
-
expect(options.length).toEqual(count);
|
|
41
|
-
|
|
42
|
-
options.forEach(({ keyValue, option }) => {
|
|
43
|
-
expect(keyValue).not.toBeFalsy();
|
|
44
|
-
expect(keyValue).toBe(option.id);
|
|
45
|
-
});
|
|
46
|
-
expect(link).not.toBeNull();
|
|
47
|
-
return expect(component).toBeAccessible();
|
|
48
|
-
});
|
|
49
|
-
|
|
50
|
-
it("value prop activates the selected option", () => {
|
|
51
|
-
const component = render({ ...mockProps, open: true });
|
|
52
|
-
const options = Array.from(
|
|
53
|
-
component.shadowRoot.querySelectorAll("dx-dropdown-option")
|
|
54
|
-
);
|
|
55
|
-
const selectedOption = options.find(
|
|
56
|
-
// @ts-ignore
|
|
57
|
-
(option: HTMLElement) => option.active === true
|
|
58
|
-
);
|
|
59
|
-
// @ts-ignore
|
|
60
|
-
const id = selectedOption.option.id;
|
|
61
|
-
expect(id).toEqual(mockProps.value);
|
|
62
|
-
return expect(component).toBeAccessible();
|
|
63
|
-
});
|
|
64
|
-
|
|
65
|
-
it("renders with menu-offset-small and menu-hidden", () => {
|
|
66
|
-
const component = render({ offset: "small", options: [] });
|
|
67
|
-
const popover: Popover =
|
|
68
|
-
component.shadowRoot.querySelector("dx-popover");
|
|
69
|
-
expect(popover).not.toBeNull();
|
|
70
|
-
|
|
71
|
-
expect(popover.classList).toContain("menu-offset-small");
|
|
72
|
-
expect(popover.classList).toContain("menu-hidden");
|
|
73
|
-
|
|
74
|
-
const options =
|
|
75
|
-
component.shadowRoot.querySelectorAll("dx-dropdown-option");
|
|
76
|
-
expect(options).toHaveLength(0);
|
|
77
|
-
|
|
78
|
-
return expect(component).toBeAccessible();
|
|
79
|
-
});
|
|
80
|
-
});
|
|
81
|
-
|
|
82
|
-
describe("interactions", () => {
|
|
83
|
-
it("doesn't close after onchange when stayOpenAfterChange is true", async () => {
|
|
84
|
-
const component = render({
|
|
85
|
-
...mockProps,
|
|
86
|
-
stayOpenAfterChange: true,
|
|
87
|
-
open: true
|
|
88
|
-
});
|
|
89
|
-
const mockClose = jest.fn();
|
|
90
|
-
|
|
91
|
-
const popover = component.shadowRoot.querySelector("dx-popover");
|
|
92
|
-
popover.addEventListener("close", mockClose);
|
|
93
|
-
|
|
94
|
-
const option =
|
|
95
|
-
component.shadowRoot.querySelector("dx-dropdown-option");
|
|
96
|
-
const id = option.option.id;
|
|
97
|
-
option.dispatchEvent(new CustomEvent("select", { detail: id }));
|
|
98
|
-
|
|
99
|
-
expect(mockClose).not.toHaveBeenCalled();
|
|
100
|
-
expect(component.open).toEqual(true);
|
|
101
|
-
|
|
102
|
-
return expect(component).toBeAccessible();
|
|
103
|
-
});
|
|
104
|
-
|
|
105
|
-
it("closes after onchange when stayOpenAfterChange is false", async () => {
|
|
106
|
-
const component = render({
|
|
107
|
-
...mockProps,
|
|
108
|
-
open: true
|
|
109
|
-
});
|
|
110
|
-
const mockClose = jest.fn();
|
|
111
|
-
|
|
112
|
-
const popover = component.shadowRoot.querySelector("dx-popover");
|
|
113
|
-
popover.addEventListener("close", mockClose);
|
|
114
|
-
|
|
115
|
-
const option: DropdownOption =
|
|
116
|
-
component.shadowRoot.querySelector("dx-dropdown-option");
|
|
117
|
-
const id = option.option.id;
|
|
118
|
-
option.dispatchEvent(new CustomEvent("select", { detail: id }));
|
|
119
|
-
|
|
120
|
-
expect(mockClose).toHaveBeenCalledTimes(1);
|
|
121
|
-
return expect(component).toBeAccessible();
|
|
122
|
-
});
|
|
123
|
-
|
|
124
|
-
it("handles keydown event with ArrowDown key", () => {
|
|
125
|
-
const [firstOption] = mockProps.options;
|
|
126
|
-
const component = render({ ...mockProps, value: null, open: true });
|
|
127
|
-
expect(component.focusedValue).toBeNull();
|
|
128
|
-
|
|
129
|
-
component.dispatchEvent(
|
|
130
|
-
new KeyboardEvent("keydown", { key: "ArrowDown" })
|
|
131
|
-
);
|
|
132
|
-
expect(component.focusedValue).toBe(firstOption.id);
|
|
133
|
-
});
|
|
134
|
-
|
|
135
|
-
it("ignores other click keys", () => {
|
|
136
|
-
const component = render({ ...mockProps, open: true });
|
|
137
|
-
|
|
138
|
-
component.dispatchEvent(
|
|
139
|
-
new KeyboardEvent("keydown", { key: "ArrowDown" })
|
|
140
|
-
);
|
|
141
|
-
expect(component.focusedValue).toBe(mockProps.value);
|
|
142
|
-
|
|
143
|
-
component.dispatchEvent(
|
|
144
|
-
new KeyboardEvent("keydown", { key: "ArrowLeft" })
|
|
145
|
-
);
|
|
146
|
-
|
|
147
|
-
expect(component.focusedValue).toBe(mockProps.value);
|
|
148
|
-
});
|
|
149
|
-
|
|
150
|
-
it("handles close event from popover", () => {
|
|
151
|
-
const component = render({ ...mockProps, open: true });
|
|
152
|
-
|
|
153
|
-
component.dispatchEvent(
|
|
154
|
-
new KeyboardEvent("keydown", { key: "ArrowDown" })
|
|
155
|
-
);
|
|
156
|
-
expect(component.focusedValue).toBe(mockProps.value);
|
|
157
|
-
|
|
158
|
-
const popover: HTMLElement =
|
|
159
|
-
component.shadowRoot.querySelector("dx-popover");
|
|
160
|
-
expect(popover).not.toBeNull();
|
|
161
|
-
popover.dispatchEvent(new CustomEvent("close"));
|
|
162
|
-
expect(component.focusedValue).toBeNull();
|
|
163
|
-
});
|
|
164
|
-
});
|
|
165
|
-
});
|