Skip to content

Commit

Permalink
max line length update for test files
Browse files Browse the repository at this point in the history
  • Loading branch information
ChrisMBarr committed Sep 3, 2023
1 parent 0ded5f2 commit 62a01df
Show file tree
Hide file tree
Showing 22 changed files with 154 additions and 470 deletions.
3 changes: 3 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@ max_line_length = 100
[*.ts]
quote_type = single

[*.spec.ts]
max_line_length = 150

[*.md]
max_line_length = off
trim_trailing_whitespace = false
11 changes: 2 additions & 9 deletions src/app/app.component.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,7 @@ describe('AppComponent', () => {
beforeEach(() => {
TestBed.configureTestingModule({
imports: [RouterTestingModule],
declarations: [
AppComponent,
HelpComponent,
AboutComponent,
ConvertComponent,
DonateButtonComponent,
DragAndDropFilesDirective,
],
declarations: [AppComponent, HelpComponent, AboutComponent, ConvertComponent, DonateButtonComponent, DragAndDropFilesDirective],
});

fixture = TestBed.createComponent(AppComponent);
Expand All @@ -38,6 +31,6 @@ describe('AppComponent', () => {

it('should set a random background image on the <body> element', () => {
fixture.detectChanges();
expect(injectedDocument.body.getAttribute('style')).toMatch(/background-image: url\("\/assets\/bg\d+.jpg"\);/)
expect(injectedDocument.body.getAttribute('style')).toMatch(/background-image: url\("\/assets\/bg\d+.jpg"\);/);
});
});
112 changes: 25 additions & 87 deletions src/app/convert/convert.component.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,13 +39,7 @@ describe('ConvertComponent', () => {

function configureTestBed<T>(providers: Array<T>) {
TestBed.configureTestingModule({
declarations: [
ConvertComponent,
DonateButtonComponent,
DragAndDropFilesDirective,
SlideDisplayComponent,
DownloadDisplayComponent,
],
declarations: [ConvertComponent, DonateButtonComponent, DragAndDropFilesDirective, SlideDisplayComponent, DownloadDisplayComponent],
providers,
});
parserSvc = TestBed.inject(ParserService);
Expand All @@ -71,11 +65,7 @@ describe('ConvertComponent', () => {
new MockConverter('No File Ext'),
];

mockParserService.inputConverters = [
new MockConverter('FooIn', 'foo'),
new MockConverter('BarIn', 'bar'),
new MockConverter('BazIn', 'baz'),
];
mockParserService.inputConverters = [new MockConverter('FooIn', 'foo'), new MockConverter('BarIn', 'bar'), new MockConverter('BazIn', 'baz')];

configureTestBed([{ provide: ParserService, useValue: mockParserService }, ErrorsService]);
});
Expand Down Expand Up @@ -109,20 +99,15 @@ describe('ConvertComponent', () => {

it('should change the conversion type when switchConversionType() is called', () => {
fixture.detectChanges();
component.onSwitchConversionType(
mockParserService.outputConverters[3]!,
new Event('click')
);
component.onSwitchConversionType(mockParserService.outputConverters[3]!, new Event('click'));
fixture.detectChanges();
expect(component.selectedOutputType.name).toEqual('No File Ext');
});

it('should change the conversion type when a link in the menu is clicked', () => {
fixture.detectChanges();

fixture.debugElement
.query(By.css('#test-convert-types-nav a:nth-of-type(2)'))
.triggerEventHandler('click', new Event('click'));
fixture.debugElement.query(By.css('#test-convert-types-nav a:nth-of-type(2)')).triggerEventHandler('click', new Event('click'));

fixture.detectChanges();
expect(component.selectedOutputType.name).toEqual('BarOut');
Expand All @@ -131,9 +116,7 @@ describe('ConvertComponent', () => {
it('should save the conversion type preference when a link in the menu is clicked', () => {
fixture.detectChanges();

fixture.debugElement
.query(By.css('#test-convert-types-nav a:nth-of-type(2)'))
.triggerEventHandler('click', new Event('click'));
fixture.debugElement.query(By.css('#test-convert-types-nav a:nth-of-type(2)')).triggerEventHandler('click', new Event('click'));

fixture.detectChanges();
expect(localStorage.getItem(prefKey)).toEqual('BarOut');
Expand All @@ -144,12 +127,9 @@ describe('ConvertComponent', () => {
it('should list out all available input type names for accepted file formats', () => {
fixture.detectChanges();

expect(
(
fixture.debugElement.query(By.css('#test-accepted-input-formats'))
.nativeElement as HTMLElement
).textContent
).toContain('FooIn, BarIn, or BazIn');
expect((fixture.debugElement.query(By.css('#test-accepted-input-formats')).nativeElement as HTMLElement).textContent).toContain(
'FooIn, BarIn, or BazIn'
);
});
});
});
Expand Down Expand Up @@ -185,9 +165,7 @@ describe('ConvertComponent', () => {
parserSvc.parsedFilesChanged$.subscribe(() => {
fixture.detectChanges();

expect(component.displayInitialUi)
.withContext('The displayInitialUi property')
.toBeFalse();
expect(component.displayInitialUi).withContext('The displayInitialUi property').toBeFalse();
expect(fixture.debugElement.query(By.css('#begin-area')))
.withContext('#begin-area Element')
.toBeNull();
Expand All @@ -197,18 +175,10 @@ describe('ConvertComponent', () => {
expect(fixture.debugElement.query(By.css('#display-area')))
.withContext('#display-area Element')
.not.toBeNull();
expect(
fixture.debugElement
.query(By.css('#display-area'))
.query(By.directive(SlideDisplayComponent))
)
expect(fixture.debugElement.query(By.css('#display-area')).query(By.directive(SlideDisplayComponent)))
.withContext('The SlideDisplayComponent inside of the #display-area Element')
.not.toBeNull();
expect(
fixture.debugElement
.query(By.css('#display-area'))
.query(By.directive(DownloadDisplayComponent))
)
expect(fixture.debugElement.query(By.css('#display-area')).query(By.directive(DownloadDisplayComponent)))
.withContext('The DownloadDisplayComponent inside of the #display-area Element')
.toBeNull();

Expand All @@ -229,9 +199,7 @@ describe('ConvertComponent', () => {

parserSvc.parsedFilesChanged$.subscribe(() => {
fixture.detectChanges();
expect(component.displayInitialUi)
.withContext('The displayInitialUi property')
.toBeFalse();
expect(component.displayInitialUi).withContext('The displayInitialUi property').toBeFalse();
expect(fixture.debugElement.query(By.css('#begin-area')))
.withContext('#begin-area Element')
.toBeNull();
Expand All @@ -241,18 +209,10 @@ describe('ConvertComponent', () => {
expect(fixture.debugElement.query(By.css('#display-area')))
.withContext('#display-area Element')
.not.toBeNull();
expect(
fixture.debugElement
.query(By.css('#display-area'))
.query(By.directive(SlideDisplayComponent))
)
expect(fixture.debugElement.query(By.css('#display-area')).query(By.directive(SlideDisplayComponent)))
.withContext('The SlideDisplayComponent inside of the #display-area Element')
.toBeNull();
expect(
fixture.debugElement
.query(By.css('#display-area'))
.query(By.directive(DownloadDisplayComponent))
)
expect(fixture.debugElement.query(By.css('#display-area')).query(By.directive(DownloadDisplayComponent)))
.withContext('The DownloadDisplayComponent inside of the #display-area Element')
.not.toBeNull();

Expand Down Expand Up @@ -351,39 +311,30 @@ describe('ConvertComponent', () => {
it('should trigger a click event on the file chooser when the "select some files" link is clicked', () => {
fixture.detectChanges();

const inputEl = fixture.debugElement.query(By.css('input[type="file"]'))
.nativeElement as HTMLInputElement;
const inputEl = fixture.debugElement.query(By.css('input[type="file"]')).nativeElement as HTMLInputElement;

spyOn(inputEl, 'click').and.callFake(() => {});

const selectFilesLinkEl = fixture.debugElement.query(By.css('#begin-area a'))
.nativeElement as HTMLAnchorElement;
const selectFilesLinkEl = fixture.debugElement.query(By.css('#begin-area a')).nativeElement as HTMLAnchorElement;
const clickEvent = new Event('click');
selectFilesLinkEl.dispatchEvent(clickEvent);
fixture.detectChanges();
expect(inputEl.click)
.withContext('The "select some files" link that triggers the file input')
.toHaveBeenCalledTimes(1);
expect(inputEl.click).withContext('The "select some files" link that triggers the file input').toHaveBeenCalledTimes(1);
});

it('should trigger a click event on the file chooser when the "select some more files" link is clicked', () => {
component.displayInitialUi = false;
fixture.detectChanges();

const inputEl = fixture.debugElement.query(By.css('input[type="file"]'))
.nativeElement as HTMLInputElement;
const inputEl = fixture.debugElement.query(By.css('input[type="file"]')).nativeElement as HTMLInputElement;

spyOn(inputEl, 'click').and.callFake(() => {});

const selectFilesLinkEl = fixture.debugElement.query(
By.css('#test-drop-instructions-more a')
).nativeElement as HTMLAnchorElement;
const selectFilesLinkEl = fixture.debugElement.query(By.css('#test-drop-instructions-more a')).nativeElement as HTMLAnchorElement;
const clickEvent = new Event('click');
selectFilesLinkEl.dispatchEvent(clickEvent);
fixture.detectChanges();
expect(inputEl.click)
.withContext('The "select some more files" link that triggers the file input')
.toHaveBeenCalledTimes(1);
expect(inputEl.click).withContext('The "select some more files" link that triggers the file input').toHaveBeenCalledTimes(1);
});
});

Expand Down Expand Up @@ -429,8 +380,7 @@ describe('ConvertComponent', () => {
},
{
title: 'Bridge',
lyrics:
'So remember you people\r\nRemember your children\r\nRemember your promise\r\nOh God',
lyrics: 'So remember you people\r\nRemember your children\r\nRemember your promise\r\nOh God',
},
],
},
Expand Down Expand Up @@ -591,9 +541,7 @@ describe('ConvertComponent', () => {
},
]);

const expectedErr = new LyricConverterError(
'This file is not formatted as a LyricConverter JSON file'
);
const expectedErr = new LyricConverterError('This file is not formatted as a LyricConverter JSON file');
expect(errorsSvc.add).toHaveBeenCalledWith({
message: expectedErr.message,
fileName: 'bad-file.json',
Expand Down Expand Up @@ -702,22 +650,12 @@ describe('ConvertComponent', () => {
expect(errorListEl.queryAll(By.css('ul li')).length)
.withContext('The count of displayed error messages')
.toEqual(2);
expect(
(
errorListEl.query(By.css('ul li:nth-of-type(1)')).nativeElement as HTMLElement
).innerText.trim()
)
expect((errorListEl.query(By.css('ul li:nth-of-type(1)')).nativeElement as HTMLElement).innerText.trim())
.withContext('The 1st error message in the list')
.toEqual('[[TEST:convert.component.spec.ts]] Just a message');
expect(
(
errorListEl.query(By.css('ul li:nth-of-type(2)')).nativeElement as HTMLElement
).innerText.trim()
)
expect((errorListEl.query(By.css('ul li:nth-of-type(2)')).nativeElement as HTMLElement).innerText.trim())
.withContext('The 2nd error message in the list')
.toEqual(
'not-a-virus.exe - [[TEST:convert.component.spec.ts]] A message with a file name'
);
.toEqual('not-a-virus.exe - [[TEST:convert.component.spec.ts]] A message with a file name');
});
});
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,12 +57,10 @@ describe('DownloadDisplayComponent', () => {

expect(fixture.debugElement.queryAll(By.css('.btn')).length).toEqual(2);

const btn1 = fixture.debugElement.query(By.css('.btn:nth-of-type(1)'))
.nativeElement as HTMLButtonElement;
const btn1 = fixture.debugElement.query(By.css('.btn:nth-of-type(1)')).nativeElement as HTMLButtonElement;
expect(btn1.textContent?.trim()).toEqual('Download as .zip');

const btn2 = fixture.debugElement.query(By.css('.btn:nth-of-type(2)'))
.nativeElement as HTMLButtonElement;
const btn2 = fixture.debugElement.query(By.css('.btn:nth-of-type(2)')).nativeElement as HTMLButtonElement;
expect(btn2.textContent?.trim()).toEqual('Download 2 individual files');
});

Expand Down
8 changes: 2 additions & 6 deletions src/app/convert/errors/errors.service.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,7 @@ describe('ErrorsService', () => {

it('should emit the list of errors when an error with a message and a file name is added', (done: DoneFn) => {
service.errorsChanged$.subscribe((list) => {
expect(list).toEqual([
{ message: '[[TEST:errors.service.spec.ts]] Test Message 2', fileName: 'example-file.exe' },
]);
expect(list).toEqual([{ message: '[[TEST:errors.service.spec.ts]] Test Message 2', fileName: 'example-file.exe' }]);
done();
});

Expand Down Expand Up @@ -60,9 +58,7 @@ describe('ErrorsService', () => {
});

it('should emit the list of errors and use the custom error message instead of the default message when a custom error object is attached', (done: DoneFn) => {
const customErrorObj = new LyricConverterError(
'[[TEST:errors.service.spec.ts]] Test Message 4'
);
const customErrorObj = new LyricConverterError('[[TEST:errors.service.spec.ts]] Test Message 4');

service.errorsChanged$.subscribe((list) => {
expect(list).toEqual([
Expand Down
32 changes: 6 additions & 26 deletions src/app/convert/inputs/input-type-chordpro.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,21 +69,10 @@ describe('InputTypeChordPro', () => {
fileName: testFile.name,
title: 'This is a title',
info: [
{
name: 'artist',
value: 'Hymn',
},
{
name: 'key',
value: 'E',
},
],
slides: [
{
title: 'Verse 1',
lyrics: `I know a place\nA wonderful place`,
},
{ name: 'artist', value: 'Hymn' },
{ name: 'key', value: 'E' },
],
slides: [{ title: 'Verse 1', lyrics: `I know a place\nA wonderful place` }],
});
});

Expand Down Expand Up @@ -271,18 +260,9 @@ describe('InputTypeChordPro', () => {
fileName: testFile.name,
title: 'Our Father',
info: [
{
name: 'artist',
value: 'Bethel Music',
},
{
name: 'key',
value: 'G',
},
{
name: 'comment',
value: 'Words and Music by Marcus Meier',
},
{ name: 'artist', value: 'Bethel Music' },
{ name: 'key', value: 'G' },
{ name: 'comment', value: 'Words and Music by Marcus Meier' },
],
slides: [
{
Expand Down
19 changes: 5 additions & 14 deletions src/app/convert/inputs/input-type-json.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,23 +55,16 @@ describe('InputTypeJSON', () => {
ext: 'json',
type: 'text/json',
dataAsBuffer: new ArrayBuffer(0), //not needed for this file type
dataAsString: '{"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"}]}',
dataAsString:
'{"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,
title: 'Great is your faithfulness O God',
info: [
{
name: 'Order',
value: '1C2CBC',
},
],
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: 'Chorus', lyrics: 'Your grace is enough\r\nYour grace is enough\r\nYour grace is enough for me' },
{
title: 'Verse 1',
lyrics:
Expand All @@ -90,9 +83,7 @@ describe('InputTypeJSON', () => {
dataAsString: '{}',
};

const err = new LyricConverterError(
`This file is not formatted as a LyricConverter JSON file`
);
const err = new LyricConverterError(`This file is not formatted as a LyricConverter JSON file`);
expect(() => inputConverter.extractSongData(testFile)).toThrow(err);
});

Expand Down
Loading

0 comments on commit 62a01df

Please sign in to comment.