diff --git a/generators/client/templates/vue/src/test/javascript/jest.conf.js.ejs b/generators/client/templates/vue/src/test/javascript/jest.conf.js.ejs index 7dff3110e2f4..ad23b6102bce 100644 --- a/generators/client/templates/vue/src/test/javascript/jest.conf.js.ejs +++ b/generators/client/templates/vue/src/test/javascript/jest.conf.js.ejs @@ -42,11 +42,7 @@ module.exports = { coverageThreshold: { global: { statements: 80, -<%_ if (microfrontend) { _%> - branches: 57, -<%_ } else { _%> branches: 60, -<%_ } _%> functions: 70, lines: 80, }, diff --git a/generators/client/templates/vue/src/test/javascript/spec/app/shared/alert/alert.service.spec.ts.ejs b/generators/client/templates/vue/src/test/javascript/spec/app/shared/alert/alert.service.spec.ts.ejs index dd5c6780f484..618989bfe052 100644 --- a/generators/client/templates/vue/src/test/javascript/spec/app/shared/alert/alert.service.spec.ts.ejs +++ b/generators/client/templates/vue/src/test/javascript/spec/app/shared/alert/alert.service.spec.ts.ejs @@ -40,7 +40,7 @@ describe('Alert Service test suite', () => { // WHEN alertService.showError((vueInstance) as Vue, <% if (enableTranslation) { %>translationKey<%} else {%>message<% } %>); - //THEN + // THEN <%_ if (enableTranslation) { _%> expect(translationStub.withArgs(translationKey).callCount).toEqual(1); <%_ } _%> @@ -71,7 +71,7 @@ describe('Alert Service test suite', () => { // WHEN alertService.showHttpError((vueInstance) as Vue, httpErrorResponse); - //THEN + // THEN <%_ if (enableTranslation) { _%> expect(translationStub.withArgs(translationKey).callCount).toEqual(1); <%_ } _%> @@ -107,7 +107,7 @@ describe('Alert Service test suite', () => { // WHEN alertService.showHttpError((vueInstance) as Vue, httpErrorResponse); - //THEN + // THEN <%_ if (enableTranslation) { _%> expect(translationStub.withArgs(translationKey, { entityName: 'DummyEntity' }).callCount).toEqual(1); <%_ } _%> @@ -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 = 'Validation error'; + const httpErrorResponse = { + status: 400, + headers: { + 'x-jhipsterapp-error400': 'error', + 'x-jhipsterapp-params400': 'dummyEntity', + }, + data: { + message, + fieldErrors: { + 'field1': 'error1', + }, + }, + }; + + <%_ if (enableTranslation) { _%> + // GIVEN + translationStub.withArgs(message).returns(message); + <%_ } _%> + + // WHEN + alertService.showHttpError((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(); + }); });