UNPKG

step-sequence-generator

Version:

A step sequence generator for figure skating programs

360 lines (359 loc) 18.2 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); const vitest_1 = require("vitest"); const MovementFactory_js_1 = require("./MovementFactory.js"); const Movement_js_1 = require("./Movement.js"); const movement_enums_js_1 = require("../../shared/enums/movement-enums.js"); const from_object_to_map_js_1 = require("../../utils/converters/from-object-to-map.js"); const column_name_enum_1 = require("../../shared/enums/column-name.enum"); const turn_absolute_name_enum_1 = require("../../shared/enums/turn-absolute-name.enum"); const RIGHT_LEG = 'правая'; const LEFT_LEG = 'левая'; const INNER_EDGE = 'внутреннее'; const OUTER_EDGE = 'наружное'; const TWO_EDGES = 'два ребра'; (0, vitest_1.describe)('MovementFactory', () => { const mockLine = new Map([ ['A', 'name'], ['B', 'правая'], ['C', 'левая'], ['D', 'наружное'], ['E', 'внутреннее'], ['F', '0'], ['G', 0], ['H', '1'], ]); let mockColumnName; (function (mockColumnName) { mockColumnName["NAME"] = "A"; mockColumnName["START_LEG"] = "B"; mockColumnName["END_LEG"] = "C"; mockColumnName["START_EDGE"] = "D"; mockColumnName["END_EDGE"] = "E"; mockColumnName["TRANSLATION_DIRECTION"] = "F"; mockColumnName["ROTATION_DIRECTION"] = "G"; mockColumnName["IS_SPEED_INCREASE"] = "H"; })(mockColumnName || (mockColumnName = {})); (0, vitest_1.describe)('implementation', () => { (0, vitest_1.it)('должен корректно создаваться', () => { const movement = MovementFactory_js_1.MovementFactory.createFromExcelData(mockLine, mockColumnName); (0, vitest_1.expect)(movement).toBeDefined(); (0, vitest_1.expect)(movement).toBeInstanceOf(Movement_js_1.Movement); }); }); (0, vitest_1.describe)('parseName', () => { (0, vitest_1.it)('должен вернуть корректное название элемента', () => { const input = 'name'; const expected = 'name'; const result = getFuncResult('parseName', input); (0, vitest_1.expect)(result).toBe(expected); }); (0, vitest_1.it)('должен вернуть "Неизвестный шаг" для пустой строки', () => { const input = ''; const expected = 'Неизвестный шаг'; const result = getFuncResult('parseName', input); (0, vitest_1.expect)(result).toBe(expected); }); }); // parseName (0, vitest_1.describe)('parseTransitionDirection', () => { (0, vitest_1.it)('должен вернуть TransitionDirection.FORWARD', () => { const input = 0; const expected = movement_enums_js_1.TransitionDirection.FORWARD; const result = getFuncResult('parseTransitionDirection', input); (0, vitest_1.expect)(result).toBe(expected); }); (0, vitest_1.it)('должен вернуть parseTransitionDirection.BACKWARD', () => { const input = 180; const expected = movement_enums_js_1.TransitionDirection.BACKWARD; const result = getFuncResult('parseTransitionDirection', input); (0, vitest_1.expect)(result).toBe(expected); }); (0, vitest_1.it)('должен вернуть parseTransitionDirection.NONE', () => { const input = 'test'; const expected = movement_enums_js_1.TransitionDirection.NONE; const result = getFuncResult('parseTransitionDirection', input); (0, vitest_1.expect)(result).toBe(expected); }); }); (0, vitest_1.describe)('parseRotationDirection', () => { (0, vitest_1.it)('должен вернуть RotationDirection.COUNTERCLOCKWISE', () => { const input = 180; const expected = movement_enums_js_1.RotationDirection.COUNTERCLOCKWISE; const result = getFuncResult('parseRotationDirection', input); (0, vitest_1.expect)(result).toBe(expected); }); (0, vitest_1.it)('должен вернуть RotationDirection.CLOCKWISE', () => { const input = -180; const expected = movement_enums_js_1.RotationDirection.CLOCKWISE; const result = getFuncResult('parseRotationDirection', input); (0, vitest_1.expect)(result).toBe(expected); }); (0, vitest_1.it)('должен вернуть RotationDirection.NONE', () => { const input = 0; const expected = movement_enums_js_1.RotationDirection.NONE; const result = getFuncResult('parseRotationDirection', input); (0, vitest_1.expect)(result).toBe(expected); }); (0, vitest_1.it)('должен выбросить ошибку', () => { const input = 'test'; (0, vitest_1.expect)(() => getFuncResult('parseRotationDirection', input)).toThrowError('from parseRotationDirection: wrong value for rotationDirection'); }); }); (0, vitest_1.describe)('parseRotationDegree', () => { (0, vitest_1.it)('должен вернуть RotationDegree.DEGREE_180', () => { const input = 180; const expected = movement_enums_js_1.RotationDegree.DEGREE_180; const result = getFuncResult('parseRotationDegree', input); (0, vitest_1.expect)(result).toBe(expected); }); (0, vitest_1.it)('должен вернуть RotationDegree.DEGREE_180 при отрицательном повороте', () => { const input = -180; const expected = movement_enums_js_1.RotationDegree.DEGREE_180; const result = getFuncResult('parseRotationDegree', input); (0, vitest_1.expect)(result).toBe(expected); }); (0, vitest_1.it)('должен вернуть RotationDegree.DEGREES_0', () => { const input = 0; const expected = movement_enums_js_1.RotationDegree.DEGREES_0; const result = getFuncResult('parseRotationDegree', input); (0, vitest_1.expect)(result).toBe(expected); }); (0, vitest_1.it)('должен выбросить ошибку', () => { (0, vitest_1.expect)(() => getFuncResult('parseRotationDegree', 'test')).toThrowError('from parseRotationDegree: wrong value for rotationDirection'); }); }); (0, vitest_1.describe)('parseLeg', () => { (0, vitest_1.it)('должен вернуть Leg.BOTH', () => { const input = `${RIGHT_LEG}, ${LEFT_LEG}`; const expected = movement_enums_js_1.Leg.BOTH; const result = getFuncResult('parseLeg', input); (0, vitest_1.expect)(result).toStrictEqual(expected); }); (0, vitest_1.it)('должен вернуть Leg.LEFT', () => { const input = LEFT_LEG; const expected = movement_enums_js_1.Leg.LEFT; const result = getFuncResult('parseLeg', input); (0, vitest_1.expect)(result).toStrictEqual(expected); }); (0, vitest_1.it)('должен вернуть Leg.RIGHT', () => { const input = RIGHT_LEG; const expected = movement_enums_js_1.Leg.RIGHT; const result = getFuncResult('parseLeg', input); (0, vitest_1.expect)(result).toStrictEqual(expected); }); }); (0, vitest_1.describe)('parseIsChangeLeg', () => { (0, vitest_1.it)('должен вернуть false', () => { const input1 = `${RIGHT_LEG}, ${LEFT_LEG}`; const input2 = `${RIGHT_LEG}, ${LEFT_LEG}`; const expected = false; const result = getFuncResult('parseIsChangeLeg', input1, input2); (0, vitest_1.expect)(result).toBe(expected); }); (0, vitest_1.it)('должен вернуть true', () => { const input1 = `${RIGHT_LEG}, ${LEFT_LEG}`; const input2 = RIGHT_LEG; const expected = true; const result = getFuncResult('parseIsChangeLeg', input1, input2); (0, vitest_1.expect)(result).toBe(expected); }); }); (0, vitest_1.describe)('getLegList', () => { (0, vitest_1.it)('должен вернуть массив строк', () => { const input = `${RIGHT_LEG}, ${LEFT_LEG}`; const expected = [LEFT_LEG, RIGHT_LEG]; const result = getFuncResult('getLegList', input); (0, vitest_1.expect)(result).toStrictEqual(expected); }); (0, vitest_1.it)('должен вернуть отсортированный массив строк', () => { const input = '2, 1'; const expected = ['1', '2']; const result = getFuncResult('getLegList', input); (0, vitest_1.expect)(result).toStrictEqual(expected); }); (0, vitest_1.it)('должен вернуть массив строк без пробелов', () => { const input = ' 2 , 1 '; const expected = ['1', '2']; const result = getFuncResult('getLegList', input); (0, vitest_1.expect)(result).toStrictEqual(expected); }); }); (0, vitest_1.describe)('validateLegList', () => { (0, vitest_1.describe)('должен вернуть true', () => { const inputList = [[RIGHT_LEG], [LEFT_LEG]]; const expected = true; vitest_1.test.each(inputList)('должен вернуть true c наличием "%s"', (input) => { const result = getFuncResult('validateLegList', input); (0, vitest_1.expect)(result).toBe(expected); }); }); (0, vitest_1.it)('должен выбросить ошибку при отсутствии в массиве "левая" или "правая"', () => { const input = ['wrongString']; (0, vitest_1.expect)(() => getFuncResult('validateLegList', input)).toThrowError('wrong Leg'); }); }); (0, vitest_1.describe)('parseEdge', () => { (0, vitest_1.it)('должен вернуть Edge.OUTER', () => { const input = OUTER_EDGE; const expected = movement_enums_js_1.Edge.OUTER; const result = getFuncResult('parseEdge', input); (0, vitest_1.expect)(result).toBe(expected); }); (0, vitest_1.it)('должен вернуть Edge.INNER', () => { const input = INNER_EDGE; const expected = movement_enums_js_1.Edge.INNER; const result = getFuncResult('parseEdge', input); (0, vitest_1.expect)(result).toBe(expected); }); (0, vitest_1.it)('должен вернуть Edge.TWO_EDGES', () => { const input = TWO_EDGES; const expected = movement_enums_js_1.Edge.TWO_EDGES; const result = getFuncResult('parseEdge', input); (0, vitest_1.expect)(result).toBe(expected); }); }); (0, vitest_1.describe)('parseIsChangeEdge', () => { (0, vitest_1.it)('должен вернуть true', () => { const input1 = OUTER_EDGE; const input2 = INNER_EDGE; const expected = true; const result = getFuncResult('parseIsChangeEdge', input1, input2); (0, vitest_1.expect)(result).toBe(expected); }); (0, vitest_1.it)('должен вернуть false', () => { const input1 = OUTER_EDGE; const input2 = OUTER_EDGE; const expected = false; const result = getFuncResult('parseIsChangeEdge', input1, input2); (0, vitest_1.expect)(result).toBe(expected); }); }); (0, vitest_1.describe)('validateEdge', () => { (0, vitest_1.describe)('должен вернуть true', () => { const inputList = [INNER_EDGE, OUTER_EDGE, TWO_EDGES]; const expected = true; vitest_1.test.each(inputList)('validateEdge("%s")', (input) => { const result = getFuncResult('validateEdge', input); (0, vitest_1.expect)(result).toBe(expected); }); }); (0, vitest_1.it)('должен выбросить ошибку', () => { const input = 'wrongString'; (0, vitest_1.expect)(() => getFuncResult('validateEdge', input)).toThrowError('wrong value for edge'); }); }); (0, vitest_1.describe)('parseIsSpeedIncrease', () => { (0, vitest_1.it)('должен вернуть true', () => { const input = 1; const expected = true; const result = getFuncResult('parseIsSpeedIncrease', input); (0, vitest_1.expect)(result).toBe(expected); }); (0, vitest_1.it)('должен вернуть false', () => { const input = 0; const expected = false; const result = getFuncResult('parseIsSpeedIncrease', input); (0, vitest_1.expect)(result).toBe(expected); }); (0, vitest_1.it)('должен выбросить ошибку', () => { const input = 'wrongString'; (0, vitest_1.expect)(() => getFuncResult('parseIsSpeedIncrease', input)).toThrowError('wrong value for speedIncrease'); }); }); (0, vitest_1.describe)('parseIsDifficult', () => { (0, vitest_1.it)('должен вернуть true когда value = 1', () => { const input = 1; const expected = true; const result = getFuncResult('parseIsDifficult', input); (0, vitest_1.expect)(result).toBe(expected); }); (0, vitest_1.it)('должен вернуть true когда value = string', () => { const input = 'someString'; const expected = true; const result = getFuncResult('parseIsDifficult', input); (0, vitest_1.expect)(result).toBe(expected); }); (0, vitest_1.it)('должен вернуть false когда value = 0', () => { const input = 0; const expected = false; const result = getFuncResult('parseIsDifficult', input); (0, vitest_1.expect)(result).toBe(expected); }); (0, vitest_1.it)('должен вернуть false когда value = null', () => { const input = null; const expected = false; const result = getFuncResult('parseIsDifficult', input); (0, vitest_1.expect)(result).toBe(expected); }); }); (0, vitest_1.describe)('parseType', () => { // eslint-disable-next-line @typescript-eslint/no-explicit-any let argList; (0, vitest_1.describe)('MovementCharacter.SEQUENCE', () => { argList = ['step', 'turn', 'sequence', 'hop', 'glide', 'unknown']; vitest_1.it.each(argList)('должен возвращать %s', (item) => { const expected = item; const result = getFuncResult('parseType', item); (0, vitest_1.expect)(result).toBe(expected); }); argList = [null, undefined, 'test']; vitest_1.it.each(argList)('должен вернуть UNKNOWN при %s', (arg) => { const result = getFuncResult('parseType', arg); (0, vitest_1.expect)(result !== movement_enums_js_1.MovementCharacter.SEQUENCE).toBeTruthy(); }); }); }); (0, vitest_1.describe)('parse line', () => { (0, vitest_1.it)('должен вернуть new Movement', () => { const lineObj = [ { ID: 'ID134', A: 'чиктао вперёд внутрь с правой', B: 'правая', C: 'левая', D: 'внутреннее', E: 'наружное', F: '0', G: '180', H: '0', I: '', }, ]; const lineMap = (0, from_object_to_map_js_1.convertFromObjectToMap)(lineObj)[0]; const expected = new Movement_js_1.Movement({ id: 'ID134', name: 'чиктао вперёд внутрь с правой', transitionDirection: movement_enums_js_1.TransitionDirection.FORWARD, rotationDirection: movement_enums_js_1.RotationDirection.COUNTERCLOCKWISE, rotationDegree: 180, startLeg: movement_enums_js_1.Leg.RIGHT, endLeg: movement_enums_js_1.Leg.LEFT, isChangeLeg: true, startEdge: movement_enums_js_1.Edge.INNER, endEdge: movement_enums_js_1.Edge.OUTER, isChangeEdge: true, isSpeedIncrease: false, isDifficult: false, type: movement_enums_js_1.MovementCharacter.UNKNOWN, description: '', absoluteName: turn_absolute_name_enum_1.TurnAbsoluteName.UNKNOWN, distance: 1, }); const result = MovementFactory_js_1.MovementFactory.createFromExcelData(lineMap, column_name_enum_1.ColumnName); (0, vitest_1.expect)(result).toStrictEqual(expected); }); }); (0, vitest_1.describe)('parseId', () => { (0, vitest_1.it)('должен вернуть строку без пробелов вначале и конце', () => { const input = ' testLine '; const expected = 'testLine'; const result = getFuncResult('parseId', input); (0, vitest_1.expect)(result).toEqual(expected); }); }); // eslint-disable-next-line @typescript-eslint/no-explicit-any function getFuncResult(funcName, ...args) { // @ts-expect-error-any return MovementFactory_js_1.MovementFactory[`${funcName}`](...args); } });