Skip to content

Commit 7cce8ab

Browse files
Merge pull request #787 from chromaui/docs_visual_testing_handbook_TypeScript_updates
Docs: Visual testing Handbook - TypeScript migration
2 parents 9d836ec + 97e85fa commit 7cce8ab

File tree

15 files changed

+695
-656
lines changed

15 files changed

+695
-656
lines changed

content/visual-testing-handbook/react/en/automate.md

Lines changed: 61 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
title: 'Automate visual testing'
33
tocTitle: 'Automate'
44
description: 'Automate visual testing to catch regressions'
5-
commit: 'b9671fb'
5+
commit: '198ca0f'
66
---
77

88
Over the natural course of development, bugs are inevitable. Visual test automation uses machines to detect changes in UI appearance for a human to review.
@@ -55,7 +55,7 @@ UI tests capture an image snapshot of every story in a cloud browser environment
5555
Add Chromatic as a development package to your project:
5656

5757
```shell
58-
yarn add -D chromatic
58+
yarn add --dev chromatic
5959
```
6060

6161
Once it’s finished installing, we have all that we need. Now is an excellent time to commit and push the changes to the remote repository.
@@ -92,20 +92,45 @@ git checkout -b change-commentlist-outline
9292

9393
Tweak the `CommentList` component
9494

95-
```diff:title=src/components/CommentList.jsx
96-
import PropTypes from 'prop-types';
95+
```diff:title=src/components/CommentList.tsx
96+
import styled, { createGlobalStyle } from "styled-components";
9797

98-
import styled, { createGlobalStyle } from 'styled-components';
98+
interface Author {
99+
name: string;
100+
avatar: string;
101+
}
102+
103+
interface Comment {
104+
text: string;
105+
author: Author;
106+
}
107+
108+
export interface CommentListProps {
109+
/**
110+
* Is the component in the loading state
111+
*/
112+
loading?: boolean;
113+
114+
/**
115+
* Total number of comments
116+
*/
117+
totalCount?: number;
118+
119+
/**
120+
* List of comments
121+
*/
122+
comments?: Comment[];
123+
}
99124

100-
const CommentListDiv = styled.div`
125+
const CommentListWrapper = styled.div`
101126
font-family: "Nunito Sans", "Helvetica Neue", Helvetica, Arial, sans-serif;
102127
color: #333;
103128
display: inline-block;
104129
vertical-align: top;
105130
width: 265px;
106131
`;
107132

108-
const CommentItemDiv = styled.div`
133+
const CommentItem = styled.div`
109134
font-size: 12px;
110135
line-height: 14px;
111136
clear: both;
@@ -122,7 +147,7 @@ const CommentItemDiv = styled.div`
122147
+ font-weight: bold;
123148
`;
124149

125-
const AvatarDiv = styled.div`
150+
const Avatar = styled.div`
126151
float: left;
127152
position: relative;
128153
overflow: hidden;
@@ -143,22 +168,30 @@ const AvatarImg = styled.img`
143168
background: #999;
144169
`;
145170

146-
const MessageDiv = styled.div`
171+
const Message = styled.div`
147172
overflow: hidden;
148173
padding-top: 10px;
149174
padding-right: 20px;
150175
`;
151176

152-
const AuthorSpan = styled.span`
177+
const Author = styled.span`
153178
font-weight: bold;
154179
`;
155-
const TextSpan = styled.span``;
156180

157-
const GlobalStyle = createGlobalStyle`
158-
@import url('https://fonts.googleapis.com/css?family=Nunito+Sans:400,400i,800');
159-
`;
181+
const CommentText = styled.span``;
160182

161-
export default function CommentList({ loading, comments, totalCount }) {
183+
const GlobalStyle = createGlobalStyle`
184+
@import url('https://fonts.googleapis.com/css?family=Nunito+Sans:400,400i,800');
185+
`;
186+
187+
/**
188+
* The Commentlist component should display the comments from the user.
189+
*/
190+
export default function CommentList({
191+
loading = false,
192+
comments = [],
193+
totalCount = 10,
194+
}: CommentListProps) {
162195
if (loading) {
163196
return <div>loading</div>;
164197
}
@@ -167,52 +200,22 @@ export default function CommentList({ loading, comments, totalCount }) {
167200
}
168201
return (
169202
<>
170-
<GlobalStyle/>
171-
<CommentListDiv>
172-
{comments.map(({ text, author: { name, avatar } }) => (
173-
<CommentItemDiv key={`comment_${name}`}>
174-
<AvatarDiv>
175-
<AvatarImg src={avatar} />
176-
</AvatarDiv>
177-
<MessageDiv>
178-
<AuthorSpan>{name}</AuthorSpan> <TextSpan>{text}</TextSpan>
179-
</MessageDiv>
180-
</CommentItemDiv>
181-
))}
182-
</CommentListDiv>
203+
<GlobalStyle />
204+
<CommentListWrapper>
205+
{comments.map(({ text, author: { name, avatar } }) => (
206+
<CommentItem key={`comment_${name}`}>
207+
<Avatar>
208+
<AvatarImg src={avatar} />
209+
</Avatar>
210+
<Message>
211+
<Author>{name}</Author> <CommentText>{text}</CommentText>
212+
</Message>
213+
</CommentItem>
214+
))}
215+
</CommentListWrapper>
183216
</>
184217
);
185218
}
186-
187-
CommentList.propTypes = {
188-
/**
189-
* Is the component in the loading state
190-
*/
191-
loading: PropTypes.bool,
192-
193-
/**
194-
* Total number of comments
195-
*/
196-
totalCount: PropTypes.number,
197-
/**
198-
* List of comments
199-
*/
200-
comments: PropTypes.arrayOf(
201-
PropTypes.shape({
202-
text: PropTypes.string,
203-
author: PropTypes.shape({
204-
name: PropTypes.string,
205-
avatar: PropTypes.string,
206-
}),
207-
})
208-
),
209-
};
210-
211-
CommentList.defaultProps = {
212-
loading: false,
213-
totalCount: 10,
214-
comments: [],
215-
};
216219
```
217220

218221
Commit the change, push it to the repo and run Chromatic:

content/visual-testing-handbook/react/en/conclusion.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,13 @@ This guide introduced you to the basics of visual testing. Tom and I hope you ca
1717
If you've been following along, your repository and deployed Storybook should look like this:
1818

1919
- 📕 [**GitHub repository**](https://github.com/chromaui/learnstorybook-visual-testing-code)
20-
- 🌎 [**Deployed Storybook**](https://6070d9288779ab00214a9831-edgtavyhhd.chromatic.com/?path=/story/commentlist--paginated)
20+
- 🌎 [**Deployed Storybook**](https://6070d9288779ab00214a9831-pqbtsnhqei.chromatic.com/)
2121

2222
## More resources
2323

2424
Want to dive deeper? Here are some additional helpful resources:
2525

26-
- [**Official Storybook docs**](https://storybook.js.org/docs/react/get-started/why-storybook) has API documentation, examples, and the addon gallery.
26+
- [**Official Storybook docs**](https://storybook.js.org/docs/get-started/why-storybook) has API documentation, examples, and the addon gallery.
2727

2828
- [**How to actually test UIs**](https://storybook.js.org/blog/how-to-actually-test-uis/) is a summary of practical UI testing strategies from Shopify, Adobe, Twilio, and more.
2929

0 commit comments

Comments
 (0)