Skip to content
Snippets Groups Projects
Select Git revision
  • 1d59ceebc1f522842a2c6fd8d024ee9b267fc6e3
  • main default protected
  • OZG-8252-gitlab-pipelines
  • OZG-7856_schadcode_scanner
  • release
  • ci-pipeline
  • OZG-7526-signatur-nicht-uebernommen
  • OZG-6223-zip-download-bug
  • OZG-7367-tooltip-extension
  • OZG-7023-OZG-6956-E2E-externe-Stellen
  • OZG-6238-npm-durch-pnpm-ersetzen
  • release-admin
  • release-info
  • OZG-6700-admin-feature-toggle
  • E2E-Updates
  • OZG-7047-tooltips
  • OZG-6957-e2e-fachstellen-oe-daten
  • OZG-7006-ZuarbeitAnfragen
  • temp_OZG-7027
  • unit-tests-hotfix
  • OZG-6731-POC-keycloakResourceService-with-multiple-stateResources
  • 2.26.0
  • 2.25.0
  • 2.24.2
  • 2.24.1
  • 2.24.0
  • 2.23.0
  • 2.22.0
  • 2.21.0
  • 2.20.0
  • 2.21.0-SNAPSHOT
  • 2.19.0
  • 2.18.0
  • 2.17.1
  • 1.3.0
  • release-admin-1.3.0
  • release-info-1.3.0
  • 2.17.0
  • 2.16.0
  • 2.15.0
  • release-admin-1.1.0
41 results

snackbar.service.spec.ts

Blame
  • snackbar.service.spec.ts 2.41 KiB
    import { MatSnackBar } from '@angular/material/snack-bar';
    import { CommandResource, CommandStatus } from '@goofy-client/command-shared';
    import { Mock, mock, useFromMock } from '@goofy-client/test-utils';
    import * as faker from 'faker';
    import { createCommandResource } from 'libs/command-shared/test/command';
    import { SnackbarErrorComponent } from './snackbar-error/snackbar-error.component';
    import { SnackbarComponent } from './snackbar.component';
    import { SnackBarService } from './snackbar.service';
    
    describe('SnackBarService', () => {
    	let service: SnackBarService;
    	let snackBar: Mock<MatSnackBar>;
    
    	const commandResource: CommandResource = createCommandResource();
    	const message: string = faker.lorem.words(5);
    
    	beforeEach(() => {
    		snackBar = mock(MatSnackBar);
    
    		service = new SnackBarService(useFromMock(snackBar));
    	})
    
    	it('should create', () => {
    		expect(service).toBeDefined();
    	})
    
    	describe('show', () => {
    
    		beforeEach(() => {
    			service.listenOnRevokeAction = jest.fn();
    			service.listenOnAfterDismissed = jest.fn();
    		})
    
    		it('should open from component', () => {
    			service.show(commandResource, message);
    
    			expect(snackBar.openFromComponent).toHaveBeenCalledWith(SnackbarComponent, {
    				data: { message, commandResource }, duration: 10000
    			});
    		})
    
    		it('should listen to snackbar revoke action', () => {
    			service.show(commandResource, message, null);
    
    			expect(service.listenOnRevokeAction).toHaveBeenCalledWith(null);
    		})
    
    		it('should listen to snackbar after dismissed', () => {
    			service.show(commandResource, message, null);
    
    			expect(service.listenOnAfterDismissed).toHaveBeenCalled();
    		})
    
    		it('should open error snackbar when status is ERROR', () => {
    			const commandWithError = { ...commandResource, status: CommandStatus.ERROR}
    			service.show(commandWithError, message, null);
    
    			expect(snackBar.openFromComponent).toHaveBeenCalledWith(SnackbarErrorComponent, {
    				data: { message }, duration: 10000
    			});
    		});
    	})
    
    	describe('show error', () => {
    
    		beforeEach(() => {
    			service.listenOnAfterDismissed = jest.fn();
    		})
    
    		it('should open from component', () => {
    			service.showError(message);
    
    			expect(snackBar.openFromComponent).toHaveBeenCalledWith(SnackbarErrorComponent, {
    				data: { message }, duration: 10000
    			});
    		})
    
    		it('should listen to snackbar after dismissed', () => {
    			service.showError(message);
    
    			expect(service.listenOnAfterDismissed).toHaveBeenCalled();
    		})
    	})
    })