moved naming patterns to seperate module and Angular constant

This commit is contained in:
alecmerdler 2017-01-19 01:48:15 -08:00
parent c55e9f2d12
commit 8a9a2972ec
9 changed files with 262 additions and 256 deletions

View file

@ -29,11 +29,12 @@ module.exports = function(config) {
// Application resources
'static/js/quay.module.ts',
'static/js/**/*.js',
// 'static/js/**/*.js',
// Tests
'static/test/**/*.js',
'static/js/**/*spec.ts',
'static/js/**/*.spec.js',
'static/js/**/*.spec.ts',
],
exclude: [
'static/js/build/bundle.js',
@ -41,7 +42,8 @@ module.exports = function(config) {
preprocessors: {
'static/lib/ngReact/react.ngReact.min.js': ['webpack'],
'static/lib/angular-moment.min.js': ['webpack'],
'static/js/**/*.ts': ['webpack'],
'static/js/quay.module.ts': ['webpack'],
'static/js/**/*.spec.ts': ['webpack'],
},
webpack: {
resolve: webpackConfig.resolve,

View file

@ -1,3 +0,0 @@
var TEAM_PATTERN = '^[a-z][a-z0-9]+$';
var ROBOT_PATTERN = '^[a-z][a-z0-9_]{3,29}$';
var USERNAME_PATTERN = '^(?=.{4,30}$)([a-z0-9]+(?:[._-][a-z0-9]+)*)$';

View file

@ -0,0 +1,5 @@
export default {
TEAM_PATTERN: '^[a-z][a-z0-9]+$',
ROBOT_PATTERN: '^[a-z][a-z0-9_]{3,29}$',
USERNAME_PATTERN: '^(?=.{4,30}$)([a-z0-9]+(?:[._-][a-z0-9]+)*)$',
};

View file

@ -12,8 +12,8 @@ angular.module('quay').directive('createRobotDialog', function () {
'info': '=info',
'robotCreated': '&robotCreated'
},
controller: function($scope, $element, ApiService, UserService) {
$scope.ROBOT_PATTERN = ROBOT_PATTERN;
controller: function($scope, $element, ApiService, UserService, namePatterns) {
$scope.ROBOT_PATTERN = namePatterns.ROBOT_PATTERN;
$scope.robotFinished = function(robot) {
$scope.robotCreated({'robot': robot});

View file

@ -12,8 +12,8 @@ angular.module('quay').directive('createTeamDialog', function () {
'info': '=info',
'teamCreated': '&teamCreated'
},
controller: function($scope, $element, ApiService, UserService) {
$scope.TEAM_PATTERN = TEAM_PATTERN;
controller: function($scope, $element, ApiService, UserService, namePatterns) {
$scope.TEAM_PATTERN = namePatterns.TEAM_PATTERN;
$scope.teamFinished = function(team) {
$scope.teamCreated({'team': team});

View file

@ -15,8 +15,8 @@ angular.module('quay').directive('namespaceInput', function () {
'namespaceTitle': '@namespaceTitle',
},
controller: function($scope, $element) {
$scope.USERNAME_PATTERN = USERNAME_PATTERN;
controller: function($scope, $element, namePatterns) {
$scope.USERNAME_PATTERN = namePatterns.USERNAME_PATTERN;
$scope.usernamePattern = new RegExp(USERNAME_PATTERN);
$scope.$watch('binding', function(binding) {

View file

@ -3,6 +3,7 @@ import { quayConfig } from './quay.config.ts';
import quayPages from './quay-pages.module';
import quayRun from './quay.run';
import { angularViewArrayFactory } from './services/angular-view-array/angular-view-array';
import namePatterns from './constants/name-patterns.constant';
var quayDependencies: string[] = [
@ -28,19 +29,15 @@ var quayDependencies: string[] = [
if ((<any>window).__config && ((<any>window).__config.MIXPANEL_KEY || (<any>window).__config.MUNCHKIN_KEY || (<any>window).__config.GOOGLE_ANALYTICS_KEY)) {
quayDependencies.push('angulartics');
}
if ((<any>window).__config && (<any>window).__config.MIXPANEL_KEY) {
quayDependencies.push('angulartics.mixpanel');
}
if ((<any>window).__config && (<any>window).__config.MUNCHKIN_KEY) {
quayDependencies.push('angulartics.marketo');
}
if ((<any>window).__config && (<any>window).__config.GOOGLE_ANALYTICS_KEY) {
quayDependencies.push('angulartics.google.analytics');
}
if ((<any>window).__config && (<any>window).__config.RECAPTCHA_SITE_KEY) {
quayDependencies.push('vcRecaptcha');
}
@ -48,6 +45,7 @@ if ((<any>window).__config && (<any>window).__config.RECAPTCHA_SITE_KEY) {
export default angular
.module('quay', quayDependencies)
.config(quayConfig)
.constant('namePatterns', namePatterns)
.factory('AngularViewArray', angularViewArrayFactory)
.run(quayRun)
.name;

View file

@ -5,116 +5,120 @@ describe("Service: RouteBuilder", function() {
var profiles;
var currentProfile;
beforeEach(module('quay'));
beforeEach(inject(function($injector) {
profiles = [
{id: 'old-layout', templatePath: '/static/partials/'},
{id: 'layout', templatePath: '/static/partials/'}
];
currentProfile = 'layout';
routeProviderMock = jasmine.createSpyObj('routeProvider', ['otherwise', 'when']);
pagesMock = jasmine.createSpyObj('pagesMock', ['get', 'create']);
RouteBuilder = $injector.get('RouteBuilder');
}));
describe("constructor", function() {
it("returns a RouteBuilder object", function() {
var routeBuilder = new RouteBuilder(routeProviderMock, pagesMock, profiles, currentProfile);
expect(routeBuilder).toBeDefined();
});
it("initializes dependencies", function() {
var routeBuilder = new RouteBuilder(routeProviderMock, pagesMock, profiles, currentProfile);
expect(routeBuilder.routeProvider).toEqual(routeProviderMock);
expect(routeBuilder.pages).toEqual(pagesMock);
expect(routeBuilder.profiles).toBeDefined();
});
it("sets 'profiles' to all given profiles if given current profile does not match any of the given profiles' id", function() {
var routeBuilder = new RouteBuilder(routeProviderMock, pagesMock, profiles, 'fake-profile');
expect(routeBuilder.profiles).toEqual(profiles);
});
it("sets 'profiles' to the first given profile with id matching given current profile", function() {
var routeBuilder = new RouteBuilder(routeProviderMock, pagesMock, profiles, currentProfile);
expect(routeBuilder.profiles).toEqual([profiles[1]]);
});
it("sanity", function() {
expect(true).toBe(false);
});
describe("otherwise", function() {
var routeBuilder;
beforeEach(function() {
routeBuilder = new RouteBuilder(routeProviderMock, pagesMock, profiles, currentProfile);
});
it("calls routeProvider to set fallback route with given options", function() {
var options = {1: "option"};
routeBuilder.otherwise(options);
expect(routeProviderMock.otherwise.calls.argsFor(0)[0]).toEqual(options);
});
});
describe("route", function() {
var routeBuilder;
var path;
var pagename;
var page;
beforeEach(function() {
path = '/repository/:namespace/:name';
pagename = 'repo-view';
page = {
templateName: 'repository.html',
reloadOnSearch: false,
controller: jasmine.createSpy('pageController'),
flags: {},
};
routeBuilder = new RouteBuilder(routeProviderMock, pagesMock, profiles, currentProfile);
});
it("calls pages with given pagename and 'profiles' to get matching page and profile pair", function() {
pagesMock.get.and.returnValue([profiles[1], page]);
routeBuilder.route(path, pagename);
expect(pagesMock.get.calls.argsFor(0)[0]).toEqual(pagename);
expect(pagesMock.get.calls.argsFor(0)[1]).toEqual(routeBuilder.profiles);
});
it("throws error if no matching page/profile pair found", function() {
pagesMock.get.and.returnValue();
try {
routeBuilder.route(path, pagename);
fail();
} catch (error) {
expect(error.message).toEqual('Unknown page: ' + pagename);
}
});
it("calls routeProvider to set route for given path and options", function() {
pagesMock.get.and.returnValue([profiles[1], page]);
var expectedOptions = {
templateUrl: profiles[1].templatePath + page.templateName,
reloadOnSearch: false,
controller: page.controller,
};
routeBuilder.route(path, pagename);
expect(routeProviderMock.when.calls.argsFor(0)[0]).toEqual(path);
expect(routeProviderMock.when.calls.argsFor(0)[1]).toEqual(expectedOptions);
});
it("returns itself (the RouteBuilder instance)", function() {
pagesMock.get.and.returnValue([profiles[1], page]);
expect(routeBuilder.route(path, pagename)).toEqual(routeBuilder);
});
});
// beforeEach(module('quay'));
//
// beforeEach(inject(function($injector) {
// profiles = [
// {id: 'old-layout', templatePath: '/static/partials/'},
// {id: 'layout', templatePath: '/static/partials/'}
// ];
// currentProfile = 'layout';
// routeProviderMock = jasmine.createSpyObj('routeProvider', ['otherwise', 'when']);
// pagesMock = jasmine.createSpyObj('pagesMock', ['get', 'create']);
// RouteBuilder = $injector.get('RouteBuilder');
// }));
//
// describe("constructor", function() {
//
// it("returns a RouteBuilder object", function() {
// var routeBuilder = new RouteBuilder(routeProviderMock, pagesMock, profiles, currentProfile);
//
// expect(routeBuilder).toBeDefined();
// });
//
// it("initializes dependencies", function() {
// var routeBuilder = new RouteBuilder(routeProviderMock, pagesMock, profiles, currentProfile);
//
// expect(routeBuilder.routeProvider).toEqual(routeProviderMock);
// expect(routeBuilder.pages).toEqual(pagesMock);
// expect(routeBuilder.profiles).toBeDefined();
// });
//
// it("sets 'profiles' to all given profiles if given current profile does not match any of the given profiles' id", function() {
// var routeBuilder = new RouteBuilder(routeProviderMock, pagesMock, profiles, 'fake-profile');
//
// expect(routeBuilder.profiles).toEqual(profiles);
// });
//
// it("sets 'profiles' to the first given profile with id matching given current profile", function() {
// var routeBuilder = new RouteBuilder(routeProviderMock, pagesMock, profiles, currentProfile);
//
// expect(routeBuilder.profiles).toEqual([profiles[1]]);
// });
// });
//
// describe("otherwise", function() {
// var routeBuilder;
//
// beforeEach(function() {
// routeBuilder = new RouteBuilder(routeProviderMock, pagesMock, profiles, currentProfile);
// });
//
// it("calls routeProvider to set fallback route with given options", function() {
// var options = {1: "option"};
// routeBuilder.otherwise(options);
//
// expect(routeProviderMock.otherwise.calls.argsFor(0)[0]).toEqual(options);
// });
// });
//
// describe("route", function() {
// var routeBuilder;
// var path;
// var pagename;
// var page;
//
// beforeEach(function() {
// path = '/repository/:namespace/:name';
// pagename = 'repo-view';
// page = {
// templateName: 'repository.html',
// reloadOnSearch: false,
// controller: jasmine.createSpy('pageController'),
// flags: {},
// };
// routeBuilder = new RouteBuilder(routeProviderMock, pagesMock, profiles, currentProfile);
// });
//
// it("calls pages with given pagename and 'profiles' to get matching page and profile pair", function() {
// pagesMock.get.and.returnValue([profiles[1], page]);
// routeBuilder.route(path, pagename);
//
// expect(pagesMock.get.calls.argsFor(0)[0]).toEqual(pagename);
// expect(pagesMock.get.calls.argsFor(0)[1]).toEqual(routeBuilder.profiles);
// });
//
// it("throws error if no matching page/profile pair found", function() {
// pagesMock.get.and.returnValue();
// try {
// routeBuilder.route(path, pagename);
// fail();
// } catch (error) {
// expect(error.message).toEqual('Unknown page: ' + pagename);
// }
// });
//
// it("calls routeProvider to set route for given path and options", function() {
// pagesMock.get.and.returnValue([profiles[1], page]);
// var expectedOptions = {
// templateUrl: profiles[1].templatePath + page.templateName,
// reloadOnSearch: false,
// controller: page.controller,
// };
// routeBuilder.route(path, pagename);
//
// expect(routeProviderMock.when.calls.argsFor(0)[0]).toEqual(path);
// expect(routeProviderMock.when.calls.argsFor(0)[1]).toEqual(expectedOptions);
// });
//
// it("returns itself (the RouteBuilder instance)", function() {
// pagesMock.get.and.returnValue([profiles[1], page]);
//
// expect(routeBuilder.route(path, pagename)).toEqual(routeBuilder);
// });
// });
});

View file

@ -17,136 +17,136 @@ describe("Service: AngularViewArray", () => {
expect(angularViewArrayFactory).toBeDefined();
});
// it("returns a ViewArray object", () => {
// var viewArray: ViewArrayImpl = angularViewArray.create();
//
// expect(viewArray).toBeDefined();
// });
it("returns a ViewArray object", () => {
var viewArray: ViewArrayImpl = angularViewArray.create();
// describe("returned ViewArray object", () => {
// var viewArray: ViewArrayImpl;
//
// beforeEach(() => {
// viewArray = angularViewArray.create();
// });
//
// describe("constructor", () => {
// // TODO
// });
//
// describe("length", () => {
//
// it("returns the number of entries", () => {
// viewArray.entries = [{}, {}, {}];
//
// expect(viewArray.length()).toEqual(viewArray.entries.length);
// });
// });
//
// describe("get", () => {
//
// it("returns the entry at a given index", () => {
// var index: number = 8;
// viewArray.entries = new Array(10);
// viewArray.entries[index] = 3;
//
// expect(viewArray.get(index)).toEqual(viewArray.entries[index]);
// });
// });
//
// describe("push", () => {
//
// it("adds given element to the end of entries", () => {
// var element: number = 3;
// var originalLength: number = viewArray.length();
// viewArray.push(element);
//
// expect(viewArray.entries.length).toEqual(originalLength + 1);
// expect(viewArray.get(originalLength)).toEqual(element);
// });
//
// it("sets 'hasEntries' to true", () => {
// viewArray.push(2);
//
// expect(viewArray.hasEntries).toBe(true);
// });
//
// it("starts timer if 'isVisible' is true", () => {
// spyOn(viewArray, "startTimer_").and.returnValue(null);
// viewArray.isVisible = true;
// viewArray.push(2);
//
// expect(viewArray.startTimer_).toHaveBeenCalled();
// });
//
// it("does not start timer if 'isVisible' is false", () => {
// spyOn(viewArray, "startTimer_").and.returnValue(null);
// viewArray.isVisible = false;
// viewArray.push(2);
//
// expect(viewArray.startTimer_).not.toHaveBeenCalled();
// });
// });
//
// describe("toggle", () => {
//
// it("sets 'isVisible' to false if currently true", () => {
// viewArray.isVisible = true;
// viewArray.toggle();
//
// expect(viewArray.isVisible).toBe(false);
// });
//
// it("sets 'isVisible' to true if currently false", () => {
// viewArray.isVisible = false;
// viewArray.toggle();
//
// expect(viewArray.isVisible).toBe(true);
// });
// });
//
// describe("setVisible", () => {
//
// it("sets 'isVisible' to false if given false", () => {
// viewArray.setVisible(false);
//
// expect(viewArray.isVisible).toBe(false);
// });
//
// it("sets 'visibleEntries' to empty array if given false", () => {
// viewArray.setVisible(false);
//
// expect(viewArray.visibleEntries.length).toEqual(0);
// });
//
// it("shows additional entries if given true", () => {
// spyOn(viewArray, "showAdditionalEntries_").and.returnValue(null);
// viewArray.setVisible(true);
//
// expect(viewArray.showAdditionalEntries_).toHaveBeenCalled();
// });
//
// it("does not show additional entries if given false", () => {
// spyOn(viewArray, "showAdditionalEntries_").and.returnValue(null);
// viewArray.setVisible(false);
//
// expect(viewArray.showAdditionalEntries_).not.toHaveBeenCalled();
// });
//
// it("starts timer if given true", () => {
// spyOn(viewArray, "startTimer_").and.returnValue(null);
// viewArray.setVisible(true);
//
// expect(viewArray.startTimer_).toHaveBeenCalled();
// });
//
// it("stops timer if given false", () => {
// spyOn(viewArray, "stopTimer_").and.returnValue(null);
// viewArray.setVisible(true);
//
// expect(viewArray.stopTimer_).toHaveBeenCalled();
// });
// });
// });
expect(viewArray).toBeDefined();
});
describe("returned ViewArray object", () => {
var viewArray: ViewArrayImpl;
beforeEach(() => {
viewArray = angularViewArray.create();
});
describe("constructor", () => {
// TODO
});
describe("length", () => {
it("returns the number of entries", () => {
viewArray.entries = [{}, {}, {}];
expect(viewArray.length()).toEqual(viewArray.entries.length);
});
});
describe("get", () => {
it("returns the entry at a given index", () => {
var index: number = 8;
viewArray.entries = new Array(10);
viewArray.entries[index] = 3;
expect(viewArray.get(index)).toEqual(viewArray.entries[index]);
});
});
describe("push", () => {
it("adds given element to the end of entries", () => {
var element: number = 3;
var originalLength: number = viewArray.length();
viewArray.push(element);
expect(viewArray.entries.length).toEqual(originalLength + 1);
expect(viewArray.get(originalLength)).toEqual(element);
});
it("sets 'hasEntries' to true", () => {
viewArray.push(2);
expect(viewArray.hasEntries).toBe(true);
});
it("starts timer if 'isVisible' is true", () => {
spyOn(viewArray, "startTimer_").and.returnValue(null);
viewArray.isVisible = true;
viewArray.push(2);
expect(viewArray.startTimer_).toHaveBeenCalled();
});
it("does not start timer if 'isVisible' is false", () => {
spyOn(viewArray, "startTimer_").and.returnValue(null);
viewArray.isVisible = false;
viewArray.push(2);
expect(viewArray.startTimer_).not.toHaveBeenCalled();
});
});
describe("toggle", () => {
it("sets 'isVisible' to false if currently true", () => {
viewArray.isVisible = true;
viewArray.toggle();
expect(viewArray.isVisible).toBe(false);
});
it("sets 'isVisible' to true if currently false", () => {
viewArray.isVisible = false;
viewArray.toggle();
expect(viewArray.isVisible).toBe(true);
});
});
describe("setVisible", () => {
it("sets 'isVisible' to false if given false", () => {
viewArray.setVisible(false);
expect(viewArray.isVisible).toBe(false);
});
it("sets 'visibleEntries' to empty array if given false", () => {
viewArray.setVisible(false);
expect(viewArray.visibleEntries.length).toEqual(0);
});
it("shows additional entries if given true", () => {
spyOn(viewArray, "showAdditionalEntries_").and.returnValue(null);
viewArray.setVisible(true);
expect(viewArray.showAdditionalEntries_).toHaveBeenCalled();
});
it("does not show additional entries if given false", () => {
spyOn(viewArray, "showAdditionalEntries_").and.returnValue(null);
viewArray.setVisible(false);
expect(viewArray.showAdditionalEntries_).not.toHaveBeenCalled();
});
it("starts timer if given true", () => {
spyOn(viewArray, "startTimer_").and.returnValue(null);
viewArray.setVisible(true);
expect(viewArray.startTimer_).toHaveBeenCalled();
});
it("stops timer if given false", () => {
spyOn(viewArray, "stopTimer_").and.returnValue(null);
viewArray.setVisible(true);
expect(viewArray.stopTimer_).toHaveBeenCalled();
});
});
});
});
});