Skip to content

Commit

Permalink
Add some extra data and reorganize some data in the intermediary JSON…
Browse files Browse the repository at this point in the history
… file format
  • Loading branch information
ChrisMBarr committed May 4, 2024
1 parent ce0dc10 commit 3dbc19c
Show file tree
Hide file tree
Showing 37 changed files with 499 additions and 121 deletions.
26 changes: 24 additions & 2 deletions src/app/convert/convert.component.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ import { ISong } from './models/song.model';
import { LyricConverterError } from './models/errors.model';

import { TestUtils } from 'test/test-utils';
import { mockStaticTimestamp } from '../../../test/mock-song-objects';
import { version } from '../version';

class MockConverter implements IOutputConverter {
constructor(
Expand Down Expand Up @@ -353,7 +355,13 @@ describe('ConvertComponent', () => {

const outputFile: IOutputFile = {
songData: {
fileName: 'JSON - Your Grace Is Enough',
originalFile: {
extension: 'json',
format: 'JSON',
name: 'JSON - Your Grace Is Enough',
},
lyricConverterVersion: version,
timestamp: mockStaticTimestamp,
title: 'Great is your faithfulness O God',
info: [{ name: 'Order', value: '1C2CBC' }],
slides: [
Expand Down Expand Up @@ -395,6 +403,13 @@ describe('ConvertComponent', () => {
it('should get converters for passed in raw files and list them for Text Type Output', () => {
component.selectedOutputType = new OutputTypePlainText();
component.getConvertersAndExtractData([rawJsonFile]);

//normalize timestamps for comparison
component.convertedSongsForOutput = component.convertedSongsForOutput.map((convertedSong) => {
convertedSong.songData = TestUtils.normalizeSongTimestamp(convertedSong.songData);
return convertedSong;
});

expect(component.convertedSongsForOutput).toEqual([outputFile]);
});

Expand All @@ -403,6 +418,13 @@ describe('ConvertComponent', () => {

component.selectedOutputType = new OutputTypePlainText();
component.getConvertersAndExtractData([rawJsonFile, imageFile]);

//normalize timestamps for comparison
component.convertedSongsForOutput = component.convertedSongsForOutput.map((convertedSong) => {
convertedSong.songData = TestUtils.normalizeSongTimestamp(convertedSong.songData);
return convertedSong;
});

expect(component.convertedSongsForOutput).toEqual([outputFile]);
});
});
Expand Down Expand Up @@ -582,7 +604,7 @@ describe('ConvertComponent', () => {

//@ts-expect-error - we are testing throwing errors so we need this unreachable code
return {
fileName: `${song.fileName}.${this.fileExt!}`,
fileName: `${song.originalFile.name}.${this.fileExt!}`,
outputContent: '',
songData: song,
};
Expand Down
2 changes: 1 addition & 1 deletion src/app/convert/convert.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ export class ConvertComponent implements OnInit {
//Handle any errors that happen downstream on the selected IOutputConverter
this.errorsSvc.add({
message: `There was a problem converting this song to the ${this.selectedOutputType.name} format`,
fileName: s.fileName,
fileName: s.originalFile.name,
thrownError: err,
});
}
Expand Down
79 changes: 65 additions & 14 deletions src/app/convert/inputs/input-type-chordpro.spec.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import { InputTypeChordPro } from './input-type-chordpro';
import { TestUtils } from 'test/test-utils';
import { version } from '../../version';
import { mockStaticTimestamp } from '../../../../test/mock-song-objects';

describe('InputTypeChordPro', () => {
let inputConverter: InputTypeChordPro;
Expand Down Expand Up @@ -65,8 +67,15 @@ describe('InputTypeChordPro', () => {
it('should return a song for "simple" test file', async () => {
const testFile = await TestUtils.loadTestFileAsRawDataFile('ChordPro', 'simple.cho');

expect(inputConverter.extractSongData(testFile)).toEqual({
fileName: testFile.name,
const normalizedSongData = TestUtils.normalizeSongTimestamp(inputConverter.extractSongData(testFile));
expect(normalizedSongData).toEqual({
originalFile: {
extension: inputConverter.fileExt,
format: inputConverter.name,
name: testFile.name,
},
lyricConverterVersion: version,
timestamp: mockStaticTimestamp,
title: 'This is a title',
info: [
{ name: 'artist', value: 'Hymn' },
Expand All @@ -79,8 +88,15 @@ describe('InputTypeChordPro', () => {
it('should return a song for "At the Cross"', async () => {
const testFile = await TestUtils.loadTestFileAsRawDataFile('ChordPro', 'At the Cross.cho');

expect(inputConverter.extractSongData(testFile)).toEqual({
fileName: testFile.name,
const normalizedSongData = TestUtils.normalizeSongTimestamp(inputConverter.extractSongData(testFile));
expect(normalizedSongData).toEqual({
originalFile: {
extension: inputConverter.fileExt,
format: inputConverter.name,
name: testFile.name,
},
lyricConverterVersion: version,
timestamp: mockStaticTimestamp,
title: 'At the Cross',
info: [
{
Expand Down Expand Up @@ -116,8 +132,15 @@ describe('InputTypeChordPro', () => {
it('should return a song for "Our Father"', async () => {
const testFile = await TestUtils.loadTestFileAsRawDataFile('ChordPro', 'Our Father.cho');

expect(inputConverter.extractSongData(testFile)).toEqual({
fileName: testFile.name,
const normalizedSongData = TestUtils.normalizeSongTimestamp(inputConverter.extractSongData(testFile));
expect(normalizedSongData).toEqual({
originalFile: {
extension: inputConverter.fileExt,
format: inputConverter.name,
name: testFile.name,
},
lyricConverterVersion: version,
timestamp: mockStaticTimestamp,
title: 'Our Father',
info: [
{
Expand Down Expand Up @@ -167,8 +190,15 @@ describe('InputTypeChordPro', () => {
it('should return a song for "Swing Low Sweet Chariot"', async () => {
const testFile = await TestUtils.loadTestFileAsRawDataFile('ChordPro', 'Swing Low Sweet Chariot.cho');

expect(inputConverter.extractSongData(testFile)).toEqual({
fileName: testFile.name,
const normalizedSongData = TestUtils.normalizeSongTimestamp(inputConverter.extractSongData(testFile));
expect(normalizedSongData).toEqual({
originalFile: {
extension: inputConverter.fileExt,
format: inputConverter.name,
name: testFile.name,
},
lyricConverterVersion: version,
timestamp: mockStaticTimestamp,
title: 'Swing Low Sweet Chariot',
info: [],
slides: [
Expand All @@ -193,8 +223,15 @@ describe('InputTypeChordPro', () => {
it('should return a song for test file 4 that only uses unlabeled paired directives for "Our Father - unlabeled paired directives"', async () => {
const testFile = await TestUtils.loadTestFileAsRawDataFile('ChordPro', 'Our Father - unlabeled paired directives.cho');

expect(inputConverter.extractSongData(testFile)).toEqual({
fileName: testFile.name,
const normalizedSongData = TestUtils.normalizeSongTimestamp(inputConverter.extractSongData(testFile));
expect(normalizedSongData).toEqual({
originalFile: {
extension: inputConverter.fileExt,
format: inputConverter.name,
name: testFile.name,
},
lyricConverterVersion: version,
timestamp: mockStaticTimestamp,
title: 'Our Father',
info: [
{
Expand Down Expand Up @@ -256,8 +293,15 @@ describe('InputTypeChordPro', () => {
it('should return a song for test file 5 that only uses paired directives with internal labels for "Our Father - directives with internal inline labels"', async () => {
const testFile = await TestUtils.loadTestFileAsRawDataFile('ChordPro', 'Our Father - directives with internal inline labels.cho');

expect(inputConverter.extractSongData(testFile)).toEqual({
fileName: testFile.name,
const normalizedSongData = TestUtils.normalizeSongTimestamp(inputConverter.extractSongData(testFile));
expect(normalizedSongData).toEqual({
originalFile: {
extension: inputConverter.fileExt,
format: inputConverter.name,
name: testFile.name,
},
lyricConverterVersion: version,
timestamp: mockStaticTimestamp,
title: 'Our Father',
info: [
{ name: 'artist', value: 'Bethel Music' },
Expand Down Expand Up @@ -310,8 +354,15 @@ describe('InputTypeChordPro', () => {
it('should return a song for test file 6 that only uses paired directives with internal labels for "Our Father - complex tags"', async () => {
const testFile = await TestUtils.loadTestFileAsRawDataFile('ChordPro', 'Our Father - complex tags.cho');

expect(inputConverter.extractSongData(testFile)).toEqual({
fileName: testFile.name,
const normalizedSongData = TestUtils.normalizeSongTimestamp(inputConverter.extractSongData(testFile));
expect(normalizedSongData).toEqual({
originalFile: {
extension: inputConverter.fileExt,
format: inputConverter.name,
name: testFile.name,
},
lyricConverterVersion: version,
timestamp: mockStaticTimestamp,
title: 'Our Father',
info: [
{ name: 'artist', value: 'Bethel Music' },
Expand Down
9 changes: 8 additions & 1 deletion src/app/convert/inputs/input-type-chordpro.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { ChordLyricsPair, ChordProParser, Paragraph, Tag } from 'chordsheetjs';
import { ISong, ISongInfo, ISongSlide } from '../models/song.model';
import { IInputConverter } from './input-converter.model';
import { IRawDataFile } from '../models/file.model';
import { version } from '../../version';

/**
* @description ChordPro File Official Docs: https://chordpro.org/chordpro/
Expand Down Expand Up @@ -35,7 +36,13 @@ export class InputTypeChordPro implements IInputConverter {
const slides = this.getLyrics(parsedSong.bodyParagraphs);

return {
fileName: rawFile.name,
originalFile: {
extension: this.fileExt,
format: this.name,
name: rawFile.name,
},
lyricConverterVersion: version,
timestamp: new Date().toISOString(),
title,
info,
slides,
Expand Down
14 changes: 12 additions & 2 deletions src/app/convert/inputs/input-type-json.spec.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
import { IRawDataFile } from 'src/app/convert/models/file.model';
import { InputTypeJSON } from './input-type-json';
import { LyricConverterError } from '../models/errors.model';
import { mockStaticTimestamp } from '../../../../test/mock-song-objects';
import { version } from '../../version';
import { TestUtils } from '../../../../test/test-utils';

describe('InputTypeJSON', () => {
let inputConverter: InputTypeJSON;
Expand Down Expand Up @@ -59,8 +62,15 @@ describe('InputTypeJSON', () => {
'{"title":"Great is your faithfulness O God","info":[{"name":"Order","value":"1C2CBC"}],"slides":[{"title":"Chorus","lyrics":"Your grace is enough\\r\\nYour grace is enough\\r\\nYour grace is enough for me"},{"title":"Verse 1","lyrics":"Great is your faithfulness O God\\r\\nYou wrestle with the sinners heart\\r\\nYou lead us by still waters and to mercy\\r\\nAnd nothing can keep us apart"}]}',
};

expect(inputConverter.extractSongData(testFile)).toEqual({
fileName: testFile.name,
const normalizedSongData = TestUtils.normalizeSongTimestamp(inputConverter.extractSongData(testFile));
expect(normalizedSongData).toEqual({
originalFile: {
extension: inputConverter.fileExt,
format: inputConverter.name,
name: testFile.name,
},
lyricConverterVersion: version,
timestamp: mockStaticTimestamp,
title: 'Great is your faithfulness O God',
info: [{ name: 'Order', value: '1C2CBC' }],
slides: [
Expand Down
9 changes: 8 additions & 1 deletion src/app/convert/inputs/input-type-json.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { IInputConverter } from './input-converter.model';
import { IRawDataFile } from 'src/app/convert/models/file.model';
import { ISong } from 'src/app/convert/models/song.model';
import { LyricConverterError } from '../models/errors.model';
import { version } from '../../version';

export class InputTypeJSON implements IInputConverter {
readonly name = 'JSON';
Expand All @@ -13,7 +14,13 @@ export class InputTypeJSON implements IInputConverter {

extractSongData(rawFile: IRawDataFile): ISong {
const returnSong: ISong = {
fileName: rawFile.name,
originalFile: {
extension: this.fileExt,
format: this.name,
name: rawFile.name,
},
lyricConverterVersion: version,
timestamp: new Date().toISOString(),
title: rawFile.name,
info: [],
slides: [],
Expand Down
Loading

0 comments on commit 3dbc19c

Please sign in to comment.