Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
67 changes: 67 additions & 0 deletions .enzyme/lingui-helper.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
import React from 'react'
import { shape, object } from 'prop-types'
import { mount, shallow } from 'enzyme'
import { I18nProvider } from '@lingui/react'

// Create the I18nProvider to retrieve context for wrapping around.
const language = 'en'
const intlProvider = new I18nProvider({
language,
catalogs: {
[language]: {}
}
}, {})

const {
linguiPublisher: {
i18n: originalI18n
}
} = intlProvider.getChildContext()

// You customize the i18n object here:
const i18n = {
...originalI18n,
_: key => key // provide _ macro, for just passing down the key
}

/**
* When using Lingui `withI18n` on components, props.i18n is required.
*/
function nodeWithI18nProp(node) {
return React.cloneElement(node, { i18n })
}

/*
* Methods to use
*/
export function shallowWithIntl(node, { context } = {}) {
return shallow(
nodeWithI18nProp(node),
{
context: Object.assign({}, context, { i18n })
}
)
}

export function mountWithIntl(node, { context, childContextTypes } = {}) {
const newContext = Object.assign({}, context, { linguiPublisher: { i18n } })
/*
* I18nProvider sets the linguiPublisher in the context for withI18n to get
* the i18n object from.
*/
const newChildContextTypes = Object.assign({},
{
linguiPublisher: shape({
i18n: object.isRequired
}).isRequired
},
childContextTypes
)
return mount(
nodeWithI18nProp(node),
{
context: newContext,
childContextTypes: newChildContextTypes
}
)
}
1 change: 1 addition & 0 deletions .idea/webResources.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

37 changes: 37 additions & 0 deletions .jest/register-context.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,40 @@ jest.mock('../src/utils/sprite/spriteUI', () => ({
jest.mock('../src/utils/sprite/spriteAssets', () => ({
keys: () => [],
}))

jest.mock('../src/utils/sprite/coloredIconsUI', () => ({
keys: () => [],
}))

jest.mock('../src/public/assets/pic_transactions_112.svg', () => 'pic_transactions_112.svg')

jest.mock('i18n/lingui', () => ({
i18n: {
_: (
key,
params,
data,
) => {
if (!data) {
return key
}

const source = data.defaults

if (!params) {
return source
}

return Object.keys(params).reduce((
result,
param,
) => {
if (result.indexOf(param) === -1) {
return result
}

return result.replace(`{${param}}`, params[param])
}, source)
}
}
}))
26 changes: 26 additions & 0 deletions Jenkinsfile
Original file line number Diff line number Diff line change
@@ -1,5 +1,31 @@
builder(
jUnitReportsPath: 'reports/unit-tests',
coverageReportsPath: 'reports/coverage',
buildTasks: [
[
name: 'Linters',
type: 'lint',
method: 'inside',
buildStage: 'build',
command: [
// 'npm run lint:css', // TODO: enable CSS linting
'npm run lint:js',
],
],
[
name: 'Tests',
type: 'test',
method: 'inside',
buildStage: 'build',
jUnitPath: '/usr/src/app/reports/unit-tests',
coveragePath: '/usr/src/app/reports/coverage',
Comment on lines +20 to +21
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@soar Should it be /usr/src/app? Looks more like just /app.

environment: [
NODE_ENV: 'production',
],
command: [
'npm run test:unit',
],
],
[
name: 'Nginx Checks',
type: 'test',
Expand Down
4 changes: 2 additions & 2 deletions jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ module.exports = {
statements: 0,
},
},
coverageDirectory: '<rootDir>/reports/unit-tests/coverage',
coverageDirectory: '<rootDir>/reports/coverage',
coverageReporters: [
'lcov',
],
Expand All @@ -25,7 +25,7 @@ module.exports = {
'[/\\\\]node_modules[/\\\\](?!lodash-es).+\\.(js|jsx)$',
],
moduleFileExtensions: ['js', 'jsx'],
moduleDirectories: ['src', 'node_modules'],
moduleDirectories: ['<rootDir>', 'src', 'node_modules'],
moduleNameMapper: {
'\\.(css|scss)$': 'identity-obj-proxy',
'^lodash-es$': 'lodash',
Expand Down
Loading