gql_position_parser.test.ts 1.6 KB
Newer Older
1 2 3 4 5 6
import * as vscode from 'vscode';
import {
  commentRangeFromPosition,
  commitFromPosition,
  pathFromPosition,
} from './gql_position_parser';
7 8 9 10 11 12 13
import { noteOnDiff } from '../../test/integration/fixtures/graphql/discussions.js';
import { GqlTextPosition } from '../gitlab/graphql/shared';

const { position } = noteOnDiff;

const oldPosition = {
  ...position,
14
  oldLine: 5,
15 16 17 18 19 20 21 22 23 24 25
  newLine: null,
  oldPath: 'oldPath.js',
  diffRefs: {
    ...position.diffRefs,
    baseSha: 'abcd',
  },
} as GqlTextPosition;

const newPosition = {
  ...position,
  oldLine: null,
26
  newLine: 20,
27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50
  newPath: 'newPath.js',
  diffRefs: {
    ...position.diffRefs,
    headSha: '1234',
  },
} as GqlTextPosition;

describe('pathFromPosition', () => {
  it('returns old path for old position', () => {
    expect(pathFromPosition(oldPosition)).toBe('oldPath.js');
  });
  it('returns new path for new position', () => {
    expect(pathFromPosition(newPosition)).toBe('newPath.js');
  });
});

describe('commitFromPosition', () => {
  it('returns baseSha for old position', () => {
    expect(commitFromPosition(oldPosition)).toBe('abcd');
  });
  it('returns headSha for new position', () => {
    expect(commitFromPosition(newPosition)).toBe('1234');
  });
});
51 52 53 54 55 56 57 58 59 60 61

describe('commentRangeFromPosition', () => {
  it('returns range with old line', () => {
    const line = new vscode.Position(4, 0);
    expect(commentRangeFromPosition(oldPosition)).toEqual(new vscode.Range(line, line));
  });
  it('returns headSha for new position', () => {
    const line = new vscode.Position(19, 0);
    expect(commentRangeFromPosition(newPosition)).toEqual(new vscode.Range(line, line));
  });
});