Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

BC-3475 - Add alternative text to file content element #4394

Merged
merged 17 commits into from
Sep 21, 2023
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
Show all changes
17 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,16 @@ import { ContentElementType } from '@shared/domain';
import { TimestampsResponse } from '../timestamps.response';

export class FileElementContent {
constructor({ caption }: FileElementContent) {
constructor({ caption, alternativeText }: FileElementContent) {
this.caption = caption;
this.alternativeText = alternativeText;
}

@ApiProperty()
caption: string;

@ApiProperty()
alternativeText?: string;
}

export class FileElementResponse {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { ApiProperty, getSchemaPath } from '@nestjs/swagger';
import { ApiProperty, ApiPropertyOptional, getSchemaPath } from '@nestjs/swagger';
import { ContentElementType, InputFormat } from '@shared/domain';
import { Type } from 'class-transformer';
import { IsDate, IsEnum, IsString, ValidateNested } from 'class-validator';
Expand All @@ -17,6 +17,10 @@ export class FileContentBody {
@IsString()
@ApiProperty({})
caption!: string;

@IsString()
@ApiPropertyOptional()
alternativeText?: string;
}

export class FileElementContentBody extends ElementContentBody {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ export class FileElementResponseMapper implements BaseResponseMapper {
id: element.id,
timestamps: new TimestampsResponse({ lastUpdatedAt: element.updatedAt, createdAt: element.createdAt }),
type: ContentElementType.FILE,
content: new FileElementContent({ caption: element.caption }),
content: new FileElementContent({ caption: element.caption, alternativeText: element.alternativeText }),
});

return result;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@ export class BoardDoBuilderImpl implements BoardDoBuilder {
const element = new FileElement({
id: boardNode.id,
caption: boardNode.caption,
alternativeText: boardNode.alternativeText,
children: [],
createdAt: boardNode.createdAt,
updatedAt: boardNode.updatedAt,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,7 @@ describe(RecursiveSaveVisitor.name, () => {
id: fileElement.id,
type: BoardNodeType.FILE_ELEMENT,
caption: fileElement.caption,
alternativeText: fileElement.alternativeText,
};
expect(visitor.createOrUpdateBoardNode).toHaveBeenCalledWith(expect.objectContaining(expectedNode));
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ export class RecursiveSaveVisitor implements BoardCompositeVisitor {
const boardNode = new FileElementNode({
id: fileElement.id,
caption: fileElement.caption,
alternativeText: fileElement.alternativeText,
parent: parentData?.boardNode,
position: parentData?.position,
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ export class ContentElementUpdateVisitor implements BoardCompositeVisitor {
visitFileElement(fileElement: FileElement): void {
if (this.content instanceof FileContentBody) {
fileElement.caption = this.content.caption;
fileElement.alternativeText = this.content.alternativeText;
} else {
this.throwNotHandled(fileElement);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,7 @@ describe(ContentElementService.name, () => {

const content = new FileContentBody();
content.caption = 'this has been updated';
content.alternativeText = 'this altText has been updated';
const card = cardFactory.build();
boardDoRepo.findParentOfId.mockResolvedValue(card);

Expand All @@ -216,6 +217,7 @@ describe(ContentElementService.name, () => {
await service.update(fileElement, content);

expect(fileElement.caption).toEqual(content.caption);
expect(fileElement.alternativeText).toEqual(content.alternativeText);
});

it('should persist the element', async () => {
Expand Down
2 changes: 1 addition & 1 deletion apps/server/src/modules/board/uc/element.uc.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ describe(ElementUc.name, () => {
const setup = () => {
const user = userFactory.build();
const fileElement = fileElementFactory.build();
const content = { caption: 'this has been updated' };
const content = { caption: 'this has been updated', alternativeText: 'this altText has been updated' };

const elementSpy = elementService.findById.mockResolvedValue(fileElement);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,16 @@ describe(FileElement.name, () => {
});
});

describe('update alternative text', () => {
it('should be able to update alternative text', () => {
const fileElement = fileElementFactory.build();
const text = 'this is the titanic movie from 1997 in Blue-Ray Quality';
fileElement.alternativeText = text;

expect(fileElement.alternativeText).toEqual(text);
});
});

describe('accept', () => {
it('should call the right visitor method', () => {
const visitor = createMock<BoardCompositeVisitor>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,14 @@ export class FileElement extends BoardComposite<FileElementProps> {
this.props.caption = value;
}

get alternativeText(): string | undefined {
return this.props.alternativeText;
}

set alternativeText(value: string | undefined) {
this.props.alternativeText = value;
}

isAllowedAsChild(): boolean {
return false;
}
Expand All @@ -25,4 +33,5 @@ export class FileElement extends BoardComposite<FileElementProps> {

export interface FileElementProps extends BoardCompositeProps {
caption: string;
alternativeText?: string;
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ describe(FileElementNode.name, () => {

describe('useDoBuilder()', () => {
const setup = () => {
const element = new FileElementNode({ caption: 'Test' });
const element = new FileElementNode({ caption: 'Test', alternativeText: 'altTest' });
const builder: DeepMocked<BoardDoBuilder> = createMock<BoardDoBuilder>();
const elementDo = fileElementFactory.build();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,14 @@ export class FileElementNode extends BoardNode {
@Property()
caption: string;

@Property({ nullable: true })
alternativeText?: string;

constructor(props: FileElementNodeProps) {
super(props);
this.type = BoardNodeType.FILE_ELEMENT;
this.caption = props.caption;
this.alternativeText = props.alternativeText;
}

useDoBuilder(builder: BoardDoBuilder): AnyBoardDo {
Expand All @@ -23,4 +27,5 @@ export class FileElementNode extends BoardNode {

export interface FileElementNodeProps extends BoardNodeProps {
caption: string;
alternativeText?: string;
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ export const fileElementNodeFactory = BaseFactory.define<FileElementNode, FileEl
({ sequence }) => {
return {
caption: `caption #${sequence}`,
alternativeText: `alternativeText #${sequence}`,
};
}
);
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ export const fileElementFactory = BaseFactory.define<FileElement, FileElementPro
id: new ObjectId().toHexString(),
children: [],
caption: `<p>caption #${sequence}</p>`,
alternativeText: `alternativeText #${sequence}`,
createdAt: new Date(),
updatedAt: new Date(),
};
Expand Down