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

Apiview token changes #8851

Merged
merged 5 commits into from
Aug 23, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
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 @@ -8,6 +8,8 @@ import contentWithDiffNodes from "./test-data/content-with-diff-nodes.json";
import contentWithDiffInOnlyDocs from "./test-data/content-with-diff-in-only-docs.json";
import contentWithActiveOnly from "./test-data/content-with-active-revision-only.json";
import contentWithFullDiff from "./test-data/content-with-diff-full-style.json";
import contentWithAddedOnly from "./test-data/content-with-only-added-diff.json";
import contentWithRemovedOnly from "./test-data/content-with-only-removed-diff.json";

describe('API Tree Builder', () => {
let httpMock: HttpTestingController;
Expand Down Expand Up @@ -151,7 +153,7 @@ describe('API Tree Builder', () => {
apiTreeBuilder.postMessage(arrayBuffer);
});

it('test number lines without docs', (done) => {
it('test number lines in no diff without docs', (done) => {
apiTreeBuilder.onmessage = ({ data }) => {
if (data.directive === ReviewPageWorkerMessageDirective.UpdateCodePanelRowData) {
const codePanelRowData = data.payload as CodePanelRowData[];
Expand Down Expand Up @@ -182,6 +184,38 @@ describe('API Tree Builder', () => {
apiTreeBuilder.postMessage(arrayBuffer);
});

it('test number lines in no diff with docs', (done) => {
apiTreeBuilder.onmessage = ({ data }) => {
if (data.directive === ReviewPageWorkerMessageDirective.UpdateCodePanelRowData) {
const codePanelRowData = data.payload as CodePanelRowData[];
expect(codePanelRowData.length).toBe(162);
const linesWithDiff = codePanelRowData.filter(row => row.diffKind === 'removed' || row.diffKind === 'added');
expect(linesWithDiff.length).toBe(0);
}
done();
};

apiTreeBuilder.onerror = (error) => {
done.fail(error.message);
};

const apiTreeBuilderData : ApiTreeBuilderData = {
diffStyle: 'full',
showDocumentation: true,
showComments: false,
showSystemComments: false,
showHiddenApis: false
};

const jsonString = JSON.stringify(contentWithActiveOnly);
const encoder = new TextEncoder();
const arrayBuffer = encoder.encode(jsonString).buffer;

apiTreeBuilder.postMessage(apiTreeBuilderData);
apiTreeBuilder.postMessage(arrayBuffer);
});


it('test diff lines in full diff without docs', (done) => {
apiTreeBuilder.onmessage = ({ data }) => {
if (data.directive === ReviewPageWorkerMessageDirective.UpdateCodePanelRowData) {
Expand Down Expand Up @@ -243,4 +277,127 @@ describe('API Tree Builder', () => {
apiTreeBuilder.postMessage(apiTreeBuilderData);
apiTreeBuilder.postMessage(arrayBuffer);
});

it('test diff lines in tree style diff without docs', (done) => {
maririos marked this conversation as resolved.
Show resolved Hide resolved
apiTreeBuilder.onmessage = ({ data }) => {
if (data.directive === ReviewPageWorkerMessageDirective.UpdateCodePanelRowData) {
const codePanelRowData = data.payload as CodePanelRowData[];
expect(codePanelRowData.length).toBe(27);
const linesWithDiff = codePanelRowData.filter(row => row.diffKind === 'removed' || row.diffKind === 'added');
expect(linesWithDiff.length).toBe(9);
}
done();
};

apiTreeBuilder.onerror = (error) => {
done.fail(error.message);
};

const apiTreeBuilderData : ApiTreeBuilderData = {
diffStyle: 'trees',
showDocumentation: false,
showComments: false,
showSystemComments: false,
showHiddenApis: false
};

const jsonString = JSON.stringify(contentWithFullDiff);
const encoder = new TextEncoder();
const arrayBuffer = encoder.encode(jsonString).buffer;

apiTreeBuilder.postMessage(apiTreeBuilderData);
apiTreeBuilder.postMessage(arrayBuffer);
});
it('test diff lines in node style diff without docs', (done) => {
apiTreeBuilder.onmessage = ({ data }) => {
if (data.directive === ReviewPageWorkerMessageDirective.UpdateCodePanelRowData) {
const codePanelRowData = data.payload as CodePanelRowData[];
expect(codePanelRowData.length).toBe(20);
const linesWithDiff = codePanelRowData.filter(row => row.diffKind === 'removed' || row.diffKind === 'added');
expect(linesWithDiff.length).toBe(9);
}
done();
};

apiTreeBuilder.onerror = (error) => {
done.fail(error.message);
};

const apiTreeBuilderData : ApiTreeBuilderData = {
diffStyle: 'nodes',
showDocumentation: false,
showComments: false,
showSystemComments: false,
showHiddenApis: false
};

const jsonString = JSON.stringify(contentWithFullDiff);
const encoder = new TextEncoder();
const arrayBuffer = encoder.encode(jsonString).buffer;

apiTreeBuilder.postMessage(apiTreeBuilderData);
apiTreeBuilder.postMessage(arrayBuffer);
});

it('test diff lines with added diff only', (done) => {
apiTreeBuilder.onmessage = ({ data }) => {
if (data.directive === ReviewPageWorkerMessageDirective.UpdateCodePanelRowData) {
const codePanelRowData = data.payload as CodePanelRowData[];
expect(codePanelRowData.length).toBe(460);
const linesWithDiff = codePanelRowData.filter(row => row.diffKind === 'removed' || row.diffKind === 'added');
expect(linesWithDiff.length).toBe(1);
}
done();
};

apiTreeBuilder.onerror = (error) => {
done.fail(error.message);
};

const apiTreeBuilderData : ApiTreeBuilderData = {
diffStyle: 'full',
showDocumentation: false,
showComments: false,
showSystemComments: false,
showHiddenApis: false
};

const jsonString = JSON.stringify(contentWithAddedOnly);
const encoder = new TextEncoder();
const arrayBuffer = encoder.encode(jsonString).buffer;

apiTreeBuilder.postMessage(apiTreeBuilderData);
apiTreeBuilder.postMessage(arrayBuffer);
});

it('test diff lines with removed diff only', (done) => {
apiTreeBuilder.onmessage = ({ data }) => {
if (data.directive === ReviewPageWorkerMessageDirective.UpdateCodePanelRowData) {
const codePanelRowData = data.payload as CodePanelRowData[];
expect(codePanelRowData.length).toBe(460);
const linesWithDiff = codePanelRowData.filter(row => row.diffKind === 'removed' || row.diffKind === 'added');
expect(linesWithDiff.length).toBe(1);
}
done();
};

apiTreeBuilder.onerror = (error) => {
done.fail(error.message);
};

const apiTreeBuilderData : ApiTreeBuilderData = {
diffStyle: 'full',
showDocumentation: false,
showComments: false,
showSystemComments: false,
showHiddenApis: false
};

const jsonString = JSON.stringify(contentWithRemovedOnly);
const encoder = new TextEncoder();
const arrayBuffer = encoder.encode(jsonString).buffer;

apiTreeBuilder.postMessage(apiTreeBuilderData);
apiTreeBuilder.postMessage(arrayBuffer);
});
});
Loading