Skip to content

Commit

Permalink
Merge branch 'main' into EW-1083
Browse files Browse the repository at this point in the history
  • Loading branch information
SimoneRadtke-Cap authored Jan 30, 2025
2 parents c39bbf5 + 8c78cd2 commit d26f9f6
Show file tree
Hide file tree
Showing 9 changed files with 67 additions and 101 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ export type CommonCartridgeFileParserOptions = {
export const DEFAULT_FILE_PARSER_OPTIONS: CommonCartridgeFileParserOptions = {
maxSearchDepth: 5,
pathSeparator: '/',
inputFormat: InputFormat.RICH_TEXT_CK5,
inputFormat: InputFormat.RICH_TEXT_CK4,
};

export type CommonCartridgeOrganizationProps = {
Expand All @@ -27,7 +27,6 @@ export type CommonCartridgeOrganizationProps = {

export type CommonCartridgeWebContentResourceProps = {
type: CommonCartridgeResourceTypeV1P1.WEB_CONTENT;
title: string;
html: string;
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,6 @@ describe('CommonCartridgeResourceFactory', () => {

expect(result).toStrictEqual({
type: CommonCartridgeResourceTypeV1P1.WEB_CONTENT,
title: organizationProps.title,
html: '<p>Content</p>',
});
});
Expand All @@ -191,7 +190,6 @@ describe('CommonCartridgeResourceFactory', () => {

expect(result).toStrictEqual({
type: CommonCartridgeResourceTypeV1P1.WEB_CONTENT,
title: organizationProps.title,
html: '',
});
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ export class CommonCartridgeResourceFactory {
case CommonCartridgeResourceTypeV1P1.WEB_LINK:
return this.createWebLinkResource(content, title);
case CommonCartridgeResourceTypeV1P1.WEB_CONTENT:
return this.createWebContentResource(content, title, inputFormat);
return this.createWebContentResource(content, inputFormat);
default:
return undefined;
}
Expand Down Expand Up @@ -59,7 +59,6 @@ export class CommonCartridgeResourceFactory {

private createWebContentResource(
content: string,
title: string,
inputFormat: InputFormat
): CommonCartridgeWebContentResourceProps | undefined {
const document = this.tryCreateDocument(content, 'text/html');
Expand All @@ -72,7 +71,6 @@ export class CommonCartridgeResourceFactory {

return {
type: CommonCartridgeResourceTypeV1P1.WEB_CONTENT,
title,
html,
};
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,7 @@ describe('CommonCartridgeExportMapper', () => {
expect(result).toEqual({
identifier: `i${task.id}`,
title: task.name,
html: `<h1>${task.name}</h1><p>${task.description ?? ''}</p>`,
html: `<p>${task.description ?? ''}</p>`,
intendedUse: CommonCartridgeIntendedUseType.UNSPECIFIED,
type: CommonCartridgeResourceType.WEB_CONTENT,
});
Expand All @@ -252,7 +252,7 @@ describe('CommonCartridgeExportMapper', () => {
expect(result).toEqual({
identifier: `i${task.id}`,
title: task.name,
html: `<h1>${task.name}</h1><p>${task.description ?? ''}</p>`,
html: `<p>${task.description ?? ''}</p>`,
intendedUse: CommonCartridgeIntendedUseType.ASSIGNMENT,
type: CommonCartridgeResourceType.WEB_CONTENT,
});
Expand All @@ -267,7 +267,7 @@ describe('CommonCartridgeExportMapper', () => {
expect(result).toEqual({
identifier: `i${task.id}`,
title: task.name,
html: `<h1>${task.name}</h1><p>${task.description ?? ''}</p>`,
html: `<p>${task.description ?? ''}</p>`,
intendedUse: CommonCartridgeIntendedUseType.UNSPECIFIED,
type: CommonCartridgeResourceType.WEB_CONTENT,
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,9 +64,7 @@ export class CommonCartridgeExportMapper {
type: CommonCartridgeResourceType.WEB_CONTENT,
identifier: createIdentifier(lessonContent.id),
title: lessonContent.title,
html: `<h1>${lessonContent.title ?? ''}</h1><p>${
(lessonContent.content as ComponentTextPropsDto).text ?? ''
}</p>`,
html: `<p>${(lessonContent.content as ComponentTextPropsDto).text ?? ''}</p>`,
intendedUse: CommonCartridgeIntendedUseType.UNSPECIFIED,
};
case LessonContentDtoComponentValues.GEO_GEBRA:
Expand Down Expand Up @@ -146,7 +144,7 @@ export class CommonCartridgeExportMapper {
type: CommonCartridgeResourceType.WEB_CONTENT,
identifier: createIdentifier(task.id),
title: task.name,
html: `<h1>${task.name}</h1><p>${task.description ?? ''}</p>`,
html: `<p>${task.description ?? ''}</p>`,
intendedUse,
};
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,34 +60,34 @@ describe('CommonCartridgeImportMapper', () => {
});
});
});
});

describe('mapOrganizationToCard', () => {
describe('when organization is provided', () => {
describe('when organization is provided and withTitle is false', () => {
const setup = () => setupOrganization();

it('should map organization to card', () => {
it('should set the title to an empty string', () => {
const { organization } = setup();

const result = sut.mapOrganizationToCard(organization);
const result = sut.mapOrganizationToCard(organization, false);

expect(result).toEqual({
title: organization.title,
title: '',
height: 150,
});
});
});
});

describe('when organization is provided and withTitle is false', () => {
describe('mapOrganizationToCard', () => {
describe('when organization is provided', () => {
const setup = () => setupOrganization();

it('should set the title to an empty string', () => {
it('should map organization to card', () => {
const { organization } = setup();

const result = sut.mapOrganizationToCard(organization, false);
const result = sut.mapOrganizationToCard(organization);

expect(result).toEqual({
title: '',
title: organization.title,
height: 150,
});
});
Expand All @@ -105,7 +105,7 @@ describe('CommonCartridgeImportMapper', () => {
const result = sut.mapOrganizationToTextElement(organization);

expect(result).toBeInstanceOf(RichTextContentBody);
expect(result).toEqual<RichTextContentBody>({
expect(result).toEqual({
text: `<b>${organization.title}</b>`,
inputFormat: InputFormat.RICH_TEXT_CK5_SIMPLE,
});
Expand Down Expand Up @@ -156,16 +156,15 @@ describe('CommonCartridgeImportMapper', () => {
it('should return rich text content element body', () => {
const resource: CommonCartridgeImportResourceProps = {
type: CommonCartridgeResourceTypeV1P1.WEB_CONTENT,
title: faker.lorem.words(3),
html: faker.lorem.paragraph(),
};

const result = sut.mapResourceToContentElementBody(resource);

expect(result).toBeInstanceOf(RichTextContentBody);
expect(result).toEqual<RichTextContentBody>({
inputFormat: InputFormat.RICH_TEXT_CK4,
text: resource.html,
inputFormat: InputFormat.RICH_TEXT_CK5_SIMPLE,
});
});
});
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { AnyElementContentBody, ContentElementType, LinkContentBody, RichTextContentBody } from '@modules/board';
import { CardProps, ColumnProps } from '@modules/board/domain';
import {
CommonCartridgeImportResourceProps,
CommonCartridgeImportWebContentResourceProps,
Expand All @@ -11,17 +12,18 @@ import { InputFormat } from '@shared/domain/types';

@Injectable()
export class CommonCartridgeImportMapper {
public mapOrganizationToColumn(organization: CommonCartridgeOrganizationProps) {
return {
public mapOrganizationToColumn(organization: CommonCartridgeOrganizationProps): Partial<ColumnProps> {
const column = {
title: organization.title,
};

return column;
}

public mapOrganizationToCard(organization: CommonCartridgeOrganizationProps, withTitle = true) {
return {
title: withTitle ? organization.title : '',
height: 150,
};
public mapOrganizationToCard(organization: CommonCartridgeOrganizationProps, withTitle = true): Partial<CardProps> {
const card = { title: withTitle ? organization.title : '', height: 150 };

return card;
}

public mapOrganizationToTextElement(organization: CommonCartridgeOrganizationProps): AnyElementContentBody {
Expand Down Expand Up @@ -69,7 +71,7 @@ export class CommonCartridgeImportMapper {
const body = new RichTextContentBody();

body.text = resource.html;
body.inputFormat = InputFormat.RICH_TEXT_CK5_SIMPLE;
body.inputFormat = InputFormat.RICH_TEXT_CK4;

return body;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,19 +25,14 @@ describe('CommonCartridgeImportService', () => {
const board2Title = '';
const board3Title = 'Spaltenboard 1';

const column1ofBoard1Title = 'Test Text';
const column1ofBoard2Title = 'Test Aufgabe';
const column1ofBoard3Title = 'Spalte 1';
const column2ofBoard3Title = 'Spalte 2';
const column3ofBoard3Title = 'Spalte 3';
const column4ofBoard3Title = 'Spalte 4';

const emptyCardTitle = '';
const card1Title = 'Karte 1';
const card2Title = 'Karte 2';
const card3Title = 'Karte 3';
const card4Title = 'Karte 4';

const columnPlaceholderTitle1 = '1';
const columnPlaceholderTitle2 = '2';

// eslint-disable-next-line @typescript-eslint/no-unsafe-return
const objectContainingTitle = (title: string) => expect.objectContaining({ title });

Expand Down Expand Up @@ -122,27 +117,15 @@ describe('CommonCartridgeImportService', () => {

expect(boardNodeServiceMock.addToParent).toHaveBeenCalledWith(
objectContainingTitle(board1Title),
objectContainingTitle(column1ofBoard1Title)
objectContainingTitle(columnPlaceholderTitle1)
);
expect(boardNodeServiceMock.addToParent).toHaveBeenCalledWith(
objectContainingTitle(board2Title),
objectContainingTitle(column1ofBoard2Title)
);
expect(boardNodeServiceMock.addToParent).toHaveBeenCalledWith(
objectContainingTitle(board3Title),
objectContainingTitle(column1ofBoard3Title)
objectContainingTitle(columnPlaceholderTitle1)
);
expect(boardNodeServiceMock.addToParent).toHaveBeenCalledWith(
objectContainingTitle(board3Title),
objectContainingTitle(column2ofBoard3Title)
);
expect(boardNodeServiceMock.addToParent).toHaveBeenCalledWith(
objectContainingTitle(board3Title),
objectContainingTitle(column3ofBoard3Title)
);
expect(boardNodeServiceMock.addToParent).toHaveBeenCalledWith(
objectContainingTitle(board3Title),
objectContainingTitle(column4ofBoard3Title)
objectContainingTitle(columnPlaceholderTitle1)
);
});

Expand All @@ -154,28 +137,20 @@ describe('CommonCartridgeImportService', () => {
expect(spyBuildCard).toHaveBeenCalledTimes(6);

expect(boardNodeServiceMock.addToParent).toHaveBeenCalledWith(
objectContainingTitle(column1ofBoard1Title),
objectContainingTitle(emptyCardTitle)
);
expect(boardNodeServiceMock.addToParent).toHaveBeenCalledWith(
objectContainingTitle(column1ofBoard2Title),
objectContainingTitle(emptyCardTitle)
);
expect(boardNodeServiceMock.addToParent).toHaveBeenCalledWith(
objectContainingTitle(column1ofBoard3Title),
objectContainingTitle(card1Title)
objectContainingTitle(board1Title),
objectContainingTitle(columnPlaceholderTitle1)
);
expect(boardNodeServiceMock.addToParent).toHaveBeenCalledWith(
objectContainingTitle(column2ofBoard3Title),
objectContainingTitle(card2Title)
objectContainingTitle(board2Title),
objectContainingTitle(columnPlaceholderTitle1)
);
expect(boardNodeServiceMock.addToParent).toHaveBeenCalledWith(
objectContainingTitle(column3ofBoard3Title),
objectContainingTitle(card3Title)
objectContainingTitle(board3Title),
objectContainingTitle(columnPlaceholderTitle1)
);
expect(boardNodeServiceMock.addToParent).toHaveBeenCalledWith(
objectContainingTitle(column4ofBoard3Title),
objectContainingTitle(card4Title)
objectContainingTitle(board3Title),
objectContainingTitle(columnPlaceholderTitle2)
);
});

Expand All @@ -186,10 +161,6 @@ describe('CommonCartridgeImportService', () => {

expect(spyBuildContentElement).toHaveBeenCalledTimes(6);

expect(boardNodeServiceMock.addToParent).toHaveBeenCalledWith(
objectContainingTitle(emptyCardTitle),
expect.any(RichTextElement)
);
expect(boardNodeServiceMock.addToParent).toHaveBeenCalledWith(
objectContainingTitle(card1Title),
expect.any(RichTextElement)
Expand All @@ -209,16 +180,16 @@ describe('CommonCartridgeImportService', () => {
expect(boardNodeServiceMock.updateContent).toHaveBeenCalledTimes(6);

expect(boardNodeServiceMock.updateContent).toHaveBeenCalledWith(expect.any(RichTextElement), {
text: 'Test Text<p></p><p>Dies ist ein Textinhalt.</p><p></p>',
inputFormat: InputFormat.RICH_TEXT_CK5_SIMPLE,
text: '<h1>Test Text</h1><p></p><p>Dies ist ein Textinhalt.</p><p></p>',
inputFormat: InputFormat.RICH_TEXT_CK4,
});
expect(boardNodeServiceMock.updateContent).toHaveBeenCalledWith(expect.any(RichTextElement), {
text: 'Test Aufgabe<p></p>',
inputFormat: InputFormat.RICH_TEXT_CK5_SIMPLE,
text: '<h1>Test Aufgabe</h1><p></p>',
inputFormat: InputFormat.RICH_TEXT_CK4,
});
expect(boardNodeServiceMock.updateContent).toHaveBeenCalledWith(expect.any(RichTextElement), {
text: '<p></p><p>Karteninhalt von Karte 1</p><p></p>',
inputFormat: InputFormat.RICH_TEXT_CK5_SIMPLE,
inputFormat: InputFormat.RICH_TEXT_CK4,
});
expect(boardNodeServiceMock.updateContent).toHaveBeenCalledWith(expect.any(LinkElement), {
title: 'Example Domain',
Expand Down
Loading

0 comments on commit d26f9f6

Please sign in to comment.