run(() => {
     object = EmberObject.extend(EditorBaseControllerMixin, {
         slugGenerator: EmberObject.create({
             generateSlug(slugType, str) {
                 return RSVP.resolve(`${str}-slug`);
             }
         }),
         model: EmberObject.create({
             slug: 'whatever'
         })
     }).create();
 });
Пример #2
0
    it('#clearAll removes everything without deletion', function () {
        let notifications = this.subject();
        let notificationModel = EmberObject.create({message: 'model'});

        notificationModel.toJSON = function () {};
        notificationModel.deleteRecord = function () {};
        sinon.spy(notificationModel, 'deleteRecord');
        notificationModel.save = function () {
            return {
                finally(callback) {
                    return callback(notificationModel);
                }
            };
        };
        sinon.spy(notificationModel, 'save');

        notifications.handleNotification(notificationModel);
        notifications.handleNotification({message: 'pojo'});

        notifications.clearAll();

        expect(notifications.get('content')).to.be.empty;
        expect(notificationModel.deleteRecord.called).to.be.false;
        expect(notificationModel.save.called).to.be.false;
    });
Пример #3
0
    it('#closeNotification removes and deletes DS.Notification records', function () {
        let notification = EmberObject.create({message: 'Close test', status: 'alert'});
        let notifications = this.subject();

        notification.toJSON = function () {};
        notification.deleteRecord = function () {};
        sinon.spy(notification, 'deleteRecord');
        notification.save = function () {
            return {
                finally(callback) {
                    return callback(notification);
                }
            };
        };
        sinon.spy(notification, 'save');

        run(() => {
            notifications.handleNotification(notification);
        });

        expect(notifications.get('alerts')).to.include(notification);

        run(() => {
            notifications.closeNotification(notification);
        });

        expect(notification.deleteRecord.calledOnce).to.be.true;
        expect(notification.save.calledOnce).to.be.true;

        expect(notifications.get('alerts')).to.not.include(notification);
    });
    beforeEach(function () {
        /* eslint-disable camelcase */
        let tag = EmberObject.create({
            id: 1,
            name: 'Test',
            slug: 'test',
            description: 'Description.',
            metaTitle: 'Meta Title',
            metaDescription: 'Meta description',
            errors: Errors.create(),
            hasValidated: []
        });
        /* eslint-enable camelcase */

        this.set('tag', tag);
        this.set('actions.setProperty', function (property, value) {
            // this should be overridden if a call is expected
            // eslint-disable-next-line no-console
            console.error(`setProperty called '${property}: ${value}'`);
        });

        this.register('service:config', configStub);
        this.inject.service('config', {as: 'config'});

        this.register('service:media-queries', mediaQueriesStub);
        this.inject.service('media-queries', {as: 'mediaQueries'});
    });
    beforeEach(function () {
        let testObject = EmberObject.create();
        testObject.set('name', 'Test');
        testObject.set('hasValidated', []);
        testObject.set('errors', Errors.create());

        this.set('testObject', testObject);
    });
 run(() => {
     object = EmberObject.extend(EditorBaseControllerMixin, {
         model: EmberObject.create({isNew: true}),
         generateSlug: task(function* () {
             this.set('model.slug', 'test-slug');
             yield RSVP.resolve();
         })
     }).create();
 });
            run(() => {
                object = EmberObject.extend(EditorBaseControllerMixin, {
                    model: EmberObject.create({isNew: false}),
                    generateSlug: task(function* () {
                        expect(false, 'generateSlug should not be called').to.equal(true);

                        yield RSVP.resolve();
                    })
                }).create();
            });
Пример #8
0
    it('#handleNotification deals with DS.Notification notifications', function () {
        let notifications = this.subject();
        let notification = EmberObject.create({message: '<h1>Test</h1>', status: 'alert'});

        notification.toJSON = function () {};

        notifications.handleNotification(notification);

        notification = notifications.get('alerts')[0];

        // alerts received from the server should be marked html safe
        expect(notification.get('message')).to.have.property('toHTML');
    });
            run(() => {
                object = EmberObject.extend(EditorBaseControllerMixin, {
                    slugGenerator: EmberObject.create({
                        generateSlug(slugType, str) {
                            return RSVP.resolve(`${str}-slug`);
                        }
                    }),
                    model: EmberObject.create({slug: ''})
                }).create();

                object.set('model.titleScratch', 'title');

                expect(object.get('model.slug')).to.equal('');

                run(() => {
                    object.get('generateSlug').perform();
                });

                wait().then(() => {
                    expect(object.get('model.slug')).to.equal('title-slug');
                    done();
                });
            });
Пример #10
0
    it('isAuthoredByUser is correct', function () {
        let model = this.subject({
            authorId: 'abcd1234'
        });
        let user = EmberObject.create({id: 'abcd1234'});

        expect(model.isAuthoredByUser(user)).to.be.ok;

        run(function () {
            model.set('authorId', 'wxyz9876');

            expect(model.isAuthoredByUser(user)).to.not.be.ok;
        });
    });
Пример #11
0
        function setupEmberCard({env, options, payload}) {
            let id = `GHOST_CARD_${uuid()}`;
            let newlyCreated;
            if (payload.newlyCreated) {
                newlyCreated = true;
                delete payload.newlyCreated;
            }
            let card = EmberObject.create({
                id,
                env,
                options,
                payload,
                card: cardObject,
                newlyCreated
            });

            self.emberCards.pushObject(card);

            env.onTeardown(() => {
                self.emberCards.removeObject(card);
            });

            return card;
        }
Пример #12
0
    classNames: ['ghost-login'],

    session: injectService(),

    beforeModel() {
        this._super(...arguments);

        if (this.get('session.isAuthenticated')) {
            this.transitionTo(Configuration.routeIfAlreadyAuthenticated);
        }
    },

    model() {
        return EmberObject.create({
            identification: '',
            password: '',
            errors: Errors.create()
        });
    },

    // the deactivate hook is called after a route has been exited.
    deactivate() {
        let controller = this.controllerFor('signin');

        this._super(...arguments);

        // clear the properties that hold the credentials when we're no longer on the signin screen
        controller.set('model.identification', '');
        controller.set('model.password', '');
    }
});
Пример #13
0
    ghostPaths: injectService(),
    notifications: injectService(),
    session: injectService(),
    ajax: injectService(),

    beforeModel() {
        if (this.get('session.isAuthenticated')) {
            this.get('notifications').showAlert('You need to sign out to register as a new user.', {type: 'warn', delayed: true, key: 'signup.create.already-authenticated'});
        }

        this._super(...arguments);
    },

    model(params) {
        let model = EmberObject.create();
        let re = /^(?:[A-Za-z0-9_\-]{4})*(?:[A-Za-z0-9_\-]{2}|[A-Za-z0-9_\-]{3})?$/;
        let email,
            tokenText;

        return new Promise((resolve) => {
            if (!re.test(params.token)) {
                this.get('notifications').showAlert('Invalid token.', {type: 'error', delayed: true, key: 'signup.create.invalid-token'});

                return resolve(this.transitionTo('signin'));
            }

            tokenText = atob(params.token);
            email = tokenText.split('|')[1];

            model.set('email', email);
 run(() => {
     this.set('tag', EmberObject.create({id: '2'}));
 });