Skip to content

Commit

Permalink
test: add test for updateFileSettings.effect
Browse files Browse the repository at this point in the history
  • Loading branch information
shaman-apprentice committed Oct 27, 2022
1 parent dcbd191 commit 5803fee
Showing 1 changed file with 51 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
import { ApplicationInitStatus } from "@angular/core"
import { TestBed } from "@angular/core/testing"
import { Action } from "redux"
import { Subject } from "rxjs"

import { EffectsModule } from "../../angular-redux/effects/effects.module"
import { State } from "../../angular-redux/state"
import { setFiles } from "../../store/files/files.actions"
import { setState } from "../../store/state.actions"
import { Store } from "../../store/store"
import { UpdateFileSettingsEffect } from "./updateFileSettings.effect"

describe("UpdateFileSettingsEffect", () => {
const mockedDialog = { open: jest.fn() }
let storeDispatchSpy

beforeEach(async () => {
storeDispatchSpy = jest.spyOn(Store, "dispatch")
mockedDialog.open = jest.fn()

EffectsModule.actions$ = new Subject<Action>()
TestBed.configureTestingModule({
imports: [EffectsModule.forRoot([UpdateFileSettingsEffect])],
providers: [{ provide: State, useValue: { getValue: () => ({ files: [] }) } }]
})
await TestBed.inject(ApplicationInitStatus).donePromise
})

afterEach(() => {
EffectsModule.actions$.complete()
})

it("should ignore a not relevant action", () => {
EffectsModule.actions$.next({ type: "whatever" })
expect(storeDispatchSpy).not.toHaveBeenCalled()
})

it("should not blacklist items if it would lead to an empty map but show error dialog", () => {
EffectsModule.actions$.next(setFiles([]))
expect(storeDispatchSpy).not.toHaveBeenCalledWith(
setState({
fileSettings: {
edges: [],
markedPackages: [],
blacklist: [],
attributeTypes: {}
}
})
)
})
})

0 comments on commit 5803fee

Please sign in to comment.