diff --git a/jest.config.js b/jest.config.js index b4e2303f5e92..c2209766b596 100644 --- a/jest.config.js +++ b/jest.config.js @@ -125,7 +125,7 @@ module.exports = { }, ], }, - modulePathIgnorePatterns: [], + modulePathIgnorePatterns: ['/src/main/resources/templates/'], testTimeout: 3000, testMatch: [ '/src/test/javascript/spec/component/**/*.spec.ts', diff --git a/src/test/javascript/spec/service/short-answer-question-util.service.spec.ts b/src/test/javascript/spec/component/exercises/quiz/short-answer-question-util.service.spec.ts similarity index 80% rename from src/test/javascript/spec/service/short-answer-question-util.service.spec.ts rename to src/test/javascript/spec/component/exercises/quiz/short-answer-question-util.service.spec.ts index 509b42b0f99f..da7e4949bbb3 100644 --- a/src/test/javascript/spec/service/short-answer-question-util.service.spec.ts +++ b/src/test/javascript/spec/component/exercises/quiz/short-answer-question-util.service.spec.ts @@ -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'; @@ -208,4 +208,42 @@ describe('ShortAnswerQuestionUtil', () => { expect(textPartsInHTML[3][0]).toContain(`

[-spot 2]

`); expect(textPartsInHTML[3][1]).toContain(`

test3

`); }); + + it('should transform text parts to html correctly', fakeAsync(() => { + const originalTextParts1 = [['random text'], [' some more text', '[-spot 1]'], ['last paragraph']]; + const formattedTextParts1 = [['

random text

'], ['

    some more text

', '

[-spot 1]

'], ['

last paragraph

']]; + expect(service.transformTextPartsIntoHTML(originalTextParts1)).toEqual(formattedTextParts1); + const originalTextParts2 = [['`random code`'], ['` some more code`', '[-spot 1]'], ['`last code paragraph`']]; + const formattedTextParts2 = [ + ['

random code

'], + ['

    some more code

', '

[-spot 1]

'], + ['

last code paragraph

'], + ]; + expect(service.transformTextPartsIntoHTML(originalTextParts2)).toEqual(formattedTextParts2); + const originalTextParts3 = [['`random code`'], [' [-spot 1]', '`some more code`', '[-spot 1]'], ['`last code paragraph`']]; + const formattedTextParts3 = [ + ['

random code

'], + ['

    [-spot 1]

', '

some more code

', '

[-spot 1]

'], + ['

last code paragraph

'], + ]; + 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(''); + })); }); diff --git a/src/test/javascript/spec/component/short-answer-quiz/short-answer-question-util.service.spec.ts b/src/test/javascript/spec/component/short-answer-quiz/short-answer-question-util.service.spec.ts deleted file mode 100644 index 33fdbbc3ba71..000000000000 --- a/src/test/javascript/spec/component/short-answer-quiz/short-answer-question-util.service.spec.ts +++ /dev/null @@ -1,50 +0,0 @@ -import { ShortAnswerQuestionUtil } from 'app/exercises/quiz/shared/short-answer-question-util.service'; -import { ArtemisMarkdownService } from 'app/shared/markdown.service'; -import { TestBed, fakeAsync } from '@angular/core/testing'; - -describe('ShortAnswerQuestionUtil', () => { - let shortAnswerQuestionUtil: ShortAnswerQuestionUtil; - - beforeEach(fakeAsync(() => { - TestBed.configureTestingModule({ providers: [ArtemisMarkdownService] }); - shortAnswerQuestionUtil = new ShortAnswerQuestionUtil(); - })); - - it('should transform text parts to html correctly', fakeAsync(() => { - const originalTextParts1 = [['random text'], [' some more text', '[-spot 1]'], ['last paragraph']]; - const formattedTextParts1 = [['

random text

'], ['

    some more text

', '

[-spot 1]

'], ['

last paragraph

']]; - expect(shortAnswerQuestionUtil.transformTextPartsIntoHTML(originalTextParts1)).toEqual(formattedTextParts1); - const originalTextParts2 = [['`random code`'], ['` some more code`', '[-spot 1]'], ['`last code paragraph`']]; - const formattedTextParts2 = [ - ['

random code

'], - ['

    some more code

', '

[-spot 1]

'], - ['

last code paragraph

'], - ]; - expect(shortAnswerQuestionUtil.transformTextPartsIntoHTML(originalTextParts2)).toEqual(formattedTextParts2); - const originalTextParts3 = [['`random code`'], [' [-spot 1]', '`some more code`', '[-spot 1]'], ['`last code paragraph`']]; - const formattedTextParts3 = [ - ['

random code

'], - ['

    [-spot 1]

', '

some more code

', '

[-spot 1]

'], - ['

last code paragraph

'], - ]; - expect(shortAnswerQuestionUtil.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(shortAnswerQuestionUtil.getIndentation(sentence1)).toBe(' '); - expect(shortAnswerQuestionUtil.getIndentation(sentence2)).toBe(' '); - expect(shortAnswerQuestionUtil.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(shortAnswerQuestionUtil.getFirstWord(sentence1)).toBe('this'); - expect(shortAnswerQuestionUtil.getFirstWord(sentence2)).toBe('another'); - expect(shortAnswerQuestionUtil.getFirstWord(sentence3)).toBe(''); - })); -});