-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #35 from leomiranda/aula04modulo04
test(jest): create tests
- Loading branch information
Showing
12 changed files
with
2,004 additions
and
71 deletions.
There are no files selected for viewing
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 |
---|---|---|
@@ -0,0 +1,11 @@ | ||
// Jest Snapshot v1, https://goo.gl/fbAQLP | ||
|
||
exports[`config/redirects renders all current redirects 1`] = ` | ||
Array [ | ||
Object { | ||
"destination": "/app/login/", | ||
"permanent": true, | ||
"source": "/login/", | ||
}, | ||
] | ||
`; |
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 |
---|---|---|
@@ -0,0 +1,7 @@ | ||
import redirects from './redirects'; | ||
|
||
describe('config/redirects', () => { | ||
test('renders all current redirects', () => { | ||
expect(redirects).toMatchSnapshot(); | ||
}); | ||
}); |
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,9 @@ | ||
module.exports = { | ||
setupFilesAfterEnv: ['<rootDir>/jest.setup.js'], | ||
moduleDirectories: ['<rootDir>/node_modules', 'node_modules'], | ||
testPathIgnorePatterns: [ | ||
'<rootDir>/.next/', | ||
'<rootDir>/cypress/', | ||
'<rootDir>/dist/', | ||
], | ||
}; |
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 @@ | ||
// jest extensions |
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 was deleted.
Oops, something went wrong.
53 changes: 53 additions & 0 deletions
53
src/theme/utils/propToStyle/__snapshots__/propToStyle.test.js.snap
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,53 @@ | ||
// Jest Snapshot v1, https://goo.gl/fbAQLP | ||
|
||
exports[`propToStyle() when receives an argument with breakpoints renders only one breakpoint resolution 1`] = ` | ||
Array [ | ||
Array [ | ||
"@media screen and (min-width:", | ||
"0", | ||
"px){", | ||
"text-align: center;", | ||
";}", | ||
], | ||
] | ||
`; | ||
exports[`propToStyle() when receives an argument with breakpoints renders two or more breakpoint resolutions 1`] = ` | ||
Array [ | ||
Array [ | ||
"@media screen and (min-width:", | ||
"0", | ||
"px){", | ||
"text-align: center;", | ||
";}", | ||
], | ||
Array [ | ||
"@media screen and (min-width:", | ||
"480", | ||
"px){", | ||
"text-align: right;", | ||
";}", | ||
], | ||
Array [ | ||
"@media screen and (min-width:", | ||
"768", | ||
"px){", | ||
"text-align: right;", | ||
";}", | ||
], | ||
Array [ | ||
"@media screen and (min-width:", | ||
"992", | ||
"px){", | ||
"text-align: right;", | ||
";}", | ||
], | ||
Array [ | ||
"@media screen and (min-width:", | ||
"1200", | ||
"px){", | ||
"text-align: right;", | ||
";}", | ||
], | ||
] | ||
`; |
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,46 @@ | ||
import { breakpointsMedia } from '../breakpointsMedia'; | ||
|
||
export function propToStyle(propName) { | ||
return (props) => { | ||
const propValue = props[propName]; | ||
|
||
if (typeof propValue === 'string' || typeof propValue === 'number') { | ||
return { | ||
// textAlign: props.textAlign | ||
[propName]: propValue, | ||
}; | ||
} | ||
|
||
if (typeof propValue === 'object') { | ||
const breakpoints = {}; | ||
|
||
if (propValue.xs) breakpoints.xs = { [propName]: propValue.xs }; | ||
if (propValue.md) breakpoints.sm = { [propName]: propValue.md }; | ||
if (propValue.md) breakpoints.md = { [propName]: propValue.md }; | ||
if (propValue.md) breakpoints.lg = { [propName]: propValue.md }; | ||
if (propValue.md) breakpoints.xl = { [propName]: propValue.md }; | ||
|
||
return breakpointsMedia(breakpoints); | ||
|
||
// return breakpointsMedia({ | ||
// xs: { | ||
// [propName]: propValue.xs, | ||
// }, | ||
// sm: { | ||
// [propName]: propValue.sm, | ||
// }, | ||
// md: { | ||
// [propName]: propValue.md, | ||
// }, | ||
// lg: { | ||
// [propName]: propValue.lg, | ||
// }, | ||
// xl: { | ||
// [propName]: propValue.xl, | ||
// }, | ||
// }); | ||
} | ||
|
||
return {}; | ||
}; | ||
} |
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,39 @@ | ||
import { propToStyle } from './index'; | ||
|
||
describe('propToStyle()', () => { | ||
describe('when receives an simple argument', () => { | ||
test('and it is a string', () => { | ||
const propToStyleResult = propToStyle('textAlign'); | ||
// <Text textAlign="center" /> | ||
const componentProps = { textAlign: 'center' }; // string | ||
const styleResult = propToStyleResult(componentProps); | ||
expect(styleResult).toEqual({ textAlign: 'center' }); | ||
}); | ||
test('and it is a number', () => { | ||
const propToStyleResult = propToStyle('flex'); | ||
// <Text flex={1} /> | ||
const componentProps = { flex: 1 }; // number | ||
const styleResult = propToStyleResult(componentProps); | ||
expect(styleResult).toEqual({ flex: 1 }); | ||
}); | ||
}); | ||
|
||
describe('when receives an argument with breakpoints', () => { | ||
test('renders only one breakpoint resolution', () => { | ||
const propToStyleResult = propToStyle('textAlign'); | ||
// <Text textAlign="center" /> | ||
const componentProps = { textAlign: { xs: 'center' } }; // string | ||
const styleResult = propToStyleResult(componentProps); | ||
|
||
expect(styleResult).toMatchSnapshot(); | ||
}); | ||
test('renders two or more breakpoint resolutions', () => { | ||
const propToStyleResult = propToStyle('textAlign'); | ||
// <Text textAlign="center" /> | ||
const componentProps = { textAlign: { xs: 'center', md: 'right' } }; // string | ||
const styleResult = propToStyleResult(componentProps); | ||
|
||
expect(styleResult).toMatchSnapshot(); | ||
}); | ||
}); | ||
}); |
Oops, something went wrong.
6efaf3c
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Successfully deployed to the following URLs: