当前位置: 首页>>代码示例>>TypeScript>>正文


TypeScript dotcms-events-service.mock.DotcmsEventsServiceMock类代码示例

本文整理汇总了TypeScript中src/app/test/dotcms-events-service.mock.DotcmsEventsServiceMock的典型用法代码示例。如果您正苦于以下问题:TypeScript mock.DotcmsEventsServiceMock类的具体用法?TypeScript mock.DotcmsEventsServiceMock怎么用?TypeScript mock.DotcmsEventsServiceMock使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了mock.DotcmsEventsServiceMock类的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。

示例1: fakeAsync

        fakeAsync(() => {
            const events: string[] = [
                'SAVE_SITE',
                'PUBLISH_SITE',
                'UPDATE_SITE_PERMISSIONS',
                'UN_ARCHIVE_SITE',
                'UPDATE_SITE',
                'ARCHIVE_SITE'
            ];
            const dotcmsEventsService: DotcmsEventsServiceMock = this.injector.get(
                DotcmsEventsService
            );
            const siteService = this.injector.get(SiteService);
            const data = {
                data: {
                    data: {
                        identifier: '5'
                    }
                },
                eventType: 'ARCHIVE_SITE'
            };

            this.siteService.switchSite(currentSite);

            respondSwitchSiteRequest.bind(this)();

            spyOn(siteService, 'siteEventsHandler');

            dotcmsEventsService.triggerSubscribeToEvents(events, data);

            tick();

            expect(siteService.siteEventsHandler).toHaveBeenCalledWith(data);
        })
开发者ID:dotCMS,项目名称:core-web,代码行数:34,代码来源:site.service.spec.ts

示例2: describe

describe('DotMessageDisplayService', () => {

    const mockRouter = {
        routerState: {
            snapshot: {
                url: '/content-types-angular'
            }
        }
    };

    const mockDotcmsEventsService: DotcmsEventsServiceMock = new DotcmsEventsServiceMock();

    let dotMessageDisplayService;

    const messageExpected: any = {
        life: 3000,
        message: 'Hello World',
        portletIdList: [],
        severity: 'ERROR',
        type: 'SIMPLE_MESSAGE'
    };

    beforeEach(() => {
        const injector = DOTTestBed.resolveAndCreate([
            { provide: DotcmsEventsService, useValue: mockDotcmsEventsService },
            { provide: Router, useValue: mockRouter },
            DotMessageDisplayService
        ]);

        dotMessageDisplayService = injector.get(DotMessageDisplayService);
    });

    it('should emit a message', (done) => {
        dotMessageDisplayService.messages().subscribe((message: DotMessage) => {
            expect(message).toEqual({
                ...messageExpected,
                severity: DotMessageSeverity.ERROR,
                type: DotMessageType.SIMPLE_MESSAGE
            });
            done();
        });

        mockDotcmsEventsService.triggerSubscribeTo('MESSAGE', {
            data: messageExpected,
            type: 'SIMPLE_MESSAGE'
        });
    });

    it('should unsubscribe', () => {
        let wasCalled = false;

        dotMessageDisplayService.messages().subscribe(() => {
            wasCalled = true;
        });

        dotMessageDisplayService.unsubscribe();

        mockDotcmsEventsService.triggerSubscribeTo('MESSAGE', {
            data: messageExpected,
            type: 'SIMPLE_MESSAGE'
        });

        expect(wasCalled).toBe(false);
    });

    describe('with portletIdList', () => {
        it('should show message when currentPortlet is in portletIdList ', (done) => {
            messageExpected.portletIdList = ['content-types-angular'];

            dotMessageDisplayService.messages().subscribe((message: DotMessage) => {
                expect(message).toEqual({
                    ...messageExpected,
                    severity: DotMessageSeverity.ERROR,
                    type: DotMessageType.SIMPLE_MESSAGE
                });
                done();
            });

            mockDotcmsEventsService.triggerSubscribeTo('MESSAGE', {
                data: messageExpected,
                type: 'SIMPLE_MESSAGE'
            });
        });

        it('should not show message when currentPortlet is not in portletIdList ', () => {
            messageExpected.portletIdList = ['not-content-types-angular'];

            let wasCalled = false;

            dotMessageDisplayService.messages().subscribe(() => {
                wasCalled = true;
            });

            mockDotcmsEventsService.triggerSubscribeTo('MESSAGE', {
                data: messageExpected,
                type: 'SIMPLE_MESSAGE'
            });

            expect(wasCalled).toBe(false);
        });
//.........这里部分代码省略.........
开发者ID:dotCMS,项目名称:core-web,代码行数:101,代码来源:dot-message-display.service.spec.ts

示例3: it

    it('should emit a message', (done) => {
        dotMessageDisplayService.messages().subscribe((message: DotMessage) => {
            expect(message).toEqual({
                ...messageExpected,
                severity: DotMessageSeverity.ERROR,
                type: DotMessageType.SIMPLE_MESSAGE
            });
            done();
        });

        mockDotcmsEventsService.triggerSubscribeTo('MESSAGE', {
            data: messageExpected,
            type: 'SIMPLE_MESSAGE'
        });
    });
开发者ID:dotCMS,项目名称:core-web,代码行数:15,代码来源:dot-message-display.service.spec.ts


注:本文中的src/app/test/dotcms-events-service.mock.DotcmsEventsServiceMock类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。