2017-02-23 22:18:23 +01:00
|
|
|
import React from 'react';
|
|
|
|
|
|
|
|
import ClientApplications from '../application-edit-component';
|
|
|
|
import renderer from 'react-test-renderer';
|
2019-01-16 10:39:58 +01:00
|
|
|
import { MemoryRouter } from 'react-router-dom';
|
|
|
|
import { CREATE_FEATURE, CREATE_STRATEGY, UPDATE_APPLICATION } from '../../../permissions';
|
2017-02-23 22:18:23 +01:00
|
|
|
|
|
|
|
jest.mock('react-mdl');
|
|
|
|
|
|
|
|
test('renders correctly if no application', () => {
|
2018-02-04 14:32:33 +01:00
|
|
|
const tree = renderer
|
2019-01-16 10:39:58 +01:00
|
|
|
.create(
|
|
|
|
<ClientApplications
|
2020-09-25 21:09:26 +02:00
|
|
|
fetchApplication={() => Promise.resolve({})}
|
2019-01-16 10:39:58 +01:00
|
|
|
storeApplicationMetaData={jest.fn()}
|
2020-09-25 21:09:26 +02:00
|
|
|
deleteApplication={jest.fn()}
|
2019-01-16 10:39:58 +01:00
|
|
|
hasPermission={() => true}
|
2020-09-25 21:09:26 +02:00
|
|
|
history={{}}
|
2019-01-16 10:39:58 +01:00
|
|
|
/>
|
|
|
|
)
|
|
|
|
.toJSON();
|
|
|
|
|
|
|
|
expect(tree).toMatchSnapshot();
|
|
|
|
});
|
|
|
|
|
|
|
|
test('renders correctly without permission', () => {
|
|
|
|
const tree = renderer
|
|
|
|
.create(
|
|
|
|
<MemoryRouter>
|
|
|
|
<ClientApplications
|
2020-09-25 21:09:26 +02:00
|
|
|
fetchApplication={() => Promise.resolve({})}
|
2019-01-16 10:39:58 +01:00
|
|
|
storeApplicationMetaData={jest.fn()}
|
2020-09-25 21:09:26 +02:00
|
|
|
deleteApplication={jest.fn()}
|
|
|
|
history={{}}
|
2019-01-16 10:39:58 +01:00
|
|
|
application={{
|
|
|
|
appName: 'test-app',
|
|
|
|
instances: [
|
|
|
|
{
|
|
|
|
instanceId: 'instance-1',
|
|
|
|
clientIp: '123.123.123.123',
|
2019-01-16 10:51:17 +01:00
|
|
|
lastSeen: '2017-02-23T15:56:49',
|
2019-01-16 10:39:58 +01:00
|
|
|
sdkVersion: '4.0',
|
|
|
|
},
|
|
|
|
],
|
|
|
|
strategies: [
|
|
|
|
{
|
|
|
|
name: 'StrategyA',
|
|
|
|
description: 'A description',
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: 'StrategyB',
|
|
|
|
description: 'B description',
|
|
|
|
notFound: true,
|
|
|
|
},
|
|
|
|
],
|
|
|
|
seenToggles: [
|
|
|
|
{
|
|
|
|
name: 'ToggleA',
|
|
|
|
description: 'this is A toggle',
|
|
|
|
enabled: true,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: 'ToggleB',
|
|
|
|
description: 'this is B toggle',
|
|
|
|
enabled: false,
|
|
|
|
notFound: true,
|
|
|
|
},
|
|
|
|
],
|
|
|
|
url: 'http://example.org',
|
|
|
|
description: 'app description',
|
|
|
|
}}
|
|
|
|
location={{ locale: 'en-GB' }}
|
|
|
|
hasPermission={() => false}
|
|
|
|
/>
|
|
|
|
</MemoryRouter>
|
|
|
|
)
|
|
|
|
.toJSON();
|
|
|
|
|
|
|
|
expect(tree).toMatchSnapshot();
|
|
|
|
});
|
|
|
|
|
|
|
|
test('renders correctly with permissions', () => {
|
|
|
|
const tree = renderer
|
|
|
|
.create(
|
|
|
|
<MemoryRouter>
|
|
|
|
<ClientApplications
|
2020-09-25 21:09:26 +02:00
|
|
|
fetchApplication={() => Promise.resolve({})}
|
2019-01-16 10:39:58 +01:00
|
|
|
storeApplicationMetaData={jest.fn()}
|
2020-09-25 21:09:26 +02:00
|
|
|
history={{}}
|
|
|
|
deleteApplication={jest.fn()}
|
2019-01-16 10:39:58 +01:00
|
|
|
application={{
|
|
|
|
appName: 'test-app',
|
|
|
|
instances: [
|
|
|
|
{
|
|
|
|
instanceId: 'instance-1',
|
|
|
|
clientIp: '123.123.123.123',
|
2019-01-16 10:51:17 +01:00
|
|
|
lastSeen: '2017-02-23T15:56:49',
|
2019-01-16 10:39:58 +01:00
|
|
|
sdkVersion: '4.0',
|
|
|
|
},
|
|
|
|
],
|
|
|
|
strategies: [
|
|
|
|
{
|
|
|
|
name: 'StrategyA',
|
|
|
|
description: 'A description',
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: 'StrategyB',
|
|
|
|
description: 'B description',
|
|
|
|
notFound: true,
|
|
|
|
},
|
|
|
|
],
|
|
|
|
seenToggles: [
|
|
|
|
{
|
|
|
|
name: 'ToggleA',
|
|
|
|
description: 'this is A toggle',
|
|
|
|
enabled: true,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: 'ToggleB',
|
|
|
|
description: 'this is B toggle',
|
|
|
|
enabled: false,
|
|
|
|
notFound: true,
|
|
|
|
},
|
|
|
|
],
|
|
|
|
url: 'http://example.org',
|
|
|
|
description: 'app description',
|
|
|
|
}}
|
|
|
|
location={{ locale: 'en-GB' }}
|
|
|
|
hasPermission={permission =>
|
|
|
|
[CREATE_FEATURE, CREATE_STRATEGY, UPDATE_APPLICATION].indexOf(permission) !== -1
|
|
|
|
}
|
|
|
|
/>
|
|
|
|
</MemoryRouter>
|
|
|
|
)
|
2018-02-04 14:32:33 +01:00
|
|
|
.toJSON();
|
2017-02-23 22:18:23 +01:00
|
|
|
|
|
|
|
expect(tree).toMatchSnapshot();
|
|
|
|
});
|