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 7165 include tldraw to the quick links #4985

Merged
merged 13 commits into from
May 8, 2024
Merged
Original file line number Diff line number Diff line change
Expand Up @@ -511,12 +511,12 @@ describe('recursive board copy visitor', () => {
expect(copy.id).not.toEqual(original.id);
});

it('should show status successful', async () => {
it('should show status partial', async () => {
const { original, fileCopyService } = setup();

const result = await service.copy({ original, fileCopyService });

expect(result.status).toEqual(CopyStatusEnum.SUCCESS);
expect(result.status).toEqual(CopyStatusEnum.PARTIAL);
});

it('should show type RichTextElement', async () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ export class RecursiveCopyVisitor implements BoardCompositeVisitorAsync {
this.resultMap.set(original.id, {
copyEntity: copy,
type: CopyElementType.DRAWING_ELEMENT,
status: CopyStatusEnum.SUCCESS,
status: CopyStatusEnum.PARTIAL,
});
this.copyMap.set(original.id, copy);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,21 @@ function createStates(elementStates: CopyStatusEnum[]): CopyStatus[] {
return elementState;
});
}
function createNestedStates(elementStates: CopyStatusEnum[]): CopyStatus {
const elementState = elementStates.shift();
const element: CopyStatus = {
title: `title-${Math.floor(Math.random() * 1000)}-${elementStates.length}`,
type: CopyElementType.LEAF,
status: CopyStatusEnum.SUCCESS,
};

if (elementState) {
element.status = elementState;
element.elements = elementStates.length ? [createNestedStates(elementStates)] : [];
}

return element;
}

describe('copy helper service', () => {
let module: TestingModule;
Expand All @@ -35,6 +50,23 @@ describe('copy helper service', () => {
});

describe('deriveStatusFromElements', () => {
describe('setup cases', () => {
it('should run method multiple times for nested structure', () => {
const derivedStatusSpy = jest.spyOn(copyHelperService, 'deriveStatusFromElements');
const element = createNestedStates([
CopyStatusEnum.SUCCESS,
CopyStatusEnum.SUCCESS,
CopyStatusEnum.SUCCESS,
CopyStatusEnum.SUCCESS,
]);

copyHelperService.deriveStatusFromElements([element]);

expect(derivedStatusSpy).toHaveBeenCalledTimes(4);
derivedStatusSpy.mockRestore();
});
});

describe('successful cases', () => {
it('should return success, if no elements were given', () => {
const derivedStatus = copyHelperService.deriveStatusFromElements([]);
Expand Down Expand Up @@ -90,6 +122,17 @@ describe('copy helper service', () => {
const elements = createStates([CopyStatusEnum.FAIL, CopyStatusEnum.NOT_DOING]);
const derivedStatus = copyHelperService.deriveStatusFromElements(elements);

expect(derivedStatus).toEqual(CopyStatusEnum.FAIL);
});
it('should return fail if the last and only nested child is FAIL ', () => {
const element = createNestedStates([
CopyStatusEnum.SUCCESS,
CopyStatusEnum.SUCCESS,
CopyStatusEnum.SUCCESS,
CopyStatusEnum.FAIL,
]);
const derivedStatus = copyHelperService.deriveStatusFromElements([element]);

expect(derivedStatus).toEqual(CopyStatusEnum.FAIL);
});
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,12 @@ const isAtLeastPartialSuccessfull = (status) => status === CopyStatusEnum.PARTIA
@Injectable()
export class CopyHelperService {
deriveStatusFromElements(elements: CopyStatus[]): CopyStatusEnum {
for (const element of elements) {
if (element.elements?.length) {
element.status = this.deriveStatusFromElements(element.elements);
}
}

VikDavydiuk marked this conversation as resolved.
Show resolved Hide resolved
const elementsStatuses = elements.map((el) => el.status);

const filtered = elementsStatuses.filter((status) => status !== CopyStatusEnum.NOT_DOING);
Expand Down
Loading