Skip to content

Commit

Permalink
[ECS-463] Fix the unit tests and the config object
Browse files Browse the repository at this point in the history
  • Loading branch information
avdev4j committed Sep 29, 2022
1 parent bb22502 commit 773e832
Show file tree
Hide file tree
Showing 6 changed files with 36 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -108,12 +108,12 @@ class <%= ComponentName %> extends React.Component {
onError: PropTypes.func,
t: PropTypes.func.isRequired,
keycloak: keycloakType.isRequired,
config: PropTypes.func,
config: PropTypes.object,
};

<%= ComponentName %>.defaultProps = {
onError: () => {},
config: () => {},
config: {},
};

export default withKeycloak(withTranslation()(<%= ComponentName %>));
Original file line number Diff line number Diff line change
Expand Up @@ -88,14 +88,14 @@ class <%= entityClass %>AddFormContainer extends PureComponent {
onCreate: PropTypes.func,
t: PropTypes.func.isRequired,
keycloak: keycloakType.isRequired,
config: PropTypes.func,
config: PropTypes.object,
};

<%= entityClass %>AddFormContainer.defaultProps = {
onError: () => {},
onCancelEditing: () => {},
onCreate: () => {},
config: () => {},
config: {},
};

export default withKeycloak(withTranslation()(<%= entityClass %>AddFormContainer));
Original file line number Diff line number Diff line change
Expand Up @@ -174,15 +174,15 @@ class <%= entityClass %>EditFormContainer extends PureComponent {
onDelete: PropTypes.func,
t: PropTypes.func.isRequired,
keycloak: keycloakType.isRequired,
config: PropTypes.func,
config: PropTypes.object,
};

<%= entityClass %>EditFormContainer.defaultProps = {
onCancelEditing: () => {},
onDelete: () => {},
onUpdate: () => {},
onError: () => {},
config: () => {},
config: {},
};

export default withKeycloak(withTranslation()(<%= entityClass %>EditFormContainer));
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,16 @@ import <%= entityClass %>AddFormContainer from 'components/<%= entityClass %>Add
import 'i18n/__mocks__/i18nMock';
import { <%= entityInstance %>MockAdd as <%= entityInstance %>Mock } from 'components/__mocks__/<%= entityInstance %>Mocks';

const configMock = {
systemParams: {
api: {
'<%= entityFileName %>-api': {
url: '',
},
},
},
};

jest.mock('api/<%= entityInstancePlural %>');
jest.mock('@material-ui/pickers', () => {
// eslint-disable-next-line react/prop-types
Expand Down Expand Up @@ -72,7 +82,7 @@ describe('<%= entityClass %>AddFormContainer', () => {
api<%= entityClass %>Post.mockImplementation(data => Promise.resolve(data));

const { findByTestId, findByLabelText, queryByText, rerender } = render(
<<%= entityClass %>AddFormContainer onError={onErrorMock} onUpdate={onCreateMock} />
<<%= entityClass %>AddFormContainer onError={onErrorMock} onUpdate={onCreateMock} config={configMock} />
);

<%_
Expand All @@ -97,7 +107,7 @@ describe('<%= entityClass %>AddFormContainer', () => {
}
})
_%>
rerender(<<%= entityClass %>AddFormContainer onError={onErrorMock} onUpdate={onCreateMock} />);
rerender(<<%= entityClass %>AddFormContainer onError={onErrorMock} onUpdate={onCreateMock} config={configMock} />);

const saveButton = await findByTestId('submit-btn');

Expand All @@ -118,7 +128,7 @@ describe('<%= entityClass %>AddFormContainer', () => {
api<%= entityClass %>Post.mockImplementation(() => Promise.reject());

const { findByTestId, findByLabelText, queryByText, rerender } = render(
<<%= entityClass %>AddFormContainer onError={onErrorMock} onUpdate={onCreateMock} />
<<%= entityClass %>AddFormContainer onError={onErrorMock} onUpdate={onCreateMock} config={configMock} />
);

<%_
Expand All @@ -143,7 +153,7 @@ describe('<%= entityClass %>AddFormContainer', () => {
}
})
_%>
rerender(<<%= entityClass %>AddFormContainer onError={onErrorMock} onUpdate={onCreateMock} />);
rerender(<<%= entityClass %>AddFormContainer onError={onErrorMock} onUpdate={onCreateMock} config={configMock} />);

const saveButton = await findByTestId('submit-btn');

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,16 @@ import <%= entityClass %>EditFormContainer from 'components/<%= entityClass %>Ed
import 'i18n/__mocks__/i18nMock';
import { <%= entityInstance %>MockEdit as <%= entityInstance %>Mock } from 'components/__mocks__/<%= entityInstance %>Mocks';

const configMock = {
systemParams: {
api: {
'<%= entityFileName %>-api': {
url: '',
},
},
},
};

jest.mock('api/<%= entityInstancePlural %>');

jest.mock('auth/withKeycloak', () => {
Expand Down Expand Up @@ -38,7 +48,7 @@ describe('<%= entityClass %>EditFormContainer', () => {
it('loads data', async () => {
api<%= entityClass %>Get.mockImplementation(() => Promise.resolve(<%= entityInstance %>Mock));
const { queryByText } = render(
<<%= entityClass %>EditFormContainer id="1" onError={onErrorMock} onUpdate={onUpdateMock} />
<<%= entityClass %>EditFormContainer id="1" onError={onErrorMock} onUpdate={onUpdateMock} config={configMock} />
);

await wait(() => {
Expand All @@ -54,7 +64,7 @@ describe('<%= entityClass %>EditFormContainer', () => {
api<%= entityClass %>Put.mockImplementation(() => Promise.resolve(<%= entityInstance %>Mock));

const { findByTestId, queryByText } = render(
<<%= entityClass %>EditFormContainer id="1" onError={onErrorMock} onUpdate={onUpdateMock} />
<<%= entityClass %>EditFormContainer id="1" onError={onErrorMock} onUpdate={onUpdateMock} config={configMock} />
);

const saveButton = await findByTestId('submit-btn');
Expand All @@ -73,7 +83,7 @@ describe('<%= entityClass %>EditFormContainer', () => {
it('shows an error if data is not successfully loaded', async () => {
api<%= entityClass %>Get.mockImplementation(() => Promise.reject());
const { queryByText } = render(
<<%= entityClass %>EditFormContainer id="1" onError={onErrorMock} onUpdate={onUpdateMock} />
<<%= entityClass %>EditFormContainer id="1" onError={onErrorMock} onUpdate={onUpdateMock} config={configMock} />
);

await wait(() => {
Expand All @@ -89,7 +99,7 @@ describe('<%= entityClass %>EditFormContainer', () => {
api<%= entityClass %>Get.mockImplementation(() => Promise.resolve(<%= entityInstance %>Mock));
api<%= entityClass %>Put.mockImplementation(() => Promise.reject());
const { findByTestId, getByText } = render(
<<%= entityClass %>EditFormContainer id="1" onError={onErrorMock} />
<<%= entityClass %>EditFormContainer id="1" onError={onErrorMock} config={configMock} />
);

const saveButton = await findByTestId('submit-btn');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -265,7 +265,7 @@ class <%= ComponentName %> extends Component {
currentPage: PropTypes.number,
itemsPerPage: PropTypes.number,
}),
config: PropTypes.func,
config: PropTypes.object,
};

<%= ComponentName %>.defaultProps = {
Expand All @@ -275,7 +275,7 @@ class <%= ComponentName %> extends Component {
onSelect: () => {},
paginationMode: '',
pagination: null,
config: () => {},
config: {},
};

export default withKeycloak(
Expand Down

0 comments on commit 773e832

Please sign in to comment.