mirror of
https://github.com/ansible/awx.git
synced 2026-01-24 16:01:20 -03:30
WIP upgrade react & react-router
This commit is contained in:
parent
cbed525547
commit
20c24eb275
105
awx/ui_next/package-lock.json
generated
105
awx/ui_next/package-lock.json
generated
@ -11596,6 +11596,16 @@
|
||||
"dom-walk": "^0.1.0"
|
||||
}
|
||||
},
|
||||
"mini-create-react-context": {
|
||||
"version": "0.3.2",
|
||||
"resolved": "https://registry.npmjs.org/mini-create-react-context/-/mini-create-react-context-0.3.2.tgz",
|
||||
"integrity": "sha512-2v+OeetEyliMt5VHMXsBhABoJ0/M4RCe7fatd/fBy6SMiKazUSEt3gxxypfnk2SHMkdBYvorHRoQxuGoiwbzAw==",
|
||||
"requires": {
|
||||
"@babel/runtime": "^7.4.0",
|
||||
"gud": "^1.0.0",
|
||||
"tiny-warning": "^1.0.2"
|
||||
}
|
||||
},
|
||||
"minimalistic-assert": {
|
||||
"version": "1.0.1",
|
||||
"resolved": "https://registry.npmjs.org/minimalistic-assert/-/minimalistic-assert-1.0.1.tgz",
|
||||
@ -13346,25 +13356,13 @@
|
||||
}
|
||||
},
|
||||
"react": {
|
||||
"version": "16.8.6",
|
||||
"resolved": "https://registry.npmjs.org/react/-/react-16.8.6.tgz",
|
||||
"integrity": "sha512-pC0uMkhLaHm11ZSJULfOBqV4tIZkx87ZLvbbQYunNixAAvjnC+snJCg0XQXn9VIsttVsbZP/H/ewzgsd5fxKXw==",
|
||||
"version": "16.10.1",
|
||||
"resolved": "https://registry.npmjs.org/react/-/react-16.10.1.tgz",
|
||||
"integrity": "sha512-2bisHwMhxQ3XQz4LiJJwG3360pY965pTl/MRrZYxIBKVj4fOHoDs5aZAkYXGxDRO1Li+SyjTAilQEbOmtQJHzA==",
|
||||
"requires": {
|
||||
"loose-envify": "^1.1.0",
|
||||
"object-assign": "^4.1.1",
|
||||
"prop-types": "^15.6.2",
|
||||
"scheduler": "^0.13.6"
|
||||
},
|
||||
"dependencies": {
|
||||
"scheduler": {
|
||||
"version": "0.13.6",
|
||||
"resolved": "https://registry.npmjs.org/scheduler/-/scheduler-0.13.6.tgz",
|
||||
"integrity": "sha512-IWnObHt413ucAYKsD9J1QShUKkbKLQQHdxRyw73sw4FN26iWr3DY/H34xGPe4nmL1DwXyWmSWmMrA9TfQbE/XQ==",
|
||||
"requires": {
|
||||
"loose-envify": "^1.1.0",
|
||||
"object-assign": "^4.1.1"
|
||||
}
|
||||
}
|
||||
"prop-types": "^15.6.2"
|
||||
}
|
||||
},
|
||||
"react-codemirror2": {
|
||||
@ -13373,20 +13371,20 @@
|
||||
"integrity": "sha512-D7y9qZ05FbUh9blqECaJMdDwKluQiO3A9xB+fssd5jKM7YAXucRuEOlX32mJQumUvHUkHRHqXIPBjm6g0FW0Ag=="
|
||||
},
|
||||
"react-dom": {
|
||||
"version": "16.8.6",
|
||||
"resolved": "https://registry.npmjs.org/react-dom/-/react-dom-16.8.6.tgz",
|
||||
"integrity": "sha512-1nL7PIq9LTL3fthPqwkvr2zY7phIPjYrT0jp4HjyEQrEROnw4dG41VVwi/wfoCneoleqrNX7iAD+pXebJZwrwA==",
|
||||
"version": "16.10.1",
|
||||
"resolved": "https://registry.npmjs.org/react-dom/-/react-dom-16.10.1.tgz",
|
||||
"integrity": "sha512-SmM4ZW0uug0rn95U8uqr52I7UdNf6wdGLeXDmNLfg3y5q5H9eAbdjF5ubQc3bjDyRrvdAB2IKG7X0GzSpnn5Mg==",
|
||||
"requires": {
|
||||
"loose-envify": "^1.1.0",
|
||||
"object-assign": "^4.1.1",
|
||||
"prop-types": "^15.6.2",
|
||||
"scheduler": "^0.13.6"
|
||||
"scheduler": "^0.16.1"
|
||||
},
|
||||
"dependencies": {
|
||||
"scheduler": {
|
||||
"version": "0.13.6",
|
||||
"resolved": "https://registry.npmjs.org/scheduler/-/scheduler-0.13.6.tgz",
|
||||
"integrity": "sha512-IWnObHt413ucAYKsD9J1QShUKkbKLQQHdxRyw73sw4FN26iWr3DY/H34xGPe4nmL1DwXyWmSWmMrA9TfQbE/XQ==",
|
||||
"version": "0.16.1",
|
||||
"resolved": "https://registry.npmjs.org/scheduler/-/scheduler-0.16.1.tgz",
|
||||
"integrity": "sha512-MIuie7SgsqMYOdCXVFZa8SKoNorJZUWHW8dPgto7uEHn1lX3fg2Gu0TzgK8USj76uxV7vB5eRMnZs/cdEHg+cg==",
|
||||
"requires": {
|
||||
"loose-envify": "^1.1.0",
|
||||
"object-assign": "^4.1.1"
|
||||
@ -13424,30 +13422,51 @@
|
||||
"integrity": "sha512-fBASbA6LnOU9dOU2eW7aQ8xmYBSXUIWr+UmF9b1efZBazGNO+rcXT/icdKnYm2pTwcRylVUYwW7H1PHfLekVzA=="
|
||||
},
|
||||
"react-router": {
|
||||
"version": "4.3.1",
|
||||
"resolved": "https://registry.npmjs.org/react-router/-/react-router-4.3.1.tgz",
|
||||
"integrity": "sha512-yrvL8AogDh2X42Dt9iknk4wF4V8bWREPirFfS9gLU1huk6qK41sg7Z/1S81jjTrGHxa3B8R3J6xIkDAA6CVarg==",
|
||||
"version": "5.1.2",
|
||||
"resolved": "https://registry.npmjs.org/react-router/-/react-router-5.1.2.tgz",
|
||||
"integrity": "sha512-yjEuMFy1ONK246B+rsa0cUam5OeAQ8pyclRDgpxuSCrAlJ1qN9uZ5IgyKC7gQg0w8OM50NXHEegPh/ks9YuR2A==",
|
||||
"requires": {
|
||||
"history": "^4.7.2",
|
||||
"hoist-non-react-statics": "^2.5.0",
|
||||
"invariant": "^2.2.4",
|
||||
"@babel/runtime": "^7.1.2",
|
||||
"history": "^4.9.0",
|
||||
"hoist-non-react-statics": "^3.1.0",
|
||||
"loose-envify": "^1.3.1",
|
||||
"mini-create-react-context": "^0.3.0",
|
||||
"path-to-regexp": "^1.7.0",
|
||||
"prop-types": "^15.6.1",
|
||||
"warning": "^4.0.1"
|
||||
"prop-types": "^15.6.2",
|
||||
"react-is": "^16.6.0",
|
||||
"tiny-invariant": "^1.0.2",
|
||||
"tiny-warning": "^1.0.0"
|
||||
},
|
||||
"dependencies": {
|
||||
"hoist-non-react-statics": {
|
||||
"version": "3.3.0",
|
||||
"resolved": "https://registry.npmjs.org/hoist-non-react-statics/-/hoist-non-react-statics-3.3.0.tgz",
|
||||
"integrity": "sha512-0XsbTXxgiaCDYDIWFcwkmerZPSwywfUqYmwT4jzewKTQSWoE6FCMoUVOeBJWK3E/CrWbxRG3m5GzY4lnIwGRBA==",
|
||||
"requires": {
|
||||
"react-is": "^16.7.0"
|
||||
},
|
||||
"dependencies": {
|
||||
"react-is": {
|
||||
"version": "16.10.1",
|
||||
"resolved": "https://registry.npmjs.org/react-is/-/react-is-16.10.1.tgz",
|
||||
"integrity": "sha512-BXUMf9sIOPXXZWqr7+c5SeOKJykyVr2u0UDzEf4LNGc6taGkQe1A9DFD07umCIXz45RLr9oAAwZbAJ0Pkknfaw=="
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"react-router-dom": {
|
||||
"version": "4.3.1",
|
||||
"resolved": "https://registry.npmjs.org/react-router-dom/-/react-router-dom-4.3.1.tgz",
|
||||
"integrity": "sha512-c/MlywfxDdCp7EnB7YfPMOfMD3tOtIjrQlj/CKfNMBxdmpJP8xcz5P/UAFn3JbnQCNUxsHyVVqllF9LhgVyFCA==",
|
||||
"version": "5.1.2",
|
||||
"resolved": "https://registry.npmjs.org/react-router-dom/-/react-router-dom-5.1.2.tgz",
|
||||
"integrity": "sha512-7BPHAaIwWpZS074UKaw1FjVdZBSVWEk8IuDXdB+OkLb8vd/WRQIpA4ag9WQk61aEfQs47wHyjWUoUGGZxpQXew==",
|
||||
"requires": {
|
||||
"history": "^4.7.2",
|
||||
"invariant": "^2.2.4",
|
||||
"@babel/runtime": "^7.1.2",
|
||||
"history": "^4.9.0",
|
||||
"loose-envify": "^1.3.1",
|
||||
"prop-types": "^15.6.1",
|
||||
"react-router": "^4.3.1",
|
||||
"warning": "^4.0.1"
|
||||
"prop-types": "^15.6.2",
|
||||
"react-router": "5.1.2",
|
||||
"tiny-invariant": "^1.0.2",
|
||||
"tiny-warning": "^1.0.0"
|
||||
}
|
||||
},
|
||||
"react-test-renderer": {
|
||||
@ -16299,14 +16318,6 @@
|
||||
"makeerror": "1.0.x"
|
||||
}
|
||||
},
|
||||
"warning": {
|
||||
"version": "4.0.3",
|
||||
"resolved": "https://registry.npmjs.org/warning/-/warning-4.0.3.tgz",
|
||||
"integrity": "sha512-rpJyN222KWIvHJ/F53XSZv0Zl/accqHR8et1kpaMTD/fLCRxtV8iX8czMzY7sVZupTI3zcUTg8eycS2kNF9l6w==",
|
||||
"requires": {
|
||||
"loose-envify": "^1.0.0"
|
||||
}
|
||||
},
|
||||
"watchpack": {
|
||||
"version": "1.6.0",
|
||||
"resolved": "https://registry.npmjs.org/watchpack/-/watchpack-1.6.0.tgz",
|
||||
|
||||
@ -69,10 +69,10 @@
|
||||
"html-entities": "^1.2.1",
|
||||
"js-yaml": "^3.13.1",
|
||||
"prop-types": "^15.6.2",
|
||||
"react": "^16.8.6",
|
||||
"react": "^16.10.1",
|
||||
"react-codemirror2": "^6.0.0",
|
||||
"react-dom": "^16.8.6",
|
||||
"react-router-dom": "^4.3.1",
|
||||
"react-dom": "^16.10.1",
|
||||
"react-router-dom": "^5.1.2",
|
||||
"react-virtualized": "^9.21.1",
|
||||
"styled-components": "^4.2.0"
|
||||
}
|
||||
|
||||
@ -1,4 +1,5 @@
|
||||
import React from 'react';
|
||||
import { createMemoryHistory } from 'history';
|
||||
import { mountWithContexts } from '@testUtils/enzymeHelpers';
|
||||
import { sleep } from '@testUtils/testUtils';
|
||||
|
||||
@ -29,10 +30,11 @@ describe('LaunchButton', () => {
|
||||
);
|
||||
expect(wrapper).toHaveLength(1);
|
||||
});
|
||||
test('redirects to job after successful launch', async done => {
|
||||
const history = {
|
||||
push: jest.fn(),
|
||||
};
|
||||
|
||||
test('should redirect to job after successful launch', async () => {
|
||||
const history = createMemoryHistory({
|
||||
initialEntries: ['/jobs/9000'],
|
||||
});
|
||||
JobTemplatesAPI.launch.mockResolvedValue({
|
||||
data: {
|
||||
id: 9000,
|
||||
@ -51,10 +53,10 @@ describe('LaunchButton', () => {
|
||||
expect(JobTemplatesAPI.readLaunch).toHaveBeenCalledWith(1);
|
||||
await sleep(0);
|
||||
expect(JobTemplatesAPI.launch).toHaveBeenCalledWith(1);
|
||||
expect(history.push).toHaveBeenCalledWith('/jobs/9000');
|
||||
done();
|
||||
expect(history.location.pathname).toEqual('/jobs/9000');
|
||||
});
|
||||
test('displays error modal after unsuccessful launch', async done => {
|
||||
|
||||
test('displays error modal after unsuccessful launch', async () => {
|
||||
JobTemplatesAPI.launch.mockRejectedValue(
|
||||
new Error({
|
||||
response: {
|
||||
@ -79,6 +81,5 @@ describe('LaunchButton', () => {
|
||||
await sleep(0);
|
||||
wrapper.update();
|
||||
expect(wrapper.find('Modal').length).toBe(0);
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
@ -81,7 +81,9 @@ describe('<NotificationList />', () => {
|
||||
);
|
||||
await sleep(0);
|
||||
wrapper.update();
|
||||
expect(wrapper).toMatchSnapshot();
|
||||
const dataList = wrapper.find('PaginatedDataList');
|
||||
expect(dataList).toHaveLength(1);
|
||||
expect(dataList.prop('items')).toEqual(data.results);
|
||||
});
|
||||
|
||||
test('should render list fetched of items', async () => {
|
||||
|
||||
@ -159,9 +159,27 @@ exports[`<NotificationListItem canToggleNotifications /> initially renders succe
|
||||
},
|
||||
"displayName": "Styled(Link)",
|
||||
"foldedComponentIds": Array [],
|
||||
"propTypes": Object {
|
||||
"innerRef": [Function],
|
||||
"onClick": [Function],
|
||||
"replace": [Function],
|
||||
"target": [Function],
|
||||
"to": [Function],
|
||||
},
|
||||
"render": [Function],
|
||||
"styledComponentId": "sc-bdVaJa",
|
||||
"target": [Function],
|
||||
"target": Object {
|
||||
"$$typeof": Symbol(react.forward_ref),
|
||||
"displayName": "Link",
|
||||
"propTypes": Object {
|
||||
"innerRef": [Function],
|
||||
"onClick": [Function],
|
||||
"replace": [Function],
|
||||
"target": [Function],
|
||||
"to": [Function],
|
||||
},
|
||||
"render": [Function],
|
||||
},
|
||||
"toString": [Function],
|
||||
"warnTooManyClasses": [Function],
|
||||
"withComponent": [Function],
|
||||
@ -176,23 +194,29 @@ exports[`<NotificationListItem canToggleNotifications /> initially renders succe
|
||||
>
|
||||
<Link
|
||||
className="sc-bdVaJa eBseNd"
|
||||
replace={false}
|
||||
to={
|
||||
Object {
|
||||
"pathname": "/foo",
|
||||
}
|
||||
}
|
||||
>
|
||||
<a
|
||||
<LinkAnchor
|
||||
className="sc-bdVaJa eBseNd"
|
||||
onClick={[Function]}
|
||||
href="/foo"
|
||||
navigate={[Function]}
|
||||
>
|
||||
<b
|
||||
id="items-list-item-9000"
|
||||
<a
|
||||
className="sc-bdVaJa eBseNd"
|
||||
href="/foo"
|
||||
onClick={[Function]}
|
||||
>
|
||||
Foo
|
||||
</b>
|
||||
</a>
|
||||
<b
|
||||
id="items-list-item-9000"
|
||||
>
|
||||
Foo
|
||||
</b>
|
||||
</a>
|
||||
</LinkAnchor>
|
||||
</Link>
|
||||
</StyledComponent>
|
||||
</Styled(Link)>
|
||||
|
||||
@ -85,7 +85,7 @@ describe('<OrganizationAccess />', () => {
|
||||
const wrapper = mountWithContexts(
|
||||
<OrganizationAccess organization={organization} />
|
||||
);
|
||||
expect(wrapper.find('OrganizationAccess')).toMatchSnapshot();
|
||||
expect(wrapper.find('PaginatedDataList')).toHaveLength(1);
|
||||
});
|
||||
|
||||
test('should fetch and display access records on mount', async done => {
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@ -273,9 +273,27 @@ exports[`<OrganizationAccessItem /> initially renders succesfully 1`] = `
|
||||
},
|
||||
"displayName": "Styled(Link)",
|
||||
"foldedComponentIds": Array [],
|
||||
"propTypes": Object {
|
||||
"innerRef": [Function],
|
||||
"onClick": [Function],
|
||||
"replace": [Function],
|
||||
"target": [Function],
|
||||
"to": [Function],
|
||||
},
|
||||
"render": [Function],
|
||||
"styledComponentId": "sc-bdVaJa",
|
||||
"target": [Function],
|
||||
"target": Object {
|
||||
"$$typeof": Symbol(react.forward_ref),
|
||||
"displayName": "Link",
|
||||
"propTypes": Object {
|
||||
"innerRef": [Function],
|
||||
"onClick": [Function],
|
||||
"replace": [Function],
|
||||
"target": [Function],
|
||||
"to": [Function],
|
||||
},
|
||||
"render": [Function],
|
||||
},
|
||||
"toString": [Function],
|
||||
"warnTooManyClasses": [Function],
|
||||
"withComponent": [Function],
|
||||
@ -290,19 +308,25 @@ exports[`<OrganizationAccessItem /> initially renders succesfully 1`] = `
|
||||
>
|
||||
<Link
|
||||
className="sc-bdVaJa fqQVUT"
|
||||
replace={false}
|
||||
to={
|
||||
Object {
|
||||
"pathname": "/bar",
|
||||
}
|
||||
}
|
||||
>
|
||||
<a
|
||||
<LinkAnchor
|
||||
className="sc-bdVaJa fqQVUT"
|
||||
onClick={[Function]}
|
||||
href="/bar"
|
||||
navigate={[Function]}
|
||||
>
|
||||
jane
|
||||
</a>
|
||||
<a
|
||||
className="sc-bdVaJa fqQVUT"
|
||||
href="/bar"
|
||||
onClick={[Function]}
|
||||
>
|
||||
jane
|
||||
</a>
|
||||
</LinkAnchor>
|
||||
</Link>
|
||||
</StyledComponent>
|
||||
</Styled(Link)>
|
||||
|
||||
@ -50,14 +50,7 @@ describe('<JobTemplateDetail />', () => {
|
||||
jest.clearAllMocks();
|
||||
});
|
||||
|
||||
test('initially renders succesfully', () => {
|
||||
const wrapper = mountWithContexts(
|
||||
<JobTemplateDetail template={template} />
|
||||
);
|
||||
expect(wrapper).toMatchSnapshot();
|
||||
});
|
||||
|
||||
test('Can load with missing summary fields', async done => {
|
||||
test('Can load with missing summary fields', async () => {
|
||||
const mockTemplate = { ...template };
|
||||
mockTemplate.summary_fields = { user_capabilities: {} };
|
||||
|
||||
@ -69,8 +62,8 @@ describe('<JobTemplateDetail />', () => {
|
||||
'Detail[label="Description"]',
|
||||
el => el.length === 1
|
||||
);
|
||||
done();
|
||||
});
|
||||
|
||||
test('When component mounts API is called to get instance groups', async done => {
|
||||
const wrapper = mountWithContexts(
|
||||
<JobTemplateDetail template={template} />
|
||||
@ -89,6 +82,7 @@ describe('<JobTemplateDetail />', () => {
|
||||
expect(JobTemplatesAPI.readInstanceGroups).toHaveBeenCalledTimes(1);
|
||||
done();
|
||||
});
|
||||
|
||||
test('Edit button is absent when user does not have edit privilege', async done => {
|
||||
const regularUser = {
|
||||
forks: 1,
|
||||
|
||||
@ -1,194 +0,0 @@
|
||||
// Jest Snapshot v1, https://goo.gl/fbAQLP
|
||||
|
||||
exports[`<JobTemplateDetail /> initially renders succesfully 1`] = `
|
||||
<Wrap>
|
||||
<WithI18n
|
||||
template={
|
||||
Object {
|
||||
"forks": 1,
|
||||
"host_config_key": "ssh",
|
||||
"id": 1,
|
||||
"inventory": 1,
|
||||
"job_type": "run",
|
||||
"limit": "1",
|
||||
"name": "Temp 1",
|
||||
"playbook": "",
|
||||
"project": 7,
|
||||
"summary_fields": Object {
|
||||
"created_by": Object {
|
||||
"username": "Joe",
|
||||
},
|
||||
"credentials": Array [
|
||||
Object {
|
||||
"id": 1,
|
||||
"kind": "ssh",
|
||||
"name": "Credential 1",
|
||||
},
|
||||
Object {
|
||||
"id": 2,
|
||||
"kind": "awx",
|
||||
"name": "Credential 2",
|
||||
},
|
||||
],
|
||||
"inventory": Object {
|
||||
"name": "Inventory",
|
||||
},
|
||||
"modified_by": Object {
|
||||
"username": "Joe",
|
||||
},
|
||||
"project": Object {
|
||||
"name": "Project",
|
||||
},
|
||||
"user_capabilities": Object {
|
||||
"edit": true,
|
||||
},
|
||||
},
|
||||
"verbosity": 1,
|
||||
}
|
||||
}
|
||||
>
|
||||
<I18n
|
||||
update={true}
|
||||
withHash={true}
|
||||
>
|
||||
<withRouter(JobTemplateDetail)
|
||||
i18n={"/i18n/"}
|
||||
template={
|
||||
Object {
|
||||
"forks": 1,
|
||||
"host_config_key": "ssh",
|
||||
"id": 1,
|
||||
"inventory": 1,
|
||||
"job_type": "run",
|
||||
"limit": "1",
|
||||
"name": "Temp 1",
|
||||
"playbook": "",
|
||||
"project": 7,
|
||||
"summary_fields": Object {
|
||||
"created_by": Object {
|
||||
"username": "Joe",
|
||||
},
|
||||
"credentials": Array [
|
||||
Object {
|
||||
"id": 1,
|
||||
"kind": "ssh",
|
||||
"name": "Credential 1",
|
||||
},
|
||||
Object {
|
||||
"id": 2,
|
||||
"kind": "awx",
|
||||
"name": "Credential 2",
|
||||
},
|
||||
],
|
||||
"inventory": Object {
|
||||
"name": "Inventory",
|
||||
},
|
||||
"modified_by": Object {
|
||||
"username": "Joe",
|
||||
},
|
||||
"project": Object {
|
||||
"name": "Project",
|
||||
},
|
||||
"user_capabilities": Object {
|
||||
"edit": true,
|
||||
},
|
||||
},
|
||||
"verbosity": 1,
|
||||
}
|
||||
}
|
||||
>
|
||||
<Route>
|
||||
<JobTemplateDetail
|
||||
history={"/history/"}
|
||||
i18n={"/i18n/"}
|
||||
location={
|
||||
Object {
|
||||
"hash": "",
|
||||
"pathname": "",
|
||||
"search": "",
|
||||
"state": "",
|
||||
}
|
||||
}
|
||||
match={
|
||||
Object {
|
||||
"isExact": false,
|
||||
"params": Object {},
|
||||
"path": "",
|
||||
"url": "",
|
||||
}
|
||||
}
|
||||
template={
|
||||
Object {
|
||||
"forks": 1,
|
||||
"host_config_key": "ssh",
|
||||
"id": 1,
|
||||
"inventory": 1,
|
||||
"job_type": "run",
|
||||
"limit": "1",
|
||||
"name": "Temp 1",
|
||||
"playbook": "",
|
||||
"project": 7,
|
||||
"summary_fields": Object {
|
||||
"created_by": Object {
|
||||
"username": "Joe",
|
||||
},
|
||||
"credentials": Array [
|
||||
Object {
|
||||
"id": 1,
|
||||
"kind": "ssh",
|
||||
"name": "Credential 1",
|
||||
},
|
||||
Object {
|
||||
"id": 2,
|
||||
"kind": "awx",
|
||||
"name": "Credential 2",
|
||||
},
|
||||
],
|
||||
"inventory": Object {
|
||||
"name": "Inventory",
|
||||
},
|
||||
"modified_by": Object {
|
||||
"username": "Joe",
|
||||
},
|
||||
"project": Object {
|
||||
"name": "Project",
|
||||
},
|
||||
"user_capabilities": Object {
|
||||
"edit": true,
|
||||
},
|
||||
},
|
||||
"verbosity": 1,
|
||||
}
|
||||
}
|
||||
>
|
||||
<WithI18n>
|
||||
<I18n
|
||||
update={true}
|
||||
withHash={true}
|
||||
>
|
||||
<ContentLoading
|
||||
i18n={"/i18n/"}
|
||||
>
|
||||
<EmptyState>
|
||||
<div
|
||||
className="pf-c-empty-state styles.modifiers.lg"
|
||||
>
|
||||
<EmptyStateBody>
|
||||
<div
|
||||
className="pf-c-empty-state__body"
|
||||
>
|
||||
Loading...
|
||||
</div>
|
||||
</EmptyStateBody>
|
||||
</div>
|
||||
</EmptyState>
|
||||
</ContentLoading>
|
||||
</I18n>
|
||||
</WithI18n>
|
||||
</JobTemplateDetail>
|
||||
</Route>
|
||||
</withRouter(JobTemplateDetail)>
|
||||
</I18n>
|
||||
</WithI18n>
|
||||
</Wrap>
|
||||
`;
|
||||
@ -45,14 +45,19 @@ exports[`mountWithContexts injected I18nProvider should mount and render deeply
|
||||
exports[`mountWithContexts injected Router should mount and render 1`] = `
|
||||
<div>
|
||||
<Link
|
||||
replace={false}
|
||||
to="/"
|
||||
>
|
||||
<a
|
||||
onClick={[Function]}
|
||||
<LinkAnchor
|
||||
href="/"
|
||||
navigate={[Function]}
|
||||
>
|
||||
home
|
||||
</a>
|
||||
<a
|
||||
href="/"
|
||||
onClick={[Function]}
|
||||
>
|
||||
home
|
||||
</a>
|
||||
</LinkAnchor>
|
||||
</Link>
|
||||
</div>
|
||||
`;
|
||||
|
||||
@ -5,6 +5,7 @@
|
||||
import React from 'react';
|
||||
import { shape, object, string, arrayOf } from 'prop-types';
|
||||
import { mount, shallow } from 'enzyme';
|
||||
import { MemoryRouter, Router } from 'react-router-dom';
|
||||
import { I18nProvider } from '@lingui/react';
|
||||
import { ConfigProvider } from '../src/contexts/Config';
|
||||
|
||||
@ -13,13 +14,13 @@ const intlProvider = new I18nProvider(
|
||||
{
|
||||
language,
|
||||
catalogs: {
|
||||
[language]: {}
|
||||
}
|
||||
[language]: {},
|
||||
},
|
||||
},
|
||||
{}
|
||||
);
|
||||
const {
|
||||
linguiPublisher: { i18n: originalI18n }
|
||||
linguiPublisher: { i18n: originalI18n },
|
||||
} = intlProvider.getChildContext();
|
||||
|
||||
const defaultContexts = {
|
||||
@ -34,13 +35,14 @@ const defaultContexts = {
|
||||
ansible_version: null,
|
||||
custom_virtualenvs: [],
|
||||
version: null,
|
||||
toJSON: () => '/config/'
|
||||
toJSON: () => '/config/',
|
||||
},
|
||||
router: {
|
||||
history: {
|
||||
history_: {
|
||||
push: () => {},
|
||||
replace: () => {},
|
||||
createHref: () => {},
|
||||
listen: () => {},
|
||||
location: {
|
||||
hash: '',
|
||||
pathname: '',
|
||||
@ -61,33 +63,38 @@ const defaultContexts = {
|
||||
isExact: false,
|
||||
path: '',
|
||||
url: '',
|
||||
}
|
||||
},
|
||||
},
|
||||
toJSON: () => '/router/',
|
||||
},
|
||||
};
|
||||
|
||||
function wrapContexts (node, context) {
|
||||
const { config } = context;
|
||||
function wrapContexts(node, context) {
|
||||
const { config, router } = context;
|
||||
class Wrap extends React.Component {
|
||||
render () {
|
||||
render() {
|
||||
// eslint-disable-next-line react/no-this-in-sfc
|
||||
const { children, ...props } = this.props;
|
||||
const component = React.cloneElement(children, props);
|
||||
if (router.history) {
|
||||
return (
|
||||
<ConfigProvider value={config}>
|
||||
<Router history={router.history}>{component}</Router>
|
||||
</ConfigProvider>
|
||||
);
|
||||
}
|
||||
return (
|
||||
<ConfigProvider value={config}>
|
||||
{component}
|
||||
<MemoryRouter>{component}</MemoryRouter>
|
||||
</ConfigProvider>
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
return (
|
||||
<Wrap>{node}</Wrap>
|
||||
);
|
||||
return <Wrap>{node}</Wrap>;
|
||||
}
|
||||
|
||||
function applyDefaultContexts (context) {
|
||||
function applyDefaultContexts(context) {
|
||||
if (!context) {
|
||||
return defaultContexts;
|
||||
}
|
||||
@ -101,16 +108,16 @@ function applyDefaultContexts (context) {
|
||||
return newContext;
|
||||
}
|
||||
|
||||
export function shallowWithContexts (node, options = {}) {
|
||||
export function shallowWithContexts(node, options = {}) {
|
||||
const context = applyDefaultContexts(options.context);
|
||||
return shallow(wrapContexts(node, context));
|
||||
}
|
||||
|
||||
export function mountWithContexts (node, options = {}) {
|
||||
export function mountWithContexts(node, options = {}) {
|
||||
const context = applyDefaultContexts(options.context);
|
||||
const childContextTypes = {
|
||||
linguiPublisher: shape({
|
||||
i18n: object.isRequired
|
||||
i18n: object.isRequired,
|
||||
}).isRequired,
|
||||
config: shape({
|
||||
ansible_version: string,
|
||||
@ -122,9 +129,9 @@ export function mountWithContexts (node, options = {}) {
|
||||
location: shape({}),
|
||||
match: shape({}),
|
||||
}).isRequired,
|
||||
history: shape({}).isRequired,
|
||||
history: shape({}),
|
||||
}),
|
||||
...options.childContextTypes
|
||||
...options.childContextTypes,
|
||||
};
|
||||
return mount(wrapContexts(node, context), { context, childContextTypes });
|
||||
}
|
||||
@ -136,11 +143,15 @@ export function mountWithContexts (node, options = {}) {
|
||||
* @param[selector] - The selector of the element(s) to wait for.
|
||||
* @param[callback] - Callback to poll - by default this checks for a node count of 1.
|
||||
*/
|
||||
export function waitForElement (wrapper, selector, callback = el => el.length === 1) {
|
||||
export function waitForElement(
|
||||
wrapper,
|
||||
selector,
|
||||
callback = el => el.length === 1
|
||||
) {
|
||||
const interval = 100;
|
||||
return new Promise((resolve, reject) => {
|
||||
let attempts = 30;
|
||||
(function pollElement () {
|
||||
(function pollElement() {
|
||||
wrapper.update();
|
||||
const el = wrapper.find(selector);
|
||||
if (callback(el)) {
|
||||
@ -151,6 +162,6 @@ export function waitForElement (wrapper, selector, callback = el => el.length ==
|
||||
return reject(new Error(message));
|
||||
}
|
||||
return setTimeout(pollElement, interval);
|
||||
}());
|
||||
})();
|
||||
});
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user