Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix lint problems + Fix tests #14

Merged
merged 4 commits into from
May 13, 2020
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 3 additions & 0 deletions .eslintignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
node_modules/
coverage/
*.snap.ts
9 changes: 9 additions & 0 deletions .eslintrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"extends": "vtex",
"root": true,
"env": {
"node": true,
"es6": true,
"jest": true
}
}
1 change: 1 addition & 0 deletions .prettierignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
*.md
7 changes: 1 addition & 6 deletions .prettierrc
Original file line number Diff line number Diff line change
@@ -1,6 +1 @@
{
"semi": false,
"singleQuote": true,
"trailingComma": "es5",
"jsxBracketSameLine": true
}
"@vtex/prettier-config"
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,14 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/)
and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html).

## [Unreleased]
### Added
- Eslint configuration.

### Fixed
- Test errors.

### Security
- Bump dependencies versions.

## [0.3.4] - 2020-04-15

Expand Down
39 changes: 24 additions & 15 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,24 +1,33 @@
{
"version": "0.0.0",
"devDependencies": {
"@vtex/intl-equalizer": "^2.3.0",
"husky": "^2.4.1"
},
"name": "store-form",
"private": true,
"license": "UNLICENSED",
"scripts": {
"lint": "cd ./react && yarn lint",
"test": "cd ./react && yarn test --passWithNoTests",
"lint:locales": "intl-equalizer",
"locales:fix": "intl-equalizer --fix",
"verify": "yarn lint && yarn lint:locales && yarn test"
"lint": "eslint --ext js,jsx,ts,tsx .",
"format": "prettier --write \"**/*.{ts,tsx,js,jsx,json}\""
},
"husky": {
"hooks": {
"pre-commit": "yarn lint && yarn lint:locales && yarn locales:fix",
"pre-push": "yarn verify"
"pre-commit": "lint-staged"
}
},
"intl-equalizer": {
"referenceLocale": "en",
"localeDirectory": "messages"
"lint-staged": {
"*.{ts,js,tsx,jsx}": [
"eslint --fix",
"prettier --write"
],
"*.{json,graphql,gql}": [
"prettier --write"
]
},
"devDependencies": {
"@vtex/prettier-config": "^0.1.3",
"eslint": "^6.8.0",
"eslint-config-vtex": "^12.2.1",
"eslint-config-vtex-react": "^6.2.1",
"husky": "^4.2.0",
"lint-staged": "^10.0.2",
"prettier": "^1.19.1",
"typescript": "^3.8.3"
}
}
8 changes: 0 additions & 8 deletions react/.eslintrc

This file was deleted.

56 changes: 29 additions & 27 deletions react/__tests__/Form.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,34 +6,36 @@ import FormInputCheckbox from '../FormInputCheckbox'
import FormText from '../FormInputText'
import FormFieldGroup from '../FormFieldGroup'

test('should render full schema', () => {
const { getAllByText } = render(<Form entity="asdf" schema="asdf" />)
describe('Form', () => {
it('should render full schema', () => {
const { getAllByText } = render(<Form entity="asdf" schema="asdf" />)

expect(getAllByText('First Name')[0]).toBeDefined()
expect(getAllByText('Last Name')[0]).toBeDefined()
expect(getAllByText('Age')[0]).toBeDefined()
expect(getAllByText('Your height in meters')[0]).toBeDefined()
expect(getAllByText('Email address')[0]).toBeDefined()
expect(getAllByText('Street Type')[0]).toBeDefined()
expect(getAllByText('Address')[0]).toBeDefined()
expect(getAllByText('Street Number')[0]).toBeDefined()
expect(getAllByText('Do you agree with the terms?')[0]).toBeDefined()
})
expect(getAllByText('First Name')[0]).toBeDefined()
expect(getAllByText('Last Name')[0]).toBeDefined()
expect(getAllByText('Age')[0]).toBeDefined()
expect(getAllByText('Your height in meters')[0]).toBeDefined()
expect(getAllByText('Email address')[0]).toBeDefined()
expect(getAllByText('Street Type')[0]).toBeDefined()
expect(getAllByText('Address')[0]).toBeDefined()
expect(getAllByText('Street Number')[0]).toBeDefined()
expect(getAllByText('Do you agree with the terms?')[0]).toBeDefined()
})

test('should render partial schema', () => {
const { getAllByText } = render(
<Form entity="asdf" schema="asdf">
<FormText pointer="#/properties/firstName" />
<FormText pointer="#/properties/lastName" />
<FormFieldGroup pointer="#/properties/address" />
<FormInputCheckbox pointer="#/properties/agreement" />
</Form>
)
it('should render partial schema', () => {
const { getAllByText } = render(
<Form entity="asdf" schema="asdf">
<FormText pointer="#/properties/firstName" />
<FormText pointer="#/properties/lastName" />
<FormFieldGroup pointer="#/properties/address" />
<FormInputCheckbox pointer="#/properties/agreement" />
</Form>
)

expect(getAllByText('First Name')[0]).toBeDefined()
expect(getAllByText('Last Name')[0]).toBeDefined()
expect(getAllByText('Street Type')[0]).toBeDefined()
expect(getAllByText('Address')[0]).toBeDefined()
expect(getAllByText('Street Number')[0]).toBeDefined()
expect(getAllByText('Do you agree with the terms?')[0]).toBeDefined()
expect(getAllByText('First Name')[0]).toBeDefined()
expect(getAllByText('Last Name')[0]).toBeDefined()
expect(getAllByText('Street Type')[0]).toBeDefined()
expect(getAllByText('Address')[0]).toBeDefined()
expect(getAllByText('Street Number')[0]).toBeDefined()
expect(getAllByText('Do you agree with the terms?')[0]).toBeDefined()
})
})
4 changes: 1 addition & 3 deletions react/components/Checkbox.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,12 @@ export const Checkbox: FC<{
{...checkboxObject.getItemInputProps(0)}
label={label}
required={checkboxObject.isRequired}
checked={Boolean(checked)}
value="true"
{...(checked ? { checked: true } : { checked: false })}
onChange={() => {
const pointer = checkboxObject.pointer

checkboxObject.formContext.setValue(pointer, !checked)
}}
checked={Boolean(checked)}
/>
</>
)
Expand Down
19 changes: 7 additions & 12 deletions react/package.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
{
"version": "0.3.4",
"scripts": {
"lint": "tsc --noEmit && eslint --quiet --fix --ext ts,tsx .",
"test": "vtex-test-tools test",
Expand All @@ -10,31 +11,25 @@
"react-apollo": "^3.1.3",
"react-dom": "^16.8.6",
"react-hook-form-jsonschema": "0.2.0-beta.11",
"react-intl": "3.9.1"
"react-intl": "^4.5.3"
},
"devDependencies": {
"@apollo/react-testing": "^3.1.3",
"@types/graphql": "14.0.7",
"@types/jest": "^25.1.1",
"@types/node": "^13.5.3",
"@types/react": "^16.9.19",
"@types/react-intl": "^3.0.0",
"@vtex/styleguide": "^9.108.2",
"@vtex/test-tools": "^3.0.1",
"@vtex/styleguide": "^9.116.0",
"@vtex/test-tools": "^3.1.0",
"@vtex/tsconfig": "^0.2.0",
"apollo-cache-inmemory": "^1.6.5",
"eslint": "5.x",
"eslint-config-vtex-react": "^5.1.0",
"graphql": "^14.6.0",
"mutationobserver-shim": "^0.3.3",
"prettier": "^1.18.2",
"prop-types": "^15.7.2",
"typescript": "3.7.3"
"mutationobserver-shim": "^0.3.5",
"typescript": "3.8.3"
},
"jest": {
"setupFilesAfterEnv": [
"./setupTest.js"
]
},
"version": "0.3.4"
}
}
10 changes: 10 additions & 0 deletions react/setupTest.js
Original file line number Diff line number Diff line change
@@ -1 +1,11 @@
require('mutationobserver-shim')

window.matchMedia =
window.matchMedia ||
function() {
return {
matches: false,
addListener: function() {},
removeListener: function() {},
}
}
27 changes: 23 additions & 4 deletions react/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,9 +1,28 @@
{
"extends": "@vtex/tsconfig",
"compilerOptions": {
"noEmitOnError": false,
"alwaysStrict": true,
"esModuleInterop": true,
"jsx": "react",
"lib": ["es2017", "dom", "es2018.promise"],
"module": "esnext",
"moduleResolution": "node",
"noImplicitAny": true,
"noImplicitReturns": true,
"noImplicitThis": true,
"noUnusedLocals": true,
"noUnusedParameters": true,
"skipLibCheck": true,
"sourceMap": true,
"strictFunctionTypes": true,
"strictNullChecks": true,
"strictPropertyInitialization": true,
"target": "es2017",
"typeRoots": ["node_modules/@types"],
"types": ["node", "jest", "graphql"]
"types": ["node", "jest"]
},
"include": ["./typings/*.d.ts", "./**/*.tsx", "./**/*.ts"]
"exclude": ["node_modules"],
"include": ["./typings/*.d.ts", "./**/*.tsx", "./**/*.ts"],
"typeAcquisition": {
"enable": false
}
}