Skip to content

Commit b30c61c

Browse files
chazdeanlaurkim
authored andcommitted
[Layout foundations] Add tests for Stack (#7106)
<!-- ☝️How to write a good PR title: - Prefix it with [ComponentName] (if applicable), for example: [Button] - Start with a verb, for example: Add, Delete, Improve, Fix… - Give as much context as necessary and as little as possible - Prefix it with [WIP] while it’s a work in progress --> ### WHY are these changes introduced? Resolves #7093 <!-- link to issue if one exists --> <!-- Context about the problem that’s being addressed. --> ### WHAT is this pull request doing? Adds test for the `AlphaStack` component <!-- Summary of the changes committed. Before / after screenshots are appreciated for UI changes. Make sure to include alt text that describes the screenshot. If you include an animated gif showing your change, wrapping it in a details tag is recommended. Gifs usually autoplay, which can cause accessibility issues for people reviewing your PR: <details> <summary>Summary of your gif(s)</summary> <img src="..." alt="Description of what the gif shows"> </details> --> <!-- ℹ️ Delete the following for small / trivial changes --> ### How to 🎩 🖥 [Local development instructions](https://github.com/Shopify/polaris/blob/main/README.md#local-development) 🗒 [General tophatting guidelines](https://github.com/Shopify/polaris/blob/main/documentation/Tophatting.md) 📄 [Changelog guidelines](https://github.com/Shopify/polaris/blob/main/.github/CONTRIBUTING.md#changelog) <!-- Give as much information as needed to experiment with the component in the playground. --> <details> <summary>Copy-paste this code in <code>playground/Playground.tsx</code>:</summary> ```jsx import React from 'react'; import {Page} from '../src'; export function Playground() { return ( <Page title="Playground"> {/* Add the code you want to test in here */} </Page> ); } ``` </details> ### 🎩 checklist - [ ] Tested on [mobile](https://github.com/Shopify/polaris/blob/main/documentation/Tophatting.md#cross-browser-testing) - [ ] Tested on [multiple browsers](https://help.shopify.com/en/manual/shopify-admin/supported-browsers) - [ ] Tested for [accessibility](https://github.com/Shopify/polaris/blob/main/documentation/Accessibility%20testing.md) - [ ] Updated the component's `README.md` with documentation changes - [ ] [Tophatted documentation](https://github.com/Shopify/polaris/blob/main/documentation/Tophatting%20documentation.md) changes in the style guide
1 parent 8c76290 commit b30c61c

File tree

2 files changed

+32
-5
lines changed

2 files changed

+32
-5
lines changed

polaris-react/src/components/AlphaStack/AlphaStack.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ export const AlphaStack = ({
3030
const className = classNames(styles.Stack);
3131

3232
const style = {
33-
'--pc-stack-align': align,
33+
'--pc-stack-align': align ? `${align}` : '',
3434
...(spacing ? {'--pc-stack-spacing': `var(--p-space-${spacing})`} : {}),
3535
} as React.CSSProperties;
3636

polaris-react/src/components/AlphaStack/tests/AlphaStack.test.tsx

Lines changed: 31 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,39 @@ import {mountWithApp} from 'tests/utilities';
33

44
import {AlphaStack} from '../AlphaStack';
55

6+
const text = 'This is a stack';
7+
const children = <p>{text}</p>;
8+
69
describe('<AlphaStack />', () => {
7-
const renderChildren = () => [0, 1].map((i) => <div key={i}>Child {i}</div>);
10+
it('renders children', () => {
11+
const stack = mountWithApp(<AlphaStack>{children}</AlphaStack>);
12+
13+
expect(stack).toContainReactComponent('p', {children: text});
14+
});
15+
16+
it('renders custom properties by default', () => {
17+
const stack = mountWithApp(<AlphaStack>{children}</AlphaStack>);
18+
19+
expect(stack).toContainReactComponent('div', {
20+
style: {
21+
'--pc-stack-align': 'start',
22+
'--pc-stack-spacing': 'var(--p-space-4)',
23+
} as React.CSSProperties,
24+
});
25+
});
826

9-
it('renders its children', () => {
10-
const stack = mountWithApp(<AlphaStack>{renderChildren()}</AlphaStack>);
27+
it('overrides custom properties if they are passed in', () => {
28+
const stack = mountWithApp(
29+
<AlphaStack align="center" spacing="10">
30+
{children}
31+
</AlphaStack>,
32+
);
1133

12-
expect(stack).toContainReactComponentTimes('div', 3);
34+
expect(stack).toContainReactComponent('div', {
35+
style: {
36+
'--pc-stack-align': 'center',
37+
'--pc-stack-spacing': 'var(--p-space-10)',
38+
} as React.CSSProperties,
39+
});
1340
});
1441
});

0 commit comments

Comments
 (0)