Skip to content

Commit

Permalink
Merge pull request #11799 from qmonmert/refactotests
Browse files Browse the repository at this point in the history
Tests: some refacto
  • Loading branch information
pascalgrimaud authored Jan 27, 2025
2 parents 8d94114 + 10fd1ee commit 61396de
Show file tree
Hide file tree
Showing 22 changed files with 55 additions and 67 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -73,13 +73,13 @@ describe('HealthComponent', () => {
it('should get success badge class', () => {
const upBadgeClass = comp.getBadgeClass('UP');
expect(upBadgeClass).toEqual('bg-success');
expect(upBadgeClass).toBe('bg-success');
});

it('should get danger badge class', () => {
const downBadgeClass = comp.getBadgeClass('DOWN');
expect(downBadgeClass).toEqual('bg-danger');
expect(downBadgeClass).toBe('bg-danger');
});
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ describe('HealthModalComponent', () => {

const result = comp.readableValue({ name: 'jhipster' });

expect(result).toEqual('{"name":"jhipster"}');
expect(result).toBe('{"name":"jhipster"}');
});

it('should return string value', () => {
Expand All @@ -40,7 +40,7 @@ describe('HealthModalComponent', () => {

const result = comp.readableValue('jhipster');

expect(result).toEqual('jhipster');
expect(result).toBe('jhipster');
});

it('should return storage space in a human readable unit (GB)', () => {
Expand All @@ -51,7 +51,7 @@ describe('HealthModalComponent', () => {

const result = comp.readableValue(1073741825);

expect(result).toEqual('1.00 GB');
expect(result).toBe('1.00 GB');
});

it('should return storage space in a human readable unit (MB)', () => {
Expand All @@ -62,7 +62,7 @@ describe('HealthModalComponent', () => {

const result = comp.readableValue(1073741824);

expect(result).toEqual('1024.00 MB');
expect(result).toBe('1024.00 MB');
});

it('should return string value', () => {
Expand All @@ -73,7 +73,7 @@ describe('HealthModalComponent', () => {

const result = comp.readableValue(1234);

expect(result).toEqual('1234');
expect(result).toBe('1234');
});
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ describe('ApplicationConfigService', () => {

describe('without prefix', () => {
it('should return correctly', () => {
expect(service.getEndpointFor('api')).toEqual('api');
expect(service.getEndpointFor('api')).toBe('api');
});
});

Expand All @@ -22,7 +22,7 @@ describe('ApplicationConfigService', () => {
});

it('should return correctly', () => {
expect(service.getEndpointFor('api')).toEqual('prefix/api');
expect(service.getEndpointFor('api')).toBe('prefix/api');
});
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ describe('App Component', () => {

describe('ngOnInit', () => {
it('should have appName', () => {
expect(comp.appName()).toEqual('{{baseName}}');
expect(comp.appName()).toBe('{{baseName}}');
});
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ describe('Login Component', () => {

comp.login();

expect(comp.errorMessage()).toEqual('Authentication failed');
expect(comp.errorMessage()).toBe('Authentication failed');
});
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ describe('httpAuthInterceptor', () => {
const req = httpTestingController.expectOne(originalRequest.url);
expect(req.request.method).toEqual(HTTP_METHOD);
expect(req.request.url).toEqual(URL);
expect(req.request.headers.get('ContentType')).toEqual('application/json');
expect(req.request.headers.get('ContentType')).toBe('application/json');
expect(req.request.headers.get('Authorization')).toEqual(`Bearer ${TOKEN}`);
});

Expand All @@ -51,7 +51,7 @@ describe('httpAuthInterceptor', () => {
httpClient.request(originalRequest).subscribe();
const req = httpTestingController.expectOne(originalRequest.url);
expect(req.request.headers.get('ContentType')).toEqual('application/json');
expect(req.request.headers.get('ContentType')).toBe('application/json');
expect(req.request.headers.get('Authorization')).toBeFalsy();
});
});
Expand Down
4 changes: 2 additions & 2 deletions src/main/resources/generator/client/common/i18n/i18n.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@ import { mergeTranslations } from '@/Translations';

describe('i18n configuration', () => {
it('loads en translation', () => {
expect(i18n.getResourceBundle('en', '')['home']['translationEnabled']).toEqual('Internationalization enabled');
expect(i18n.getResourceBundle('en', '')['home']['translationEnabled']).toBe('Internationalization enabled');
});

it('loads fr translation', () => {
expect(i18n.getResourceBundle('fr', '')['home']['translationEnabled']).toEqual('Internationalisation activée');
expect(i18n.getResourceBundle('fr', '')['home']['translationEnabled']).toBe('Internationalisation activée');
});

describe('mergeTranslations function', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ describe('loginForm', () => {
const spy = mockPost();
await login();
expect(spy).toHaveBeenCalledTimes(1);
expect(spy).toHaveBeenCalledOnce();
});

it('should display Log out after login and display Log in after logout', async () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ describe('test login modal', () => {
const submitButton = getByTestId('submit-button');
fireEvent.click(submitButton);
});
expect(spy).toHaveBeenCalledTimes(1);
expect(spy).toHaveBeenCalledOnce();
});

it('render the modal on login button click and close the modal on close button', async () => {
Expand All @@ -85,7 +85,7 @@ describe('test login modal', () => {
const submitButton = getByRole('button', { name: 'Close' });
fireEvent.click(submitButton);
});
expect(spy).toHaveBeenCalledTimes(0);
expect(spy).not.toHaveBeenCalled();
});

it('should contain error message when submit button is clicked with empty value', async () => {
Expand Down
2 changes: 1 addition & 1 deletion src/test/resources/projects/angular/app.component.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ describe('App Component', () => {

describe('ngOnInit', () => {
it('should have appName', () => {
expect(comp.appName()).toEqual('test');
expect(comp.appName()).toBe('test');
});
});
});
10 changes: 5 additions & 5 deletions src/test/webapp/unit/common/primary/timeout/Timeout.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ describe('Timeout', () => {

vi.advanceTimersByTime(TIMEOUT_TIME);

expect(stub).toHaveBeenCalledTimes(1);
expect(stub).toHaveBeenCalledOnce();
});

it('should not launch timeout with less some time', () => {
Expand All @@ -28,7 +28,7 @@ describe('Timeout', () => {

vi.advanceTimersByTime(LESS_TIME);

expect(stub).toHaveBeenCalledTimes(0);
expect(stub).not.toHaveBeenCalled();
});

it('should not launch timeout with unsubscribe', () => {
Expand All @@ -39,7 +39,7 @@ describe('Timeout', () => {
timeout.unregister();
vi.advanceTimersByTime(TIMEOUT_TIME);

expect(stub).toHaveBeenCalledTimes(0);
expect(stub).not.toHaveBeenCalled();
});

it('should not fail to unregister when not registered', () => {
Expand All @@ -58,7 +58,7 @@ describe('Timeout', () => {
timeout.register(secondCall, TIMEOUT_TIME);
vi.advanceTimersByTime(TIMEOUT_TIME);

expect(firstCall).toHaveBeenCalledTimes(0);
expect(secondCall).toHaveBeenCalledTimes(1);
expect(firstCall).not.toHaveBeenCalled();
expect(secondCall).toHaveBeenCalledOnce();
});
});
4 changes: 2 additions & 2 deletions src/test/webapp/unit/common/primary/toast/Toast.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -97,8 +97,8 @@ describe('Toast', () => {

wrapper.unmount();

expect(unsubscribeSuccess).toHaveBeenCalledTimes(1);
expect(unsubscribeError).toHaveBeenCalledTimes(1);
expect(unsubscribeSuccess).toHaveBeenCalledOnce();
expect(unsubscribeError).toHaveBeenCalledOnce();
});

describe('Timeout', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ describe('Landscape', () => {
return mount(LandscapeVue);
} catch (e) {
if (e instanceof Error) {
expect(e.message).toEqual('repositoryWithLandscapeError');
expect(e.message).toBe('repositoryWithLandscapeError');
}
expect(console.error).toHaveBeenCalled();
}
Expand Down Expand Up @@ -196,7 +196,7 @@ describe('Landscape', () => {
return mount(LandscapeVue);
} catch (e) {
if (e instanceof Error) {
expect(e.message).toEqual('repositoryWithProjectFoldersErrorww');
expect(e.message).toBe('repositoryWithProjectFoldersErrorww');
}
expect(console.error).toHaveBeenCalled();
}
Expand All @@ -209,7 +209,7 @@ describe('Landscape', () => {
expect(wrapper.find(wrappedElement('landscape-loader')).exists()).toBe(false);
expect(wrapper.find(wrappedElement('landscape')).exists()).toBe(true);
expect(wrapper.find(wrappedElement('landscape-connectors')).findAll('path').length).toBe(17);
expect(applicationListener.addEventListener).toHaveBeenCalledTimes(1);
expect(applicationListener.addEventListener).toHaveBeenCalledOnce();

const pathField = wrapper.find(wrappedElement('folder-path-field')).element as HTMLInputElement;
expect(pathField.value).toBe('/tmp/jhlite/1234');
Expand All @@ -221,7 +221,7 @@ describe('Landscape', () => {

wrapper.unmount();

expect(applicationListener.removeEventListener).toHaveBeenCalledTimes(1);
expect(applicationListener.removeEventListener).toHaveBeenCalledOnce();
});

it('should load folder path from local storage', async () => {
Expand Down Expand Up @@ -744,7 +744,7 @@ describe('Landscape', () => {
const consoleErrors = vi.spyOn(console, 'error');
await updatePath(wrapper);

expect(console.error).toHaveBeenCalledTimes(0);
expect(console.error).not.toHaveBeenCalled();
consoleErrors.mockRestore();
});

Expand Down Expand Up @@ -845,8 +845,7 @@ describe('Landscape', () => {
const landscape = wrapper.find(wrappedElement('landscape-container'));
await landscape.trigger('mousedown', mouseEvent);

expect(cursorUpdater.set).toHaveBeenCalledTimes(1);
expect(cursorUpdater.set).toBeCalledWith('grabbing');
expect(cursorUpdater.set).toHaveBeenCalledExactlyOnceWith('grabbing');
});

it('should prevent default clicking event when defined', async () => {
Expand All @@ -863,7 +862,7 @@ describe('Landscape', () => {
const landscape = wrapper.find(wrappedElement('landscape-container'));
await landscape.trigger('mousedown', mouseEvent);

expect(mouseEvent.preventDefault).toHaveBeenCalledTimes(1);
expect(mouseEvent.preventDefault).toHaveBeenCalledOnce();
});

it('should stop grabbing on mouseup', async () => {
Expand All @@ -875,7 +874,7 @@ describe('Landscape', () => {
const landscape = wrapper.find(wrappedElement('landscape-container'));
await landscape.trigger('mouseup');

expect(cursorUpdater.reset).toHaveBeenCalledTimes(1);
expect(cursorUpdater.reset).toHaveBeenCalledOnce();
});

it('should stop grabbing on mouseleave', async () => {
Expand All @@ -887,7 +886,7 @@ describe('Landscape', () => {
const landscape = wrapper.find(wrappedElement('landscape-container'));
await landscape.trigger('mouseleave');

expect(cursorUpdater.reset).toHaveBeenCalledTimes(1);
expect(cursorUpdater.reset).toHaveBeenCalledOnce();
});

it('should be scrolling', async () => {
Expand All @@ -909,8 +908,7 @@ describe('Landscape', () => {
await landscape.trigger('mousedown', mouseEventStart);
await landscape.trigger('mousemove', mouseEventGrabbed);

expect(landscapeScroller.scroll).toHaveBeenCalledTimes(1);
expect(landscapeScroller.scroll).toBeCalledWith(expect.anything(), 20, 20);
expect(landscapeScroller.scroll).toHaveBeenCalledExactlyOnceWith(expect.anything(), 20, 20);
});

it('should not scroll without starting grabbing', async () => {
Expand All @@ -926,7 +924,7 @@ describe('Landscape', () => {
const landscape = wrapper.find(wrappedElement('landscape-container'));
await landscape.trigger('mousemove', mouseEventGrabbed);

expect(landscapeScroller.scroll).toHaveBeenCalledTimes(0);
expect(landscapeScroller.scroll).not.toHaveBeenCalled();
});
});

Expand Down Expand Up @@ -1277,8 +1275,7 @@ describe('Landscape', () => {

expect(mockModuleRect).toHaveBeenCalled();
expect(mockContainerRect).toHaveBeenCalled();
expect(landscapeScroller.scrollIntoView).toHaveBeenCalledTimes(1);
expect(landscapeScroller.scrollIntoView).toHaveBeenCalledWith(prettierModule);
expect(landscapeScroller.scrollIntoView).toHaveBeenCalledExactlyOnceWith(prettierModule);
});

it('should not scroll if the highlighted module is already visible', async () => {
Expand Down Expand Up @@ -1321,8 +1318,7 @@ describe('Landscape', () => {

await performSearch(searchInput, '');

expect(landscapeScroller.scrollSmooth).toHaveBeenCalledTimes(1);
expect(landscapeScroller.scrollSmooth).toHaveBeenCalledWith(landscapeContainer, 0, 0);
expect(landscapeScroller.scrollSmooth).toHaveBeenCalledExactlyOnceWith(landscapeContainer, 0, 0);
});

const setupSearchTest = async () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ describe('LandscapeConnector', () => {
];
const landscapeConnector: LandscapeConnector = new LandscapeConnector(positions, moduleSlug('moduleA'), moduleSlug('B'));
//MoveTo 'startPoint', LineTo, CurveTo(3 points), LineTo, CurveTo(3 points), LineTo 'endPoint'
expect(landscapeConnector.path).toEqual('M 0 0 L 4 0 C 4 0 10 0 10 6 L 10 94 C 10 94 10 100 16 100 L 100 100');
expect(landscapeConnector.path).toBe('M 0 0 L 4 0 C 4 0 10 0 10 6 L 10 94 C 10 94 10 100 16 100 L 100 100');
});

it('should generate curved path for top-right dependant', () => {
Expand All @@ -49,7 +49,7 @@ describe('LandscapeConnector', () => {
];
const landscapeConnector: LandscapeConnector = new LandscapeConnector(positions, moduleSlug('moduleA'), moduleSlug('B'));
//MoveTo 'startPoint', LineTo, CurveTo(3 points), LineTo, CurveTo(3 points), LineTo 'endPoint'
expect(landscapeConnector.path).toEqual('M 100 100 L 104 100 C 104 100 110 100 110 94 L 110 6 C 110 6 110 0 116 0 L 200 0');
expect(landscapeConnector.path).toBe('M 100 100 L 104 100 C 104 100 110 100 110 94 L 110 6 C 110 6 110 0 116 0 L 200 0');
});
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ describe('MiniMap component', () => {
await minimapViewer.trigger('mousemove');
await wrapper.vm.$nextTick();

expect(landscapeContainer.scroll).toHaveBeenCalledTimes(0);
expect(landscapeContainer.scroll).not.toHaveBeenCalled();
});

it('should track the scroller position of the landscape container', async () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,7 @@ describe('LandscapeScroller', () => {

landscapeScroller.scroll(element, 10, 10);

expect(element.scroll).toHaveBeenCalledTimes(1);
expect(element.scroll).toBeCalledWith(10, 10);
expect(element.scroll).toHaveBeenCalledExactlyOnceWith(10, 10);
});

it('should scroll smooth', () => {
Expand All @@ -28,8 +27,7 @@ describe('LandscapeScroller', () => {

landscapeScroller.scrollSmooth(element, 10, 10);

expect(element.scroll).toHaveBeenCalledTimes(1);
expect(element.scroll).toBeCalledWith({ left: 10, top: 10, behavior: 'smooth' });
expect(element.scroll).toHaveBeenCalledExactlyOnceWith({ left: 10, top: 10, behavior: 'smooth' });
});

it('should scroll into view', () => {
Expand All @@ -38,7 +36,6 @@ describe('LandscapeScroller', () => {

landscapeScroller.scrollIntoView(element);

expect(element.scrollIntoView).toHaveBeenCalledTimes(1);
expect(element.scrollIntoView).toBeCalledWith({ behavior: 'smooth', block: 'center', inline: 'center' });
expect(element.scrollIntoView).toHaveBeenCalledExactlyOnceWith({ behavior: 'smooth', block: 'center', inline: 'center' });
});
});
Loading

0 comments on commit 61396de

Please sign in to comment.