Skip to content

Commit

Permalink
[Issue comixed#207] Add the PublisherPipe class and tests.
Browse files Browse the repository at this point in the history
  • Loading branch information
mcpierce committed Mar 29, 2020
1 parent 0e3bb58 commit aaff932
Show file tree
Hide file tree
Showing 4 changed files with 101 additions and 1 deletion.
2 changes: 2 additions & 0 deletions comixed-frontend/src/app/comics/comics.constants.ts
Expand Up @@ -40,3 +40,5 @@ export const GET_VOLUMES_URL = `${API_ROOT_URL}/scraping/series/\${series}`;
export const GET_ISSUE_URL = `${API_ROOT_URL}/scraping/volumes/\${volume}/issues/\${issue}`;

export const LOAD_METADATA_URL = `${API_ROOT_URL}/scraping/comics/\${comicId}/issue/\${issueId}`;

export const PUBLISHER_IMPRINT_FORMAT = `\${publisher} (\${imprint})`;
4 changes: 3 additions & 1 deletion comixed-frontend/src/app/comics/comics.module.ts
Expand Up @@ -74,6 +74,7 @@ import { ScrapingIssueCoverUrlPipe } from './pipes/scraping-issue-cover-url.pipe
import * as fromComics from './reducers/comic.reducer';
import * as fromScraping from './reducers/scraping.reducer';
import { PublisherThumbnailUrlPipe } from './pipes/publisher-thumbnail-url.pipe';
import { PublisherPipe } from './pipes/publisher.pipe';

@NgModule({
declarations: [
Expand All @@ -92,7 +93,8 @@ import { PublisherThumbnailUrlPipe } from './pipes/publisher-thumbnail-url.pipe'
ComicCoverUrlPipe,
ComicDownloadLinkPipe,
ScrapingIssueCoverUrlPipe,
PublisherThumbnailUrlPipe
PublisherThumbnailUrlPipe,
PublisherPipe
],
imports: [
UserModule,
Expand Down
58 changes: 58 additions & 0 deletions comixed-frontend/src/app/comics/pipes/publisher.pipe.spec.ts
@@ -0,0 +1,58 @@
/*
* ComiXed - A digital comic book library management application.
* Copyright (C) 2020, The ComiXed Project
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses>
*/

import { PublisherPipe } from './publisher.pipe';
import { COMIC_2 } from 'app/comics/comics.fixtures';
import { interpolate } from 'app/app.functions';
import { PUBLISHER_IMPRINT_FORMAT } from 'app/comics/comics.constants';

describe('PublisherPipe', () => {
const PUBLISHER = 'The Publisher';
const IMPRINT = 'The Imprint';

let pipe: PublisherPipe;

beforeEach(() => {
pipe = new PublisherPipe();
});

it('create an instance', () => {
expect(pipe).toBeTruthy();
});

it('returns an empty string if no publisher is defined', () => {
expect(pipe.transform({ ...COMIC_2, publisher: null })).toEqual('');
});

it('shows only the publisher if no imprint is defined', () => {
expect(
pipe.transform({ ...COMIC_2, publisher: PUBLISHER, imprint: null })
).toEqual(PUBLISHER);
});

it('includes the imprint if present', () => {
expect(
pipe.transform({ ...COMIC_2, publisher: PUBLISHER, imprint: IMPRINT })
).toEqual(
interpolate(PUBLISHER_IMPRINT_FORMAT, {
publisher: PUBLISHER,
imprint: IMPRINT
})
);
});
});
38 changes: 38 additions & 0 deletions comixed-frontend/src/app/comics/pipes/publisher.pipe.ts
@@ -0,0 +1,38 @@
/*
* ComiXed - A digital comic book library management application.
* Copyright (C) 2020, The ComiXed Project
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses>
*/

import { Pipe, PipeTransform } from '@angular/core';
import { Comic } from 'app/comics';
import { interpolate } from 'app/app.functions';
import { PUBLISHER_IMPRINT_FORMAT } from 'app/comics/comics.constants';

@Pipe({
name: 'publisher'
})
export class PublisherPipe implements PipeTransform {
transform(comic: Comic): string {
if (!!comic.imprint) {
return interpolate(PUBLISHER_IMPRINT_FORMAT, {
publisher: comic.publisher,
imprint: comic.imprint
});
}

return comic.publisher || '';
}
}

0 comments on commit aaff932

Please sign in to comment.