Skip to content

Commit e892825

Browse files
authored
ci: add step for testing the app (#5)
1 parent 77d96a0 commit e892825

File tree

8 files changed

+120
-12
lines changed

8 files changed

+120
-12
lines changed

.circleci/config.yml

+24
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,29 @@ jobs:
7373
name: Deploy
7474
command: gcloud app deploy
7575
working_directory: api/build
76+
app_build:
77+
docker:
78+
- image: circleci/node:14.15.0
79+
steps:
80+
- checkout
81+
- restore_cache:
82+
key: app-dependency-cache-{{ checksum "app/package-lock.json" }}
83+
- run:
84+
name: Install dependencies
85+
command: npm install
86+
working_directory: app
87+
- save_cache:
88+
key: app-dependency-cache-{{ checksum "app/package-lock.json" }}
89+
paths:
90+
- ./app/node_modules
91+
- run:
92+
name: Test
93+
command: npm run test -- --ci --reporters=default --reporters=jest-junit --runInBand
94+
working_directory: app
95+
environment:
96+
- JEST_JUNIT_OUTPUT_DIR: ./test-results
97+
- store_test_results:
98+
path: ./app/test-results
7699
workflows:
77100
build:
78101
jobs:
@@ -91,3 +114,4 @@ workflows:
91114
branches:
92115
only:
93116
- main
117+
- app_build

app/__mocks__/svgrMock.ts

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export default 'div';

app/__tests__/buttons/BaseButton.tsx

+56
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
import { render, RenderResult, screen } from '@testing-library/preact';
2+
import React, { HTMLAttributes } from 'react';
3+
import BaseButton, {
4+
BaseButtonProps,
5+
} from '../../components/buttons/BaseButton';
6+
import { primaryStyle } from '../../components/buttons/PrimaryButton';
7+
import ShareIcon from '../../icons/share.svg';
8+
9+
const renderComponent = <
10+
C extends HTMLElement = HTMLButtonElement,
11+
P = HTMLAttributes<C>
12+
>(
13+
props: Partial<BaseButtonProps & P> = {},
14+
): RenderResult => {
15+
return render(<BaseButton {...primaryStyle()} {...props} />);
16+
};
17+
18+
it('should render children', async () => {
19+
renderComponent({ children: 'Button' });
20+
expect(await screen.findByText('Button')).toBeInTheDocument();
21+
});
22+
23+
it('should render icon', async () => {
24+
renderComponent({ icon: <ShareIcon data-testid="icon" /> });
25+
expect(await screen.findByTestId('icon')).toBeInTheDocument();
26+
});
27+
28+
it('should render right icon', async () => {
29+
renderComponent({ rightIcon: <ShareIcon data-testid="icon" /> });
30+
expect(await screen.findByTestId('icon')).toBeInTheDocument();
31+
});
32+
33+
it('should render loader and set aria-busy when loading', async () => {
34+
renderComponent({ children: 'Button', loading: true });
35+
expect(await screen.findByText('Button')).toHaveStyle({
36+
visibility: 'hidden',
37+
});
38+
expect(await screen.findByRole('button')).toHaveAttribute(
39+
'aria-busy',
40+
'true',
41+
);
42+
expect(await screen.findByTestId('buttonLoader')).toBeInTheDocument();
43+
});
44+
45+
it('should set aria-pressed when pressed is true', async () => {
46+
renderComponent({ children: 'Button', pressed: true });
47+
expect(await screen.findByRole('button')).toHaveAttribute(
48+
'aria-pressed',
49+
'true',
50+
);
51+
});
52+
53+
it('should render the button as an anchor element', async () => {
54+
renderComponent({ children: 'Button', tag: 'a', href: 'https://daily.dev' });
55+
expect(await screen.findByRole('link')).toBeInTheDocument();
56+
});

app/icons/share.svg

+12
Loading

app/icons/twitter_color.svg

+1
Loading

app/jest.config.js

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
module.exports = {
2+
roots: ['<rootDir>'],
3+
testRegex: '(/__tests__/.*|(\\.|/)(test|spec))\\.tsx?$',
4+
setupFilesAfterEnv: ['./__tests__/setup.ts'],
5+
testPathIgnorePatterns: [
6+
'./.next/',
7+
'./node_modules/',
8+
'<rootDir>/__tests__/setup.ts',
9+
],
10+
moduleFileExtensions: ['ts', 'tsx', 'js', 'jsx', 'json', 'node'],
11+
moduleNameMapper: {
12+
'\\.svg': '<rootDir>/__mocks__/svgrMock.ts',
13+
},
14+
snapshotSerializers: ['@emotion/jest/serializer'],
15+
};

app/pages/index.tsx

+11-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import React, { ReactElement } from 'react';
22
import Link from 'next/link';
33
import styled from '@emotion/styled';
4-
import { typoTitle1 } from '../styles/typography';
4+
import { typoFootnote, typoTitle1 } from '../styles/typography';
55
import rem from '../macros/rem.macro';
66
import PrimaryButton from '../components/buttons/PrimaryButton';
77
import SecondaryButton from '../components/buttons/SecondaryButton';
@@ -19,6 +19,13 @@ const Title = styled.h1`
1919
${typoTitle1}
2020
`;
2121

22+
const Credit = styled.a`
23+
align-self: center;
24+
color: var(--theme-label-tertiary);
25+
text-decoration: underline;
26+
${typoFootnote}
27+
`;
28+
2229
export default function Index(): ReactElement {
2330
return (
2431
<Main>
@@ -33,6 +40,9 @@ export default function Index(): ReactElement {
3340
Leaderboard please... 🍿
3441
</SecondaryButton>
3542
</Link>
43+
<Credit href="https://app.daily.dev/?ref=buzzwordquiz">
44+
Made with ❤️ by daily.dev
45+
</Credit>
3646
</Main>
3747
);
3848
}

app/tsconfig.jest.json

-11
This file was deleted.

0 commit comments

Comments
 (0)