示例#1
0
        beforeEach(function () {
            let role = server.create('role', {name: 'Administrator'});
            server.create('user', {roles: [role]});
            server.loadFixtures('settings');

            return authenticateSession(application);
        });
        beforeEach(function () {
            let [role] = server.db.roles.where({name: 'Administrator'});
            server.create('user', {roles: [role]});

            server.loadFixtures();

            authenticateSession(application);
        });
示例#3
0
    it('redirects to team page when authenticated as author', async function () {
        let role = server.create('role', {name: 'Author'});
        server.create('user', {roles: [role], slug: 'test-user'});

        authenticateSession(application);
        await visit('/settings/design');

        expect(currentURL(), 'currentURL').to.equal('/team/test-user');
    });
示例#4
0
    it('displays 404 when post does not exist', async function () {
        let role = server.create('role', {name: 'Editor'});
        server.create('user', {roles: [role], slug: 'test-user'});

        authenticateSession(application);
        await visit('/editor/1');

        expect(currentPath()).to.equal('error404');
        expect(currentURL()).to.equal('/editor/1');
    });
示例#5
0
    it('does not redirect to team page when authenticated as editor', async function () {
        let role = server.create('role', {name: 'Editor'});
        server.create('user', {roles: [role], slug: 'test-user'});
        server.create('post');

        authenticateSession(application);
        await visit('/editor/1');

        expect(currentURL(), 'currentURL').to.equal('/editor/1');
    });
示例#6
0
        beforeEach(function () {
            let role = server.create('role', {name: 'Administrator'});
            let user = server.create('user', {roles: [role]});

            // load the settings fixtures
            // TODO: this should always be run for acceptance tests
            server.loadFixtures();

            return authenticateSession(application);
        });
示例#7
0
    it('redirects to team page when authenticated as author', function () {
        let role = server.create('role', {name: 'Author'});
        let user = server.create('user', {roles: [role], slug: 'test-user'});

        authenticateSession(application);
        visit('/settings/navigation');

        andThen(() => {
            expect(currentURL(), 'currentURL').to.equal('/team/test-user');
        });
    });
示例#8
0
    it('redirects if already authenticated', function () {
        let role = server.create('role', {name: 'Author'});
        let user = server.create('user', {roles: [role], slug: 'test-user'});

        authenticateSession(application);

        visit('/signin');
        andThen(() => {
            expect(currentURL(), 'current url').to.equal('/');
        });
    });
示例#9
0
        beforeEach(function () {
            let authorRole = server.create('role', {name: 'Author'});
            author = server.create('user', {roles: [authorRole]});
            let adminRole = server.create('role', {name: 'Administrator'});
            let admin = server.create('user', {roles: [adminRole]});

            // create posts
            authorPost = server.create('post', {authorId: author.id, status: 'published', title: 'Author Post'});
            server.create('post', {authorId: admin.id, status: 'scheduled', title: 'Admin Post'});

            return authenticateSession(application);
        });
示例#10
0
    it('does not redirect to team page when authenticated as author', function () {
        let role = server.create('role', {name: 'Author'});
        let user = server.create('user', {roles: [role], slug: 'test-user'});
        server.create('post');

        authenticateSession(application);
        visit('/editor/1');

        andThen(() => {
            expect(currentURL(), 'currentURL').to.equal('/editor/1');
        });
    });
示例#11
0
    it('redirects correctly when authenticated as editor', function () {
        let role = server.create('role', {name: 'Editor'});
        let user = server.create('user', {roles: [role], slug: 'test-user'});

        server.create('user', {slug: 'no-access'});

        authenticateSession(application);
        visit('/team/no-access');

        andThen(() => {
            expect(currentURL(), 'currentURL').to.equal('/team');
        });
    });
示例#12
0
    it('redirects authors to posts', function () {
        let role = server.create('role', {name: 'Author'});
        server.create('user', {roles: [role]});

        authenticateSession(application);
        visit('/subscribers');

        andThen(function () {
            expect(currentURL()).to.equal('/');
            expect(find('.gh-nav-main a:contains("Subscribers")').length, 'sidebar link is visible')
                .to.equal(0);
        });
    });
示例#13
0
        beforeEach(function () {
            let contributorRole = server.create('role', {name: 'Contributor'});
            contributor = server.create('user', {roles: [contributorRole]});
            let adminRole = server.create('role', {name: 'Administrator'});
            let admin = server.create('user', {roles: [adminRole]});

            // Create posts
            contributorPost = server.create('post', {authors: [contributor], status: 'draft', title: 'Contributor Post Draft'});
            server.create('post', {authors: [contributor], status: 'published', title: 'Contributor Published Post'});
            server.create('post', {authors: [admin], status: 'scheduled', title: 'Admin Post'});

            return authenticateSession(application);
        });
示例#14
0
        beforeEach(function () {
            let adminRole = server.create('role', {name: 'Administrator'});
            admin = server.create('user', {roles: [adminRole]});
            let editorRole = server.create('role', {name: 'Editor'});
            editor = server.create('user', {roles: [editorRole]});

            publishedPost = server.create('post', {authorId: admin.id, status: 'published', title: 'Published Post'});
            scheduledPost = server.create('post', {authorId: admin.id, status: 'scheduled', title: 'Scheduled Post'});
            draftPost     = server.create('post', {authorId: admin.id, status: 'draft', title: 'Draft Post'});
            publishedPage = server.create('post', {authorId: admin.id, status: 'published', page: true, title: 'Published Page'});
            authorPost    = server.create('post', {authorId: editor.id, status: 'published', title: 'Editor Published Post'});

            return authenticateSession(application);
        });
示例#15
0
        beforeEach(function () {
            let role = server.create('role', {name: 'Administrator'});
            server.create('user', {roles: [role]});

            authenticateSession(application);
        });
示例#16
0
        it('can manage subscribers', function () {
            server.createList('subscriber', 40);

            authenticateSession(application);
            visit('/');
            click('.gh-nav-main a:contains("Subscribers")');

            andThen(function() {
                // it navigates to the correct page
                expect(currentPath()).to.equal('subscribers.index');

                // it has correct page title
                expect(document.title, 'page title')
                    .to.equal('Subscribers - Test Blog');

                // it loads the first page
                expect(find('.subscribers-table .lt-body .lt-row').length, 'number of subscriber rows')
                    .to.equal(30);

                // it shows the total number of subscribers
                expect(find(testSelector('total-subscribers')).text().trim(), 'displayed subscribers total')
                    .to.equal('(40)');

                // it defaults to sorting by created_at desc
                let [lastRequest] = server.pretender.handledRequests.slice(-1);
                expect(lastRequest.queryParams.order).to.equal('created_at desc');

                let createdAtHeader = find('.subscribers-table th:contains("Subscription Date")');
                expect(createdAtHeader.hasClass('is-sorted'), 'createdAt column is sorted')
                    .to.be.true;
                expect(createdAtHeader.find('.icon-descending').length, 'createdAt column has descending icon')
                    .to.equal(1);
            });

            // click the column to re-order
            click('th:contains("Subscription Date")');

            andThen(function () {
                // it flips the directions and re-fetches
                let [lastRequest] = server.pretender.handledRequests.slice(-1);
                expect(lastRequest.queryParams.order).to.equal('created_at asc');

                let createdAtHeader = find('.subscribers-table th:contains("Subscription Date")');
                expect(createdAtHeader.find('.icon-ascending').length, 'createdAt column has ascending icon')
                    .to.equal(1);
            });

            // TODO: scroll test disabled as ember-light-table doesn't calculate
            // the scroll trigger element's positioning against the scroll
            // container - https://github.com/offirgolan/ember-light-table/issues/201
            //
            // andThen(() => {
            //     // scroll to the bottom of the table to simulate infinite scroll
            //     find('.subscribers-table').scrollTop(find('.subscribers-table .ember-light-table').height() - 50);
            // });
            //
            // // trigger infinite scroll
            // triggerEvent('.subscribers-table tbody', 'scroll');
            //
            // andThen(function () {
            //     // it loads the next page
            //     expect(find('.subscribers-table .lt-body .lt-row').length, 'number of subscriber rows after infinite-scroll')
            //         .to.equal(40);
            // });

            // click the add subscriber button
            click('.gh-btn:contains("Add Subscriber")');

            andThen(function () {
                // it displays the add subscriber modal
                expect(find('.fullscreen-modal').length, 'add subscriber modal displayed')
                    .to.equal(1);
            });

            // cancel the modal
            click('.fullscreen-modal .gh-btn:contains("Cancel")');

            andThen(function () {
                // it closes the add subscriber modal
                expect(find('.fullscreen-modal').length, 'add subscriber modal displayed after cancel')
                    .to.equal(0);
            });

            // save a new subscriber
            click('.gh-btn:contains("Add Subscriber")');
            fillIn('.fullscreen-modal input[name="email"]', '*****@*****.**');
            click('.fullscreen-modal .gh-btn:contains("Add")');

            andThen(function () {
                // the add subscriber modal is closed
                expect(find('.fullscreen-modal').length, 'add subscriber modal displayed after save')
                    .to.equal(0);

                // the subscriber is added to the table
                expect(find('.subscribers-table .lt-body .lt-row:first-of-type .lt-cell:first-of-type').text().trim(), 'first email in list after addition')
                    .to.equal('*****@*****.**');

                // the table is scrolled to the top
                // TODO: implement scroll to new record after addition
                // expect(find('.subscribers-table').scrollTop(), 'scroll position after addition')
                //     .to.equal(0);

                // the subscriber total is updated
                expect(find(testSelector('total-subscribers')).text().trim(), 'subscribers total after addition')
                    .to.equal('(41)');
            });

            // saving a duplicate subscriber
            click('.gh-btn:contains("Add Subscriber")');
            fillIn('.fullscreen-modal input[name="email"]', '*****@*****.**');
            click('.fullscreen-modal .gh-btn:contains("Add")');

            andThen(function () {
                // the validation error is displayed
                expect(find('.fullscreen-modal .error .response').text().trim(), 'duplicate email validation')
                    .to.equal('Email already exists.');

                // the subscriber is not added to the table
                expect(find('.lt-cell:contains(test@example.com)').length, 'number of "test@example.com rows"')
                    .to.equal(1);

                // the subscriber total is unchanged
                expect(find(testSelector('total-subscribers')).text().trim(), 'subscribers total after failed add')
                    .to.equal('(41)');
            });

            // deleting a subscriber
            click('.fullscreen-modal .gh-btn:contains("Cancel")');
            click('.subscribers-table tbody tr:first-of-type button:last-of-type');

            andThen(function () {
                // it displays the delete subscriber modal
                expect(find('.fullscreen-modal').length, 'delete subscriber modal displayed')
                    .to.equal(1);
            });

            // cancel the modal
            click('.fullscreen-modal .gh-btn:contains("Cancel")');

            andThen(function () {
                // it closes the add subscriber modal
                expect(find('.fullscreen-modal').length, 'delete subscriber modal displayed after cancel')
                    .to.equal(0);
            });

            click('.subscribers-table tbody tr:first-of-type button:last-of-type');
            click('.fullscreen-modal .gh-btn:contains("Delete")');

            andThen(function () {
                // the add subscriber modal is closed
                expect(find('.fullscreen-modal').length, 'delete subscriber modal displayed after confirm')
                    .to.equal(0);

                // the subscriber is removed from the table
                expect(find('.subscribers-table .lt-body .lt-row:first-of-type .lt-cell:first-of-type').text().trim(), 'first email in list after addition')
                    .to.not.equal('*****@*****.**');

                // the subscriber total is updated
                expect(find(testSelector('total-subscribers')).text().trim(), 'subscribers total after addition')
                    .to.equal('(40)');
            });

            // click the import subscribers button
            click('.gh-btn:contains("Import CSV")');

            andThen(function () {
                // it displays the import subscribers modal
                expect(find('.fullscreen-modal').length, 'import subscribers modal displayed')
                    .to.equal(1);
                expect(find('.fullscreen-modal input[type="file"]').length, 'import modal contains file input')
                    .to.equal(1);
            });

            // cancel the modal
            click('.fullscreen-modal .gh-btn:contains("Cancel")');

            andThen(function () {
                // it closes the import subscribers modal
                expect(find('.fullscreen-modal').length, 'import subscribers modal displayed after cancel')
                    .to.equal(0);
            });

            click('.gh-btn:contains("Import CSV")');
            fileUpload('.fullscreen-modal input[type="file"]', ['test'], {name: 'test.csv'});

            andThen(function () {
                // modal title changes
                expect(find('.fullscreen-modal h1').text().trim(), 'import modal title after import')
                    .to.equal('Import Successful');

                // modal button changes
                expect(find('.fullscreen-modal .modal-footer button').text().trim(), 'import modal button text after import')
                    .to.equal('Close');

                // subscriber total is updated
                expect(find(testSelector('total-subscribers')).text().trim(), 'subscribers total after import')
                    .to.equal('(90)');

                // table is reset
                let [lastRequest] = server.pretender.handledRequests.slice(-1);
                expect(lastRequest.url, 'endpoint requested after import')
                    .to.match(/\/subscribers\/\?/);
                expect(lastRequest.queryParams.page, 'page requested after import')
                    .to.equal('1');

                expect(find('.subscribers-table .lt-body .lt-row').length, 'number of rows in table after import')
                    .to.equal(30);
            });

            // close modal
        });