Skip to content

Commit

Permalink
[Vue] Increase Vue code coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
qmonmert committed Aug 12, 2022
1 parent 70fd7cd commit b733114
Showing 1 changed file with 42 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ describe('Alert Service test suite', () => {
// WHEN
alertService.showError((<any>vueInstance) as Vue, <% if (enableTranslation) { %>translationKey<%} else {%>message<% } %>);

//THEN
// THEN
<%_ if (enableTranslation) { _%>
expect(translationStub.withArgs(translationKey).callCount).toEqual(1);
<%_ } _%>
Expand Down Expand Up @@ -71,7 +71,7 @@ describe('Alert Service test suite', () => {
// WHEN
alertService.showHttpError((<any>vueInstance) as Vue, httpErrorResponse);

//THEN
// THEN
<%_ if (enableTranslation) { _%>
expect(translationStub.withArgs(translationKey).callCount).toEqual(1);
<%_ } _%>
Expand Down Expand Up @@ -107,7 +107,7 @@ describe('Alert Service test suite', () => {
// WHEN
alertService.showHttpError((<any>vueInstance) as Vue, httpErrorResponse);

//THEN
// THEN
<%_ if (enableTranslation) { _%>
expect(translationStub.withArgs(translationKey, { entityName: 'DummyEntity' }).callCount).toEqual(1);
<%_ } _%>
Expand All @@ -121,4 +121,43 @@ describe('Alert Service test suite', () => {
})
).toBeTruthy();
});

it('should show error toast with data.message when http status = 400 and entity headers', async () => {
const message = 'Error!';
const httpErrorResponse = {
status: 400,
headers: {
'x-jhipsterapp-error400': 'error',
'x-jhipsterapp-params400': 'dummyEntity',
},
data: {
message: 'Error!',
fieldErrors: {
'field1': 'error1',
},
},
};

<%_ if (enableTranslation) { _%>
// GIVEN
translationStub.withArgs(message).returns(message);
<%_ } _%>

// WHEN
alertService.showHttpError((<any>vueInstance) as Vue, httpErrorResponse);

// THEN
<%_ if (enableTranslation) { _%>
expect(translationStub.withArgs(message).callCount).toEqual(1);
<%_ } _%>
expect(
toastStub.calledOnceWith(message, {
toaster: 'b-toaster-top-center',
title: 'Error',
variant: 'danger',
solid: true,
autoHideDelay: 5000,
})
).toBeTruthy();
});
});

0 comments on commit b733114

Please sign in to comment.