Skip to content

Commit

Permalink
Migrate components/images tests to jest
Browse files Browse the repository at this point in the history
  • Loading branch information
tkleinke committed Jul 5, 2024
1 parent 2970bac commit 9f8393a
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 9 deletions.
1 change: 1 addition & 0 deletions desktop/jest.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,7 @@ const config: Config = {

// The glob patterns Jest uses to detect test files
testMatch: [
'<rootDir>/test/unit/components/images/**/*.spec.ts',
'<rootDir>/test/unit/components/import/**/*.spec.ts',
'<rootDir>/test/unit/components/java/**/*.spec.ts',
'<rootDir>/test/unit/components/matrix/**/*.spec.ts',
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { describe, expect, test } from '@jest/globals';
import { constructGrid } from '../../../../../src/app/components/image/grid/construct-grid';


Expand All @@ -19,15 +20,15 @@ describe('constructGrid', () => {
}];


it('should keep the aspect ration of an image', ()=> {
test('should keep the aspect ration of an image', ()=> {

const rows = constructGrid(documents as any,4,800, 20);

expect(rows[0][0].calculatedWidth).toBe(rows[0][0].calculatedHeight * 2);
});


it('should throw when nrOfColumns not integer', () => {
test('should throw when nrOfColumns not integer', () => {

expect(function(){constructGrid([],4.1,0, 20)}).toThrow();
});
Expand Down
9 changes: 5 additions & 4 deletions desktop/test/unit/components/images/row/image-row.spec.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { describe, expect, test } from '@jest/globals';
import { ImageDocument } from 'idai-field-core';
import { ImageRow } from '../../../../../src/app/components/image/row/image-row';

Expand Down Expand Up @@ -26,7 +27,7 @@ describe('ImageRow', () => {
] as unknown as Array<ImageDocument>;


it('switch pages', () => {
test('switch pages', () => {

const imageRow = new ImageRow(300, 100, 300, imageDocuments);

Expand Down Expand Up @@ -62,7 +63,7 @@ describe('ImageRow', () => {
});


it('switch pages to show selected image', () => {
test('switch pages to show selected image', () => {

const imageRow = new ImageRow(300, 100, 300, imageDocuments);

Expand All @@ -78,7 +79,7 @@ describe('ImageRow', () => {
});


it('change width', () => {
test('change width', () => {

const imageRow = new ImageRow(150, 100, 300, imageDocuments);

Expand All @@ -94,7 +95,7 @@ describe('ImageRow', () => {
});


it('return correct values for hasNextPage and hasPreviousPage', () => {
test('return correct values for hasNextPage and hasPreviousPage', () => {

const imageRow = new ImageRow(300, 100, 300, imageDocuments);

Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { describe, expect, test } from '@jest/globals';
import { ImageWidthCalculator } from '../../../../../src/app/components/image/row/image-width-calculator';


Expand All @@ -6,7 +7,7 @@ import { ImageWidthCalculator } from '../../../../../src/app/components/image/ro
*/
describe('ImageWidthCalculator', () => {

it('calculate width', () => {
test('calculate width', () => {

expect(
ImageWidthCalculator.computeWidth(200, 100, 50, 1000)
Expand All @@ -18,15 +19,15 @@ describe('ImageWidthCalculator', () => {
});


it('round results', () => {
test('round results', () => {

expect(
ImageWidthCalculator.computeWidth(1900, 490, 50, 1000)
).toBe(194);
});


it('consider max width', () => {
test('consider max width', () => {

expect(
ImageWidthCalculator.computeWidth(500, 100, 50, 100)
Expand Down

0 comments on commit 9f8393a

Please sign in to comment.