blob: 851bed731f10ddd529b6cd4ab2ed43e1b987276e [file] [log] [blame]
/**
* @license
* Copyright 2022 Google LLC
* SPDX-License-Identifier: Apache-2.0
*/
import {assert} from '@open-wc/testing';
import {
BasePatchSetNum,
RepoName,
RevisionPatchSetNum,
} from '../../api/rest-api';
import '../../test/common-test-setup';
import {createDiffViewState} from '../../test/test-data-generators';
import {ChangeViewState} from './change';
import {createDiffUrl} from './diff';
suite('diff view state tests', () => {
test('createDiffUrl', () => {
const params: ChangeViewState = {
...createDiffViewState(),
patchNum: 12 as RevisionPatchSetNum,
diffView: {path: 'x+y/path.cpp'},
};
assert.equal(
createDiffUrl(params),
'/c/test-project/+/42/12/x%252By/path.cpp'
);
window.CANONICAL_PATH = '/base';
assert.equal(createDiffUrl(params).substring(0, 5), '/base');
window.CANONICAL_PATH = undefined;
params.repo = 'test' as RepoName;
assert.equal(createDiffUrl(params), '/c/test/+/42/12/x%252By/path.cpp');
params.basePatchNum = 6 as BasePatchSetNum;
assert.equal(createDiffUrl(params), '/c/test/+/42/6..12/x%252By/path.cpp');
params.diffView = {
path: 'foo bar/my+file.txt%',
};
params.patchNum = 2 as RevisionPatchSetNum;
delete params.basePatchNum;
assert.equal(
createDiffUrl(params),
'/c/test/+/42/2/foo+bar/my%252Bfile.txt%2525'
);
params.diffView = {
path: 'file.cpp',
lineNum: 123,
};
assert.equal(createDiffUrl(params), '/c/test/+/42/2/file.cpp#123');
params.diffView = {
path: 'file.cpp',
lineNum: 123,
leftSide: true,
};
assert.equal(createDiffUrl(params), '/c/test/+/42/2/file.cpp#b123');
});
test('diff with repo name encoding', () => {
const params: ChangeViewState = {
...createDiffViewState(),
patchNum: 12 as RevisionPatchSetNum,
repo: 'x+/y' as RepoName,
diffView: {path: 'x+y/path.cpp'},
};
assert.equal(createDiffUrl(params), '/c/x%252B/y/+/42/12/x%252By/path.cpp');
});
});