Skip to content

Commit

Permalink
feat(toolbarFieldSla,Usage): ent-4208 standalone sla, usage (#820)
Browse files Browse the repository at this point in the history
* locale strings
* toolbarFieldSla, Usage, standalone select fields
  • Loading branch information
cdcabrera committed Dec 6, 2021
1 parent 61b6b9f commit b0632a3
Show file tree
Hide file tree
Showing 8 changed files with 537 additions and 1 deletion.
10 changes: 9 additions & 1 deletion public/locales/en-US.json
Original file line number Diff line number Diff line change
Expand Up @@ -147,12 +147,20 @@
"slaPremium": "Premium",
"slaSelfSupport": "Self-Support",
"slaStandard": "Standard",
"sla_none": "No SLA",
"sla_premium": "Premium",
"sla_self-support": "Self-Support",
"sla_standard": "Standard",
"uom_cores": "Cores",
"uom_sockets": "Sockets",
"usageDevelopment": "Development/Test",
"usageDisaster": "Disaster Recovery",
"usageProduction": "Production",
"usageUnspecified": "Unspecified"
"usageUnspecified": "Unspecified",
"usage_Development/Test": "Development/Test",
"usage_Disaster Recovery": "Disaster Recovery",
"usage_Production": "Production",
"usage_unspecified": "Unspecified"
},
"curiosity-optin": {
"buttonActivate": "Activate {{appName}}",
Expand Down
42 changes: 42 additions & 0 deletions src/components/i18n/__tests__/__snapshots__/i18n.test.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -417,6 +417,23 @@ Array [
},
],
},
Object {
"file": "./src/components/toolbar/toolbarFieldSla.js",
"keys": Array [
Object {
"key": "curiosity-toolbar.sla",
"match": "translate('curiosity-toolbar.sla', { context: (type === '' && 'none')",
},
Object {
"key": "curiosity-toolbar.placeholder",
"match": "t('curiosity-toolbar.placeholder', { context: 'sla' })",
},
Object {
"key": "curiosity-toolbar.placeholder",
"match": "t('curiosity-toolbar.placeholder', { context: 'sla' })",
},
],
},
Object {
"file": "./src/components/toolbar/toolbarFieldUom.js",
"keys": Array [
Expand All @@ -434,6 +451,23 @@ Array [
},
],
},
Object {
"file": "./src/components/toolbar/toolbarFieldUsage.js",
"keys": Array [
Object {
"key": "curiosity-toolbar.usage",
"match": "translate('curiosity-toolbar.usage', { context: (type === '' && 'unspecified')",
},
Object {
"key": "curiosity-toolbar.placeholder",
"match": "t('curiosity-toolbar.placeholder', { context: 'usage' })",
},
Object {
"key": "curiosity-toolbar.placeholder",
"match": "t('curiosity-toolbar.placeholder', { context: 'usage' })",
},
],
},
Object {
"file": "./src/components/toolbar/toolbarHelpers.js",
"keys": Array [
Expand Down Expand Up @@ -618,10 +652,18 @@ Array [
"file": "./src/components/toolbar/toolbarFieldGranularity.js",
"key": "curiosity-toolbar.granularity",
},
Object {
"file": "./src/components/toolbar/toolbarFieldSla.js",
"key": "curiosity-toolbar.sla",
},
Object {
"file": "./src/components/toolbar/toolbarFieldUom.js",
"key": "curiosity-toolbar.uom",
},
Object {
"file": "./src/components/toolbar/toolbarFieldUsage.js",
"key": "curiosity-toolbar.usage",
},
Object {
"file": "./src/config/product.openshiftContainer.js",
"key": "curiosity-inventory.label",
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`ToolbarFieldSla Component should export select options: toolbarFieldOptions 1`] = `
Array [
Object {
"selected": false,
"title": "t(curiosity-toolbar.sla, {\\"context\\":\\"premium\\"})",
"value": "premium",
},
Object {
"selected": false,
"title": "t(curiosity-toolbar.sla, {\\"context\\":\\"standard\\"})",
"value": "standard",
},
Object {
"selected": false,
"title": "t(curiosity-toolbar.sla, {\\"context\\":\\"self-support\\"})",
"value": "self-support",
},
Object {
"selected": false,
"title": "t(curiosity-toolbar.sla, {\\"context\\":\\"none\\"})",
"value": "",
},
]
`;

exports[`ToolbarFieldSla Component should handle updating sla through redux state: dispatch sla 1`] = `
Array [
Array [
Array [
Object {
"type": "SET_QUERY_RESET_INVENTORY_LIST",
"viewId": "loremIpsum",
},
Object {
"sla": "premium",
"type": "SET_QUERY_RHSM_sla",
"viewId": "loremIpsum",
},
],
],
]
`;

exports[`ToolbarFieldSla Component should render a basic component: basic 1`] = `
<Select
aria-label="t(curiosity-toolbar.placeholder, {\\"context\\":\\"sla\\"})"
ariaLabel="Select option"
className=""
data-test="toolbarFieldSla"
direction="down"
id="generatedid-"
isDisabled={false}
isToggleText={true}
maxHeight={null}
name={null}
onSelect={[Function]}
options={
Array [
Object {
"selected": false,
"title": "t(curiosity-toolbar.sla, {\\"context\\":\\"premium\\"})",
"value": "premium",
},
Object {
"selected": true,
"title": "t(curiosity-toolbar.sla, {\\"context\\":\\"standard\\"})",
"value": "standard",
},
Object {
"selected": false,
"title": "t(curiosity-toolbar.sla, {\\"context\\":\\"self-support\\"})",
"value": "self-support",
},
Object {
"selected": false,
"title": "t(curiosity-toolbar.sla, {\\"context\\":\\"none\\"})",
"value": "",
},
]
}
placeholder="t(curiosity-toolbar.placeholder, {\\"context\\":\\"sla\\"})"
position="left"
selectedOptions="standard"
toggleIcon={null}
variant="single"
/>
`;
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`ToolbarFieldSla Component should export select options: toolbarFieldOptions 1`] = `
Array [
Object {
"selected": false,
"title": "t(curiosity-toolbar.usage, {\\"context\\":\\"Production\\"})",
"value": "Production",
},
Object {
"selected": false,
"title": "t(curiosity-toolbar.usage, {\\"context\\":\\"Development/Test\\"})",
"value": "Development/Test",
},
Object {
"selected": false,
"title": "t(curiosity-toolbar.usage, {\\"context\\":\\"Disaster Recovery\\"})",
"value": "Disaster Recovery",
},
Object {
"selected": false,
"title": "t(curiosity-toolbar.usage, {\\"context\\":\\"unspecified\\"})",
"value": "",
},
]
`;

exports[`ToolbarFieldSla Component should handle updating usage through redux state: dispatch usage 1`] = `
Array [
Array [
Array [
Object {
"type": "SET_QUERY_RESET_INVENTORY_LIST",
"viewId": "loremIpsum",
},
Object {
"type": "SET_QUERY_RHSM_usage",
"usage": "Production",
"viewId": "loremIpsum",
},
],
],
]
`;

exports[`ToolbarFieldSla Component should render a basic component: basic 1`] = `
<Select
aria-label="t(curiosity-toolbar.placeholder, {\\"context\\":\\"usage\\"})"
ariaLabel="Select option"
className=""
data-test="toolbarFieldUsage"
direction="down"
id="generatedid-"
isDisabled={false}
isToggleText={true}
maxHeight={null}
name={null}
onSelect={[Function]}
options={
Array [
Object {
"selected": false,
"title": "t(curiosity-toolbar.usage, {\\"context\\":\\"Production\\"})",
"value": "Production",
},
Object {
"selected": true,
"title": "t(curiosity-toolbar.usage, {\\"context\\":\\"Development/Test\\"})",
"value": "Development/Test",
},
Object {
"selected": false,
"title": "t(curiosity-toolbar.usage, {\\"context\\":\\"Disaster Recovery\\"})",
"value": "Disaster Recovery",
},
Object {
"selected": false,
"title": "t(curiosity-toolbar.usage, {\\"context\\":\\"unspecified\\"})",
"value": "",
},
]
}
placeholder="t(curiosity-toolbar.placeholder, {\\"context\\":\\"usage\\"})"
position="left"
selectedOptions="Development/Test"
toggleIcon={null}
variant="single"
/>
`;
45 changes: 45 additions & 0 deletions src/components/toolbar/__tests__/toolbarFieldSla.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
import React from 'react';
import { shallow } from 'enzyme';
import { ToolbarFieldSla, toolbarFieldOptions } from '../toolbarFieldSla';
import { store } from '../../../redux/store';
import { RHSM_API_QUERY_SLA_TYPES as SLA_TYPES, RHSM_API_QUERY_TYPES } from '../../../types/rhsmApiTypes';

describe('ToolbarFieldSla Component', () => {
let mockDispatch;

beforeEach(() => {
mockDispatch = jest.spyOn(store, 'dispatch').mockImplementation((type, data) => ({ type, data }));
});

afterEach(() => {
jest.clearAllMocks();
});

it('should render a basic component', () => {
const props = {
useProduct: () => ({ viewId: 'loremIpsum' }),
useProductQuery: () => ({ [RHSM_API_QUERY_TYPES.SLA]: SLA_TYPES.STANDARD })
};
const component = shallow(<ToolbarFieldSla {...props} />);

expect(component).toMatchSnapshot('basic');
});

it('should export select options', () => {
expect(toolbarFieldOptions).toMatchSnapshot('toolbarFieldOptions');
});

it('should handle updating sla through redux state', async () => {
const props = {
useProduct: () => ({ viewId: 'loremIpsum' })
};

const component = await mountHookComponent(<ToolbarFieldSla {...props} />);

component.find('button').simulate('click');
component.update();
component.find('button.pf-c-select__menu-item').first().simulate('click');

expect(mockDispatch.mock.calls).toMatchSnapshot('dispatch sla');
});
});
45 changes: 45 additions & 0 deletions src/components/toolbar/__tests__/toolbarFieldUsage.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
import React from 'react';
import { shallow } from 'enzyme';
import { ToolbarFieldUsage, toolbarFieldOptions } from '../toolbarFieldUsage';
import { store } from '../../../redux/store';
import { RHSM_API_QUERY_USAGE_TYPES as USAGE_TYPES, RHSM_API_QUERY_TYPES } from '../../../types/rhsmApiTypes';

describe('ToolbarFieldSla Component', () => {
let mockDispatch;

beforeEach(() => {
mockDispatch = jest.spyOn(store, 'dispatch').mockImplementation((type, data) => ({ type, data }));
});

afterEach(() => {
jest.clearAllMocks();
});

it('should render a basic component', () => {
const props = {
useProduct: () => ({ viewId: 'loremIpsum' }),
useProductQuery: () => ({ [RHSM_API_QUERY_TYPES.USAGE]: USAGE_TYPES.DEVELOPMENT })
};
const component = shallow(<ToolbarFieldUsage {...props} />);

expect(component).toMatchSnapshot('basic');
});

it('should export select options', () => {
expect(toolbarFieldOptions).toMatchSnapshot('toolbarFieldOptions');
});

it('should handle updating usage through redux state', async () => {
const props = {
useProduct: () => ({ viewId: 'loremIpsum' })
};

const component = await mountHookComponent(<ToolbarFieldUsage {...props} />);

component.find('button').simulate('click');
component.update();
component.find('button.pf-c-select__menu-item').first().simulate('click');

expect(mockDispatch.mock.calls).toMatchSnapshot('dispatch usage');
});
});
Loading

0 comments on commit b0632a3

Please sign in to comment.