153 lines
4.8 KiB
JavaScript
153 lines
4.8 KiB
JavaScript
const Backbone = require('backbone');
|
|
const PagesSubheader = require('dashboard/components/pages-subheader/pages-subheader');
|
|
const UserModel = require('dashboard/data/user-model');
|
|
const ConfigModelFixture = require('fixtures/dashboard/config-model.fixture');
|
|
|
|
const BILLING_LINK = '/account/pepe/plan';
|
|
|
|
describe('dashboard/components/pages-subheader/pages-subheader', function () {
|
|
let user, view;
|
|
|
|
const createViewFn = function () {
|
|
user = new UserModel({
|
|
username: 'pepe',
|
|
base_url: 'http://pepe.carto.com',
|
|
email: 'pepe@carto.com',
|
|
account_type: 'FREE',
|
|
db_size_in_bytes: 16384000,
|
|
quota_in_bytes: 1073741824,
|
|
plan_url: BILLING_LINK
|
|
});
|
|
|
|
// Set ConfigModel configuration
|
|
ConfigModelFixture.set('cartodb_com_hosted', false);
|
|
|
|
view = new PagesSubheader({
|
|
userModel: user,
|
|
configModel: ConfigModelFixture
|
|
});
|
|
|
|
return view;
|
|
};
|
|
|
|
beforeEach(function () {
|
|
view = createViewFn();
|
|
});
|
|
|
|
afterEach(function () {
|
|
view.clean();
|
|
});
|
|
|
|
describe('.render', function () {
|
|
it('should render properly', function () {
|
|
view.render();
|
|
|
|
expect(view.$el.html()).toContain('<li class="SideMenu-typeItem"><a href="/profile" class="SideMenu-typeLink ">个人资料</a></li>');
|
|
expect(view.$el.html()).toContain('<li class="SideMenu-typeItem"><a href="/account" class="SideMenu-typeLink ">账户</a></li>');
|
|
expect(view.$el.html()).toContain('<li class="SideMenu-typeItem"><a href="/dashboard/connected_apps" class="SideMenu-typeLink ">Apps应用</a></li>');
|
|
expect(view.$el.html()).toContain('<li class="SideMenu-typeItem"><a href="/your_apps" class="SideMenu-typeLink ">开发设置</a></li>');
|
|
});
|
|
|
|
describe('page is Profile', function () {
|
|
it('should render properly', function () {
|
|
spyOn(view, 'getPath').and.returnValue('/profile');
|
|
|
|
view.render();
|
|
|
|
expect(view.$el.html()).toContain('<li class="SideMenu-typeItem"><a href="/profile" class="SideMenu-typeLink is-selected">个人资料</a></li>');
|
|
});
|
|
});
|
|
|
|
describe('page is Account', function () {
|
|
it('should render properly', function () {
|
|
spyOn(view, 'getPath').and.returnValue('/account');
|
|
|
|
view.render();
|
|
|
|
expect(view.$el.html()).toContain('<li class="SideMenu-typeItem"><a href="/account" class="SideMenu-typeLink is-selected">账户</a></li>');
|
|
});
|
|
});
|
|
|
|
describe('page is Connected Apps', function () {
|
|
it('should render properly', function () {
|
|
spyOn(view, 'getPath').and.returnValue('/dashboard/connected_apps');
|
|
|
|
view.render();
|
|
|
|
expect(view.$el.html()).toContain('<li class="SideMenu-typeItem"><a href="/dashboard/connected_apps" class="SideMenu-typeLink is-selected">Apps应用</a></li>');
|
|
});
|
|
});
|
|
|
|
describe('page is API keys', function () {
|
|
it('should render properly', function () {
|
|
spyOn(view, 'getPath').and.returnValue('/your_apps');
|
|
|
|
view.render();
|
|
|
|
expect(view.$el.html()).toContain('<li class="SideMenu-typeItem"><a href="/your_apps" class="SideMenu-typeLink is-selected">开发设置</a></li>');
|
|
});
|
|
});
|
|
});
|
|
|
|
describe('cartodb_com_hosted', function () {
|
|
describe('.render', function () {
|
|
it('should render properly', function () {
|
|
ConfigModelFixture.set('cartodb_com_hosted', true);
|
|
|
|
view.render();
|
|
|
|
});
|
|
});
|
|
});
|
|
|
|
describe('is inside org', function () {
|
|
beforeEach(function () {
|
|
user.isInsideOrg = function () { return true; };
|
|
user.isOrgOwner = function () { return false; };
|
|
|
|
user.organization = new Backbone.Model({
|
|
name: 'carto'
|
|
});
|
|
user.organization.owner = new Backbone.Model({
|
|
email: 'owner@carto.com'
|
|
});
|
|
user.organization.isOrgAdmin = function () { return false; };
|
|
});
|
|
|
|
|
|
describe('is org admin', function () {
|
|
beforeEach(function () {
|
|
user.organization.isOrgAdmin = function () { return true; };
|
|
});
|
|
|
|
describe('.render', function () {
|
|
it('should render properly', function () {
|
|
view.render();
|
|
|
|
expect(view.$el.html()).toContain('<li class="SideMenu-typeItem"><a href="/organization" class="SideMenu-typeLink ">组织设置</a></li>');
|
|
});
|
|
|
|
describe('page is organization', function () {
|
|
it('should render properly', function () {
|
|
spyOn(view, 'getPath').and.returnValue('/organization');
|
|
|
|
view.render();
|
|
|
|
expect(view.$el.html()).toContain('<li class="SideMenu-typeItem"><a href="/organization" class="SideMenu-typeLink is-selected">组织设置</a></li>');
|
|
});
|
|
});
|
|
});
|
|
});
|
|
});
|
|
|
|
it('should not have leaks', function () {
|
|
view.render();
|
|
|
|
expect(view).toHaveNoLeaks();
|
|
});
|
|
|
|
afterEach(function () {
|
|
view.clean();
|
|
});
|
|
});
|