Skip to content

Commit 9dd9ca3

Browse files
committed
Use new converters and fix unit tests
1 parent ea6d661 commit 9dd9ca3

File tree

18 files changed

+98
-143
lines changed

18 files changed

+98
-143
lines changed
File renamed without changes.

jest.config.base.js

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
/* eslint-env node */
2+
module.exports = {
3+
testEnvironment: 'jsdom',
4+
rootDir: __dirname,
5+
6+
collectCoverage: true,
7+
collectCoverageFrom: [
8+
'<rootDir>/packages/chords-charts-studio/src/**/*.js',
9+
],
10+
coverageDirectory: '<rootDir>/coverage',
11+
coverageReporters: ['json', 'lcov', 'text', 'clover'],
12+
coverageThreshold: {
13+
global: {
14+
branches: 99,
15+
functions: 99,
16+
lines: 99,
17+
statements: 99,
18+
},
19+
},
20+
21+
transform: {
22+
'\\.js$': 'babel-jest',
23+
'\\.hbs$': 'jest-handlebars',
24+
'\\.txt': 'jest-raw-loader',
25+
},
26+
// whitelisting local modules in the node_modules folder
27+
transformIgnorePatterns: ['<rootDir>.*(node_modules)(?!.*chord-mark.*).*$'],
28+
29+
moduleNameMapper: {
30+
'\\.(css|scss)$': '<rootDir>/tests/styleMock.js',
31+
'\\.(png)$': '<rootDir>/tests/assetMock.js',
32+
},
33+
};

jest.config.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
/* eslint-env node */
2+
const baseConfig = require('./jest.config.base');
3+
4+
module.exports = {
5+
...baseConfig,
6+
projects: ['<rootDir>/packages/*/jest.config.js'],
7+
};
Lines changed: 8 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,16 @@
11
/* eslint-env node */
2+
const baseConfig = require('../../jest.config.base');
3+
const packageJson = require('./package');
4+
25
module.exports = {
3-
testEnvironment: 'jsdom',
6+
...baseConfig,
7+
name: packageJson.name,
8+
displayName: packageJson.name,
49

5-
collectCoverage: true,
6-
collectCoverageFrom: ['src/**/*.js', '!src/main.js', '!**/node_modules/**'],
7-
coverageDirectory: '<rootDir>/coverage',
10+
rootDir: '../..',
811
coveragePathIgnorePatterns: [
9-
'node_modules',
10-
'src/core/createGetVersions.js',
12+
'packages/chord-charts-studio/src/core/createGetVersions.js',
1113
],
12-
coverageReporters: ['json', 'lcov', 'text', 'clover'],
13-
coverageThreshold: {
14-
global: {
15-
branches: 99,
16-
functions: 99,
17-
lines: 99,
18-
statements: 99,
19-
},
20-
},
21-
22-
transform: {
23-
'\\.js$': 'babel-jest',
24-
'\\.hbs$': 'jest-handlebars',
25-
'\\.txt': 'jest-raw-loader',
26-
},
2714

2815
setupFiles: ['jest-localstorage-mock'],
29-
30-
moduleNameMapper: {
31-
'\\.(css|scss)$': '<rootDir>/scss/__mocks__/styleMock.js',
32-
'\\.(png)$': '<rootDir>/assets/__mocks__/assetMock.js',
33-
},
3416
};

packages/chord-charts-studio/src/songImporter/_components/InputFormatSelector.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,16 +5,16 @@ import InputFormatEntry from './InputFormatEntry';
55

66
const allEntries = [
77
{
8-
id: 'basic',
9-
label: 'Basic',
8+
id: 'auto',
9+
label: 'Detect',
1010
},
1111
{
12-
id: 'chordpro',
13-
label: 'ChordPro',
12+
id: 'chordPro',
13+
label: 'Bracketed chords (ChordPro)',
1414
},
1515
{
16-
id: 'ultimateGuitar',
17-
label: 'Ultimate Guitar',
16+
id: 'chordsOverLyrics',
17+
label: 'Chords over lyrics (Ultimate Guitar...)',
1818
},
1919
];
2020

packages/chord-charts-studio/src/songImporter/_components/SongImporter.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,14 @@ import './SongImporter.scss';
33
import React from 'react';
44
import PropTypes from 'prop-types';
55

6+
import { convert2ChordMark } from 'chord-mark-converters';
7+
68
import Modal from '../../ui/_components/Modal';
79
import Header from './Header';
810
import FilePicker from './FilePicker';
911
import Input from './Input';
1012
import PreviewError from './PreviewError';
1113
import InputFormatSelector from './InputFormatSelector';
12-
import input2ChordMark from '../input2ChordMark';
1314
import Icon from '../../ui/_components/Icon';
1415

1516
function SongImporter(props) {
@@ -31,7 +32,7 @@ function SongImporter(props) {
3132
let error = '';
3233

3334
try {
34-
chordMarkContent = input2ChordMark(content, inputFormat);
35+
chordMarkContent = convert2ChordMark(content, { inputFormat });
3536
} catch (e) {
3637
error = e.message;
3738
}

packages/chord-charts-studio/src/songImporter/_state/reducers.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ const initialState = {
77
content: '',
88
isFromWeb: false,
99
isImporting: false,
10-
inputFormat: 'basic',
10+
inputFormat: 'auto',
1111
title: '',
1212
};
1313

packages/chord-charts-studio/tests/integration/optionsPanels/rendering/_containers/Rendering.spec.js

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -307,7 +307,6 @@ describe('"Rendering" option panel', () => {
307307
});
308308

309309
const chordmarkSrc = getByText('ChordMark (Source)');
310-
const chordpro = getByText('ChordPro');
311310

312311
const chartType = getByText(
313312
preferencesWidgets.chartType.label + ':'
@@ -333,15 +332,6 @@ describe('"Rendering" option panel', () => {
333332
expect(isDisabled(alignChordsWithLyrics)).toBe(true);
334333
expect(isDisabled(alignBars)).toBe(true);
335334
expect(isDisabled(autoRepeatChords)).toBe(true);
336-
337-
act(() => {
338-
fireEvent.click(chordpro);
339-
});
340-
341-
expect(isDisabled(chartType, true)).toBe(true);
342-
expect(isDisabled(alignChordsWithLyrics)).toBe(true);
343-
expect(isDisabled(alignBars)).toBe(true);
344-
expect(isDisabled(autoRepeatChords)).toBe(true);
345335
});
346336
});
347337
});

packages/chord-charts-studio/tests/integration/songImporter/_containers/SongImporter.spec.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ describe('SongImporter', () => {
9191
test('should import a song from a website', () => {
9292
dispatch(
9393
startImportFromWeb(
94-
'chordpro',
94+
'chordPro',
9595
'[A]Amazing [D7]grace',
9696
'Amazing Grace'
9797
)

packages/chord-charts-studio/tests/unit/SongRenderers/_components/SongRenderer.spec.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ describe('SongRenderer', () => {
5858
);
5959

6060
expect(container.firstChild.firstChild.innerHTML).toBe(
61-
'<p>&nbsp;</p><p>[A]mySong</p>'
61+
'<p>[|] [A]mySong [|]</p>'
6262
);
6363
});
6464
});

packages/chord-charts-studio/tests/unit/core/renderSong.spec.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ describe('renderAsHtml()', () => {
5353
const input = 'A\n_mySong\n';
5454
const rendered = renderAsHtml(input, { chartFormat: 'chordpro' }, true);
5555

56-
expect(rendered).toEqual('<p>[A]mySong</p><p>&nbsp;</p>');
56+
expect(rendered).toEqual('<p>[|] [A]mySong [|]</p>');
5757
});
5858

5959
test('Should return ChordMark source html with useChartFormat === true & chartFormat === chordmarkSrc', () => {
@@ -98,7 +98,7 @@ describe('renderAsText()', () => {
9898
const input = 'A\n_mySong\n';
9999
const rendered = renderAsText(input, { chartFormat: 'chordpro' }, true);
100100

101-
expect(rendered).toEqual('[A]mySong\n');
101+
expect(rendered).toEqual('[|] [A]mySong [|]');
102102
});
103103

104104
test('Should return ChordMark source text with useChartFormat === true & chartFormat === chordmarkSrc', () => {

packages/chord-charts-studio/tests/unit/fileManager/exportSelectedFileAsText.spec.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ describe('exportSelectedFileAsText', () => {
8080
expect(filename).toBe('aSong - anArtist.cho');
8181

8282
const fileContent = await blobToTxt(blob);
83-
expect(fileContent).toBe('[A]mySong\n');
83+
expect(fileContent).toBe('[|] [A]mySong [|]');
8484
});
8585
});
8686

packages/chord-charts-studio/tests/unit/songImporter/_components/SongImporter.spec.js

Lines changed: 33 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
1-
jest.mock('../../../../src/songImporter/input2ChordMark');
1+
jest.mock('chord-mark-converters');
22
import React from 'react';
33

44
import { render, cleanup, waitFor } from '@testing-library/react';
55
import '@testing-library/jest-dom/extend-expect';
66
import userEvent from '@testing-library/user-event';
77

88
import SongImporter from '../../../../src/songImporter/_components/SongImporter';
9-
import input2ChordMark from '../../../../src/songImporter/input2ChordMark';
9+
import { convert2ChordMark } from 'chord-mark-converters';
1010

1111
afterEach(cleanup);
1212

@@ -36,7 +36,7 @@ describe('SongImporter', () => {
3636
importFile.mockReset();
3737
setContent.mockReset();
3838
setInputFormat.mockReset();
39-
input2ChordMark.mockImplementation((input) => input);
39+
convert2ChordMark.mockImplementation((input) => input);
4040
});
4141

4242
test('should not render import modal if isImporting = false', () => {
@@ -95,7 +95,7 @@ describe('SongImporter', () => {
9595
});
9696

9797
test('should be disabled in case of parsing error', () => {
98-
input2ChordMark.mockImplementation(() => {
98+
convert2ChordMark.mockImplementation(() => {
9999
throw new Error('Parsing Error');
100100
});
101101
const { getByText } = render(<SongImporter {...props} />);
@@ -156,15 +156,15 @@ describe('SongImporter', () => {
156156

157157
describe('Preview box', () => {
158158
test('Should display converted input', () => {
159-
input2ChordMark.mockImplementation(
159+
convert2ChordMark.mockImplementation(
160160
(input) => 'converted input ' + input
161161
);
162162
const { getByText } = render(<SongImporter {...props} />);
163163
expect(getByText('converted input myContent')).toBeInTheDocument();
164164
});
165165

166166
test('Should display error if input2chordmark fails', () => {
167-
input2ChordMark.mockImplementation(() => {
167+
convert2ChordMark.mockImplementation(() => {
168168
throw new Error('This is a parsing Error!');
169169
});
170170
const { getByText } = render(<SongImporter {...props} />);
@@ -177,50 +177,57 @@ describe('SongImporter', () => {
177177
describe('Input format selector', () => {
178178
test('Should set proper value on click', () => {
179179
const { getByLabelText, rerender } = render(
180-
<SongImporter {...props} inputFormat={'basic'} />
180+
<SongImporter {...props} inputFormat={'auto'} />
181+
);
182+
const auto = getByLabelText('Detect');
183+
const chordpro = getByLabelText('Bracketed chords (ChordPro)');
184+
const chordsOverLyrics = getByLabelText(
185+
'Chords over lyrics (Ultimate Guitar...)'
181186
);
182-
const basic = getByLabelText('Basic');
183-
const chordpro = getByLabelText('ChordPro');
184-
const ultimateGuitar = getByLabelText('Ultimate Guitar');
185187

186-
expect(basic).toBeChecked();
187-
basic.click();
188+
expect(auto).toBeChecked();
189+
auto.click();
188190
expect(setInputFormat).not.toHaveBeenCalled();
189191

190192
chordpro.click();
191-
ultimateGuitar.click();
193+
chordsOverLyrics.click();
192194

193195
rerender(<SongImporter {...props} inputFormat={'chordpro'} />);
194196

195-
basic.click();
197+
auto.click();
196198

197199
expect(setInputFormat).toHaveBeenCalledTimes(3);
198-
expect(setInputFormat).toHaveBeenNthCalledWith(1, 'chordpro');
199-
expect(setInputFormat).toHaveBeenNthCalledWith(2, 'ultimateGuitar');
200-
expect(setInputFormat).toHaveBeenNthCalledWith(3, 'basic');
200+
expect(setInputFormat).toHaveBeenNthCalledWith(1, 'chordPro');
201+
expect(setInputFormat).toHaveBeenNthCalledWith(
202+
2,
203+
'chordsOverLyrics'
204+
);
205+
expect(setInputFormat).toHaveBeenNthCalledWith(3, 'auto');
201206
});
202207

203208
test('should be disabled when importing from the web', () => {
204209
const { getByLabelText } = render(
205210
<SongImporter {...props} isFromWeb={true} />
206211
);
207-
const basic = getByLabelText('Basic');
208-
const chordpro = getByLabelText('ChordPro');
209-
const ultimateGuitar = getByLabelText('Ultimate Guitar');
212+
const auto = getByLabelText('Detect');
213+
const chordpro = getByLabelText('Bracketed chords (ChordPro)');
214+
const chordsOverLyrics = getByLabelText(
215+
'Chords over lyrics (Ultimate Guitar...)'
216+
);
210217

211-
expect(basic).not.toBeDisabled();
218+
expect(auto).not.toBeDisabled();
212219
expect(chordpro).not.toBeDisabled();
213-
expect(ultimateGuitar).not.toBeDisabled();
220+
expect(chordsOverLyrics).not.toBeDisabled();
214221

215-
expect(basic).toHaveClass('sim-InputFormat_Entry-Disabled');
222+
expect(auto).toHaveClass('sim-InputFormat_Entry-Disabled');
216223
expect(chordpro).toHaveClass('sim-InputFormat_Entry-Disabled');
217-
expect(ultimateGuitar).toHaveClass(
224+
expect(chordsOverLyrics).toHaveClass(
218225
'sim-InputFormat_Entry-Disabled'
219226
);
220227

221-
basic.click();
228+
auto.click();
222229
chordpro.click();
223-
ultimateGuitar.click();
230+
chordsOverLyrics.click();
224231

225232
expect(setInputFormat).not.toHaveBeenCalled();
226233
});

packages/chord-charts-studio/tests/unit/songImporter/_state/reducers.spec.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,7 @@ describe('songImporter: reducers', () => {
162162
...initialState,
163163
content: '',
164164
title: '',
165-
inputFormat: 'basic',
165+
inputFormat: 'auto',
166166
isImporting: true,
167167
isFromWeb: false,
168168
};

0 commit comments

Comments
 (0)