-
Notifications
You must be signed in to change notification settings - Fork 32
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added loaded the comic formats via messaging [#642]
- Loading branch information
Showing
14 changed files
with
563 additions
and
23 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
29 changes: 29 additions & 0 deletions
29
comixed-web/src/app/library/actions/comic-format.actions.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
/* | ||
* ComiXed - A digital comic book library management application. | ||
* Copyright (C) 2021, 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 { createAction, props } from '@ngrx/store'; | ||
import { ComicFormat } from '@app/library'; | ||
|
||
export const resetComicFormats = createAction( | ||
'[Comic Format] Resets the state' | ||
); | ||
|
||
export const comicFormatAdded = createAction( | ||
'[Comic Format] Comic format added', | ||
props<{ format: ComicFormat }>() | ||
); |
46 changes: 46 additions & 0 deletions
46
comixed-web/src/app/library/effects/comic-format.effects.spec.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
/* | ||
* ComiXed - A digital comic book library management application. | ||
* Copyright (C) 2021, 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 { TestBed } from '@angular/core/testing'; | ||
import { provideMockActions } from '@ngrx/effects/testing'; | ||
import { Observable } from 'rxjs'; | ||
import { ComicFormatEffects } from './comic-format.effects'; | ||
import { ComicFormatService } from '@app/library/services/comic-format.service'; | ||
import { LoggerModule } from '@angular-ru/logger'; | ||
|
||
describe('ComicFormatEffects', () => { | ||
const actions$: Observable<any> = null; | ||
let effects: ComicFormatEffects; | ||
|
||
beforeEach(() => { | ||
TestBed.configureTestingModule({ | ||
imports: [LoggerModule.forRoot()], | ||
providers: [ | ||
ComicFormatEffects, | ||
provideMockActions(() => actions$), | ||
{ provide: ComicFormatService, useValue: {} } | ||
] | ||
}); | ||
|
||
effects = TestBed.inject(ComicFormatEffects); | ||
}); | ||
|
||
it('should be created', () => { | ||
expect(effects).toBeTruthy(); | ||
}); | ||
}); |
31 changes: 31 additions & 0 deletions
31
comixed-web/src/app/library/effects/comic-format.effects.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
/* | ||
* ComiXed - A digital comic book library management application. | ||
* Copyright (C) 2021, 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 { Injectable } from '@angular/core'; | ||
import { Actions } from '@ngrx/effects'; | ||
import { ComicFormatService } from '@app/library/services/comic-format.service'; | ||
import { LoggerService } from '@angular-ru/logger'; | ||
|
||
@Injectable() | ||
export class ComicFormatEffects { | ||
constructor( | ||
private logger: LoggerService, | ||
private actions$: Actions, | ||
private comicFormatService: ComicFormatService | ||
) {} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
102 changes: 102 additions & 0 deletions
102
comixed-web/src/app/library/reducers/comic-format.reducer.spec.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,102 @@ | ||
/* | ||
* ComiXed - A digital comic book library management application. | ||
* Copyright (C) 2021, 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 { | ||
ComicFormatState, | ||
initialState, | ||
reducer | ||
} from './comic-format.reducer'; | ||
import { FORMAT_1, FORMAT_3, FORMAT_5 } from '@app/library/library.fixtures'; | ||
import { | ||
comicFormatAdded, | ||
resetComicFormats | ||
} from '@app/library/actions/comic-format.actions'; | ||
|
||
describe('ComicFormat Reducer', () => { | ||
let state: ComicFormatState; | ||
|
||
beforeEach(() => { | ||
state = { ...initialState }; | ||
}); | ||
|
||
describe('the initial state', () => { | ||
beforeEach(() => { | ||
state = reducer({ ...state }, {} as any); | ||
}); | ||
|
||
it('has no formats', () => { | ||
expect(state.formats).toEqual([]); | ||
}); | ||
}); | ||
|
||
describe('resetting the state', () => { | ||
beforeEach(() => { | ||
state = reducer( | ||
{ ...state, formats: [FORMAT_1, FORMAT_3, FORMAT_5] }, | ||
resetComicFormats() | ||
); | ||
}); | ||
|
||
it('clears the formats', () => { | ||
expect(state.formats).toEqual([]); | ||
}); | ||
}); | ||
|
||
describe('adding a new comic format', () => { | ||
const EXISTING_FORMAT = FORMAT_1; | ||
const NEW_FORMAT = FORMAT_3; | ||
|
||
beforeEach(() => { | ||
state = reducer( | ||
{ ...state, formats: [EXISTING_FORMAT] }, | ||
comicFormatAdded({ format: NEW_FORMAT }) | ||
); | ||
}); | ||
|
||
it('retains the existing format', () => { | ||
expect(state.formats).toContain(EXISTING_FORMAT); | ||
}); | ||
|
||
it('adds the new format', () => { | ||
expect(state.formats).toContain(NEW_FORMAT); | ||
}); | ||
}); | ||
|
||
describe('updating an exisiting comic format', () => { | ||
const EXISTING_FORMAT = FORMAT_1; | ||
const UPDATED_FORMAT = { | ||
...EXISTING_FORMAT, | ||
name: EXISTING_FORMAT.name.substr(1) | ||
}; | ||
|
||
beforeEach(() => { | ||
state = reducer( | ||
{ ...state, formats: [EXISTING_FORMAT] }, | ||
comicFormatAdded({ format: UPDATED_FORMAT }) | ||
); | ||
}); | ||
|
||
it('removes the existing format', () => { | ||
expect(state.formats).not.toContain(EXISTING_FORMAT); | ||
}); | ||
|
||
it('adds the updated format', () => { | ||
expect(state.formats).toContain(UPDATED_FORMAT); | ||
}); | ||
}); | ||
}); |
47 changes: 47 additions & 0 deletions
47
comixed-web/src/app/library/reducers/comic-format.reducer.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
/* | ||
* ComiXed - A digital comic book library management application. | ||
* Copyright (C) 2021, 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 { createReducer, on } from '@ngrx/store'; | ||
import { | ||
comicFormatAdded, | ||
resetComicFormats | ||
} from '../actions/comic-format.actions'; | ||
import { ComicFormat } from '@app/library'; | ||
|
||
export const COMIC_FORMAT_FEATURE_KEY = 'comic_format_state'; | ||
|
||
export interface ComicFormatState { | ||
formats: ComicFormat[]; | ||
} | ||
|
||
export const initialState: ComicFormatState = { | ||
formats: [] | ||
}; | ||
|
||
export const reducer = createReducer( | ||
initialState, | ||
|
||
on(resetComicFormats, state => ({ ...state, formats: [] })), | ||
on(comicFormatAdded, (state, action) => { | ||
const formats = state.formats.filter( | ||
format => format.id !== action.format.id | ||
); | ||
formats.push(action.format); | ||
return { ...state, formats }; | ||
}) | ||
); |
Oops, something went wrong.