Skip to content

Commit

Permalink
Development: Merge test classes for same service (#9359)
Browse files Browse the repository at this point in the history
  • Loading branch information
Strohgelaender authored Sep 27, 2024
1 parent 37a20f1 commit 3a8b738
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 53 deletions.
2 changes: 1 addition & 1 deletion jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ module.exports = {
},
],
},
modulePathIgnorePatterns: [],
modulePathIgnorePatterns: ['<rootDir>/src/main/resources/templates/'],
testTimeout: 3000,
testMatch: [
'<rootDir>/src/test/javascript/spec/component/**/*.spec.ts',
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { TestBed } from '@angular/core/testing';
import { TestBed, fakeAsync } from '@angular/core/testing';
import { TranslateModule } from '@ngx-translate/core';
import { ShortAnswerQuestionUtil } from 'app/exercises/quiz/shared/short-answer-question-util.service';
import { ArtemisTestModule } from '../test.module';
import { ArtemisTestModule } from '../../../test.module';
import { ShortAnswerQuestion } from 'app/entities/quiz/short-answer-question.model';
import { ShortAnswerSpot } from 'app/entities/quiz/short-answer-spot.model';
import { ShortAnswerMapping } from 'app/entities/quiz/short-answer-mapping.model';
Expand Down Expand Up @@ -208,4 +208,42 @@ describe('ShortAnswerQuestionUtil', () => {
expect(textPartsInHTML[3][0]).toContain(`<p>[-spot 2]</p>`);
expect(textPartsInHTML[3][1]).toContain(`<p>test3</p>`);
});

it('should transform text parts to html correctly', fakeAsync(() => {
const originalTextParts1 = [['random text'], [' some more text', '[-spot 1]'], ['last paragraph']];
const formattedTextParts1 = [['<p>random text</p>'], ['<p>&nbsp;&nbsp;&nbsp;&nbsp;some more text</p>', '<p>[-spot 1]</p>'], ['<p>last paragraph</p>']];
expect(service.transformTextPartsIntoHTML(originalTextParts1)).toEqual(formattedTextParts1);
const originalTextParts2 = [['`random code`'], ['` some more code`', '[-spot 1]'], ['`last code paragraph`']];
const formattedTextParts2 = [
['<p><code>random code</code></p>'],
['<p><code>&nbsp;&nbsp;&nbsp;&nbsp;some more code</code></p>', '<p>[-spot 1]</p>'],
['<p><code>last code paragraph</code></p>'],
];
expect(service.transformTextPartsIntoHTML(originalTextParts2)).toEqual(formattedTextParts2);
const originalTextParts3 = [['`random code`'], [' [-spot 1]', '`some more code`', '[-spot 1]'], ['`last code paragraph`']];
const formattedTextParts3 = [
['<p><code>random code</code></p>'],
['<p>&nbsp;&nbsp;&nbsp;&nbsp;[-spot 1]</p>', '<p><code>some more code</code></p>', '<p>[-spot 1]</p>'],
['<p><code>last code paragraph</code></p>'],
];
expect(service.transformTextPartsIntoHTML(originalTextParts3)).toEqual(formattedTextParts3);
}));

it('should return the correct indentation', fakeAsync(() => {
const sentence1 = ' this is a test';
const sentence2 = ' `another test`';
const sentence3 = '`last test`';
expect(service.getIndentation(sentence1)).toBe(' ');
expect(service.getIndentation(sentence2)).toBe(' ');
expect(service.getIndentation(sentence3)).toBe('');
}));

it('should return first word of a sentence', fakeAsync(() => {
const sentence1 = ' this is a test';
const sentence2 = ' `another test`';
const sentence3 = '';
expect(service.getFirstWord(sentence1)).toBe('this');
expect(service.getFirstWord(sentence2)).toBe('another');
expect(service.getFirstWord(sentence3)).toBe('');
}));
});

This file was deleted.

0 comments on commit 3a8b738

Please sign in to comment.