Rename `data` to `ctx` whenever using `PageContext` This was just inconsistent. Release-Notes: skip Google-Bug-Id: b/244279450 Change-Id: I554a800d4d5c7715f515c67a8cc74b24f12a4e6e
diff --git a/polygerrit-ui/app/elements/core/gr-router/gr-router.ts b/polygerrit-ui/app/elements/core/gr-router/gr-router.ts index 3912de7..1e487e1 100644 --- a/polygerrit-ui/app/elements/core/gr-router/gr-router.ts +++ b/polygerrit-ui/app/elements/core/gr-router/gr-router.ts
@@ -393,15 +393,15 @@ * resolves if the user is logged in. If the user us not logged in, the * promise is rejected and the page is redirected to the login flow. * - * @return A promise yielding the original route data + * @return A promise yielding the original route ctx * (if it resolves). */ - redirectIfNotLoggedIn(data: PageContext) { + redirectIfNotLoggedIn(ctx: PageContext) { return this.restApiService.getLoggedIn().then(loggedIn => { if (loggedIn) { return Promise.resolve(); } else { - this.redirectToLogin(data.canonicalPath); + this.redirectToLogin(ctx.canonicalPath); return Promise.reject(new Error()); } }); @@ -870,13 +870,13 @@ * @return if handling the route involves asynchrony, then a * promise is returned. Otherwise, synchronous handling returns null. */ - handleRootRoute(data: PageContext) { - if (data.querystring.match(/^closeAfterLogin/)) { + handleRootRoute(ctx: PageContext) { + if (ctx.querystring.match(/^closeAfterLogin/)) { // Close child window on redirect after login. window.close(); return null; } - let hash = this.getHashFromCanonicalPath(data.canonicalPath); + let hash = this.getHashFromCanonicalPath(ctx.canonicalPath); // For backward compatibility with GWT links. if (hash) { // In certain login flows the server may redirect to a hash without @@ -884,7 +884,7 @@ if (hash[0] !== '/') { hash = '/' + hash; } - if (hash.includes('/ /') && data.canonicalPath.includes('/+/')) { + if (hash.includes('/ /') && ctx.canonicalPath.includes('/+/')) { // Path decodes all '+' to ' ' -- this breaks project-based URLs. // See Issue 6888. hash = hash.replace('/ /', '/+/'); @@ -909,21 +909,21 @@ /** * Handle dashboard routes. These may be user, or project dashboards. */ - handleDashboardRoute(data: PageContext) { + handleDashboardRoute(ctx: PageContext) { // User dashboard. We require viewing user to be logged in, else we // redirect to login for self dashboard or simple owner search for // other user dashboard. return this.restApiService.getLoggedIn().then(loggedIn => { if (!loggedIn) { - if (data.params[0].toLowerCase() === 'self') { - this.redirectToLogin(data.canonicalPath); + if (ctx.params[0].toLowerCase() === 'self') { + this.redirectToLogin(ctx.canonicalPath); } else { - this.redirect('/q/owner:' + encodeURIComponent(data.params[0])); + this.redirect('/q/owner:' + encodeURIComponent(ctx.params[0])); } } else { const state: DashboardViewState = { view: GerritView.DASHBOARD, - user: data.params[0], + user: ctx.params[0], }; this.setState(state); this.dashboardViewModel.updateState(state); @@ -966,106 +966,106 @@ return Promise.resolve(); } - handleProjectDashboardRoute(data: PageContext) { - const project = data.params[0] as RepoName; + handleProjectDashboardRoute(ctx: PageContext) { + const project = ctx.params[0] as RepoName; const state: DashboardViewState = { view: GerritView.DASHBOARD, project, - dashboard: decodeURIComponent(data.params[1]) as DashboardId, + dashboard: decodeURIComponent(ctx.params[1]) as DashboardId, }; this.setState(state); this.dashboardViewModel.updateState(state); this.reporting.setRepoName(project); } - handleLegacyProjectDashboardRoute(data: PageContext) { - this.redirect('/p/' + data.params[0] + '/+/dashboard/' + data.params[1]); + handleLegacyProjectDashboardRoute(ctx: PageContext) { + this.redirect('/p/' + ctx.params[0] + '/+/dashboard/' + ctx.params[1]); } - handleGroupInfoRoute(data: PageContext) { - this.redirect('/admin/groups/' + encodeURIComponent(data.params[0])); + handleGroupInfoRoute(ctx: PageContext) { + this.redirect('/admin/groups/' + encodeURIComponent(ctx.params[0])); } handleGroupSelfRedirectRoute(_: PageContext) { this.redirect('/settings/#Groups'); } - handleGroupRoute(data: PageContext) { + handleGroupRoute(ctx: PageContext) { const state: GroupViewState = { view: GerritView.GROUP, - groupId: data.params[0] as GroupId, + groupId: ctx.params[0] as GroupId, }; this.setState(state); this.groupViewModel.updateState(state); } - handleGroupAuditLogRoute(data: PageContext) { + handleGroupAuditLogRoute(ctx: PageContext) { const state: GroupViewState = { view: GerritView.GROUP, detail: GroupDetailView.LOG, - groupId: data.params[0] as GroupId, + groupId: ctx.params[0] as GroupId, }; this.setState(state); this.groupViewModel.updateState(state); } - handleGroupMembersRoute(data: PageContext) { + handleGroupMembersRoute(ctx: PageContext) { const state: GroupViewState = { view: GerritView.GROUP, detail: GroupDetailView.MEMBERS, - groupId: data.params[0] as GroupId, + groupId: ctx.params[0] as GroupId, }; this.setState(state); this.groupViewModel.updateState(state); } - handleGroupListOffsetRoute(data: PageContext) { + handleGroupListOffsetRoute(ctx: PageContext) { const state: AdminViewState = { view: GerritView.ADMIN, adminView: AdminChildView.GROUPS, - offset: data.params[1] || 0, + offset: ctx.params[1] || 0, filter: null, - openCreateModal: data.hash === 'create', + openCreateModal: ctx.hash === 'create', }; this.setState(state); this.adminViewModel.updateState(state); } - handleGroupListFilterOffsetRoute(data: PageContext) { + handleGroupListFilterOffsetRoute(ctx: PageContext) { const state: AdminViewState = { view: GerritView.ADMIN, adminView: AdminChildView.GROUPS, - offset: data.params['offset'], - filter: data.params['filter'], + offset: ctx.params['offset'], + filter: ctx.params['filter'], }; this.setState(state); this.adminViewModel.updateState(state); } - handleGroupListFilterRoute(data: PageContext) { + handleGroupListFilterRoute(ctx: PageContext) { const state: AdminViewState = { view: GerritView.ADMIN, adminView: AdminChildView.GROUPS, - filter: data.params['filter'] || null, + filter: ctx.params['filter'] || null, }; this.setState(state); this.adminViewModel.updateState(state); } - handleProjectsOldRoute(data: PageContext) { + handleProjectsOldRoute(ctx: PageContext) { let params = ''; - if (data.params[1]) { - params = encodeURIComponent(data.params[1]); - if (data.params[1].includes(',')) { - params = encodeURIComponent(data.params[1]).replace('%2C', ','); + if (ctx.params[1]) { + params = encodeURIComponent(ctx.params[1]); + if (ctx.params[1].includes(',')) { + params = encodeURIComponent(ctx.params[1]).replace('%2C', ','); } } this.redirect(`/admin/repos/${params}`); } - handleRepoCommandsRoute(data: PageContext) { - const repo = data.params[0] as RepoName; + handleRepoCommandsRoute(ctx: PageContext) { + const repo = ctx.params[0] as RepoName; const state: RepoViewState = { view: GerritView.REPO, detail: RepoDetailView.COMMANDS, @@ -1076,8 +1076,8 @@ this.reporting.setRepoName(repo); } - handleRepoGeneralRoute(data: PageContext) { - const repo = data.params[0] as RepoName; + handleRepoGeneralRoute(ctx: PageContext) { + const repo = ctx.params[0] as RepoName; const state: RepoViewState = { view: GerritView.REPO, detail: RepoDetailView.GENERAL, @@ -1088,8 +1088,8 @@ this.reporting.setRepoName(repo); } - handleRepoAccessRoute(data: PageContext) { - const repo = data.params[0] as RepoName; + handleRepoAccessRoute(ctx: PageContext) { + const repo = ctx.params[0] as RepoName; const state: RepoViewState = { view: GerritView.REPO, detail: RepoDetailView.ACCESS, @@ -1100,8 +1100,8 @@ this.reporting.setRepoName(repo); } - handleRepoDashboardsRoute(data: PageContext) { - const repo = data.params[0] as RepoName; + handleRepoDashboardsRoute(ctx: PageContext) { + const repo = ctx.params[0] as RepoName; const state: RepoViewState = { view: GerritView.REPO, detail: RepoDetailView.DASHBOARDS, @@ -1112,104 +1112,104 @@ this.reporting.setRepoName(repo); } - handleBranchListOffsetRoute(data: PageContext) { + handleBranchListOffsetRoute(ctx: PageContext) { const state: RepoViewState = { view: GerritView.REPO, detail: RepoDetailView.BRANCHES, - repo: data.params[0] as RepoName, - offset: data.params[2] || 0, + repo: ctx.params[0] as RepoName, + offset: ctx.params[2] || 0, filter: null, }; this.setState(state); this.repoViewModel.updateState(state); } - handleBranchListFilterOffsetRoute(data: PageContext) { + handleBranchListFilterOffsetRoute(ctx: PageContext) { const state: RepoViewState = { view: GerritView.REPO, detail: RepoDetailView.BRANCHES, - repo: data.params['repo'] as RepoName, - offset: data.params['offset'], - filter: data.params['filter'], + repo: ctx.params['repo'] as RepoName, + offset: ctx.params['offset'], + filter: ctx.params['filter'], }; this.setState(state); this.repoViewModel.updateState(state); } - handleBranchListFilterRoute(data: PageContext) { + handleBranchListFilterRoute(ctx: PageContext) { const state: RepoViewState = { view: GerritView.REPO, detail: RepoDetailView.BRANCHES, - repo: data.params['repo'] as RepoName, - filter: data.params['filter'] || null, + repo: ctx.params['repo'] as RepoName, + filter: ctx.params['filter'] || null, }; this.setState(state); this.repoViewModel.updateState(state); } - handleTagListOffsetRoute(data: PageContext) { + handleTagListOffsetRoute(ctx: PageContext) { const state: RepoViewState = { view: GerritView.REPO, detail: RepoDetailView.TAGS, - repo: data.params[0] as RepoName, - offset: data.params[2] || 0, + repo: ctx.params[0] as RepoName, + offset: ctx.params[2] || 0, filter: null, }; this.setState(state); this.repoViewModel.updateState(state); } - handleTagListFilterOffsetRoute(data: PageContext) { + handleTagListFilterOffsetRoute(ctx: PageContext) { const state: RepoViewState = { view: GerritView.REPO, detail: RepoDetailView.TAGS, - repo: data.params['repo'] as RepoName, - offset: data.params['offset'], - filter: data.params['filter'], + repo: ctx.params['repo'] as RepoName, + offset: ctx.params['offset'], + filter: ctx.params['filter'], }; this.setState(state); this.repoViewModel.updateState(state); } - handleTagListFilterRoute(data: PageContext) { + handleTagListFilterRoute(ctx: PageContext) { const state: RepoViewState = { view: GerritView.REPO, detail: RepoDetailView.TAGS, - repo: data.params['repo'] as RepoName, - filter: data.params['filter'] || null, + repo: ctx.params['repo'] as RepoName, + filter: ctx.params['filter'] || null, }; this.setState(state); this.repoViewModel.updateState(state); } - handleRepoListOffsetRoute(data: PageContext) { + handleRepoListOffsetRoute(ctx: PageContext) { const state: AdminViewState = { view: GerritView.ADMIN, adminView: AdminChildView.REPOS, - offset: data.params[1] || 0, + offset: ctx.params[1] || 0, filter: null, - openCreateModal: data.hash === 'create', + openCreateModal: ctx.hash === 'create', }; this.setState(state); this.adminViewModel.updateState(state); } - handleRepoListFilterOffsetRoute(data: PageContext) { + handleRepoListFilterOffsetRoute(ctx: PageContext) { const state: AdminViewState = { view: GerritView.ADMIN, adminView: AdminChildView.REPOS, - offset: data.params['offset'], - filter: data.params['filter'], + offset: ctx.params['offset'], + filter: ctx.params['filter'], }; this.setState(state); this.adminViewModel.updateState(state); } - handleRepoListFilterRoute(data: PageContext) { + handleRepoListFilterRoute(ctx: PageContext) { const state: AdminViewState = { view: GerritView.ADMIN, adminView: AdminChildView.REPOS, - filter: data.params['filter'] || null, + filter: ctx.params['filter'] || null, }; this.setState(state); this.adminViewModel.updateState(state); @@ -1227,37 +1227,37 @@ this.redirect('/admin/groups#create'); } - handleRepoRoute(data: PageContext) { - this.redirect(data.path + ',general'); + handleRepoRoute(ctx: PageContext) { + this.redirect(ctx.path + ',general'); } - handlePluginListOffsetRoute(data: PageContext) { + handlePluginListOffsetRoute(ctx: PageContext) { const state: AdminViewState = { view: GerritView.ADMIN, adminView: AdminChildView.PLUGINS, - offset: data.params[1] || 0, + offset: ctx.params[1] || 0, filter: null, }; this.setState(state); this.adminViewModel.updateState(state); } - handlePluginListFilterOffsetRoute(data: PageContext) { + handlePluginListFilterOffsetRoute(ctx: PageContext) { const state: AdminViewState = { view: GerritView.ADMIN, adminView: AdminChildView.PLUGINS, - offset: data.params['offset'], - filter: data.params['filter'], + offset: ctx.params['offset'], + filter: ctx.params['filter'], }; this.setState(state); this.adminViewModel.updateState(state); } - handlePluginListFilterRoute(data: PageContext) { + handlePluginListFilterRoute(ctx: PageContext) { const state: AdminViewState = { view: GerritView.ADMIN, adminView: AdminChildView.PLUGINS, - filter: data.params['filter'] || null, + filter: ctx.params['filter'] || null, }; this.setState(state); this.adminViewModel.updateState(state); @@ -1272,23 +1272,23 @@ this.adminViewModel.updateState(state); } - handleQueryRoute(data: PageContext) { + handleQueryRoute(ctx: PageContext) { const state: SearchViewState = { view: GerritView.SEARCH, - query: data.params[0], - offset: data.params[2], + query: ctx.params[0], + offset: ctx.params[2], }; this.setState(state); this.searchViewModel.updateState(state); } - handleChangeIdQueryRoute(data: PageContext) { + handleChangeIdQueryRoute(ctx: PageContext) { // TODO(pcc): This will need to indicate that this was a change ID query if // standard queries gain the ability to search places like commit messages // for change IDs. const state: SearchViewState = { view: GerritView.SEARCH, - query: data.params[0], + query: ctx.params[0], }; this.setState(state); this.searchViewModel.updateState(state); @@ -1483,11 +1483,11 @@ this.agreementViewModel.updateState(state); } - handleSettingsLegacyRoute(data: PageContext) { + handleSettingsLegacyRoute(ctx: PageContext) { // email tokens may contain '+' but no space. // The parameter parsing replaces all '+' with a space, // undo that to have valid tokens. - const token = data.params[0].replace(/ /g, '+'); + const token = ctx.params[0].replace(/ /g, '+'); const state: SettingsViewState = { view: GerritView.SETTINGS, emailToken: token, @@ -1547,23 +1547,23 @@ this.pluginViewModel.updateState(state); } - handleDocumentationSearchRoute(data: PageContext) { + handleDocumentationSearchRoute(ctx: PageContext) { const state: DocumentationViewState = { view: GerritView.DOCUMENTATION_SEARCH, - filter: data.params['filter'] || null, + filter: ctx.params['filter'] || null, }; this.setState(state); this.documentationViewModel.updateState(state); } - handleDocumentationSearchRedirectRoute(data: PageContext) { + handleDocumentationSearchRedirectRoute(ctx: PageContext) { this.redirect( - '/Documentation/q/filter:' + encodeURIComponent(data.params[0]) + '/Documentation/q/filter:' + encodeURIComponent(ctx.params[0]) ); } - handleDocumentationRedirectRoute(data: PageContext) { - if (data.params[1]) { + handleDocumentationRedirectRoute(ctx: PageContext) { + if (ctx.params[1]) { windowLocationReload(); } else { // Redirect /Documentation to /Documentation/index.html
diff --git a/polygerrit-ui/app/elements/core/gr-router/gr-router_test.ts b/polygerrit-ui/app/elements/core/gr-router/gr-router_test.ts index a766176..47461eb 100644 --- a/polygerrit-ui/app/elements/core/gr-router/gr-router_test.ts +++ b/polygerrit-ui/app/elements/core/gr-router/gr-router_test.ts
@@ -202,7 +202,7 @@ test('redirectIfNotLoggedIn while logged in', () => { stubRestApi('getLoggedIn').returns(Promise.resolve(true)); - const data = { + const ctx = { save() {}, handled: true, canonicalPath: '', @@ -215,7 +215,7 @@ params: {test: 'test'}, }; const redirectStub = sinon.stub(router, 'redirectToLogin'); - return router.redirectIfNotLoggedIn(data).then(() => { + return router.redirectIfNotLoggedIn(ctx).then(() => { assert.isFalse(redirectStub.called); }); }); @@ -223,7 +223,7 @@ test('redirectIfNotLoggedIn while logged out', () => { stubRestApi('getLoggedIn').returns(Promise.resolve(false)); const redirectStub = sinon.stub(router, 'redirectToLogin'); - const data = { + const ctx = { save() {}, handled: true, canonicalPath: '', @@ -237,7 +237,7 @@ }; return new Promise(resolve => { router - .redirectIfNotLoggedIn(data) + .redirectIfNotLoggedIn(ctx) .then(() => { assert.isTrue(false, 'Should never execute'); }) @@ -274,15 +274,15 @@ let setStateStub: sinon.SinonStub; let handlePassThroughRoute: sinon.SinonStub; - // Simple route handlers are direct mappings from parsed route data to a - // new set of app.params. This test helper asserts that passing `data` + // Simple route handlers are direct mappings from parsed route ctx to a + // new set of app.params. This test helper asserts that passing `ctx` // into `methodName` results in setting the params specified in `params`. - function assertDataToParams( - data: PageContext, + function assertctxToParams( + ctx: PageContext, methodName: string, params: AppElementParams ) { - (router as any)[methodName](data); + (router as any)[methodName](ctx); assert.deepEqual(setStateStub.lastCall.args[0], params); } @@ -329,24 +329,24 @@ }); test('handleSettingsLegacyRoute', () => { - const data = {...createPageContext(), params: {0: 'my-token'}}; - assertDataToParams(data, 'handleSettingsLegacyRoute', { + const ctx = {...createPageContext(), params: {0: 'my-token'}}; + assertctxToParams(ctx, 'handleSettingsLegacyRoute', { view: GerritView.SETTINGS, emailToken: 'my-token', }); }); test('handleSettingsLegacyRoute with +', () => { - const data = {...createPageContext(), params: {0: 'my-token test'}}; - assertDataToParams(data, 'handleSettingsLegacyRoute', { + const ctx = {...createPageContext(), params: {0: 'my-token test'}}; + assertctxToParams(ctx, 'handleSettingsLegacyRoute', { view: GerritView.SETTINGS, emailToken: 'my-token+test', }); }); test('handleSettingsRoute', () => { - const data = createPageContext(); - assertDataToParams(data, 'handleSettingsRoute', { + const ctx = createPageContext(); + assertctxToParams(ctx, 'handleSettingsRoute', { view: GerritView.SETTINGS, }); }); @@ -398,19 +398,19 @@ }); test('handleQueryRoute', () => { - const data: PageContext = { + const ctx: PageContext = { ...createPageContext(), params: {0: 'project:foo/bar/baz'}, }; - assertDataToParams(data, 'handleQueryRoute', { + assertctxToParams(ctx, 'handleQueryRoute', { view: GerritView.SEARCH, query: 'project:foo/bar/baz', offset: undefined, }); - data.params[1] = '123'; - data.params[2] = '123'; - assertDataToParams(data, 'handleQueryRoute', { + ctx.params[1] = '123'; + ctx.params[2] = '123'; + assertctxToParams(ctx, 'handleQueryRoute', { view: GerritView.SEARCH, query: 'project:foo/bar/baz', offset: '123', @@ -425,11 +425,11 @@ }); test('handleChangeIdQueryRoute', () => { - const data = { + const ctx = { ...createPageContext(), params: {0: 'I0123456789abcdef0123456789abcdef01234567'}, }; - assertDataToParams(data, 'handleChangeIdQueryRoute', { + assertctxToParams(ctx, 'handleChangeIdQueryRoute', { view: GerritView.SEARCH, query: 'I0123456789abcdef0123456789abcdef01234567', }); @@ -463,17 +463,17 @@ suite('handleRootRoute', () => { test('closes for closeAfterLogin', () => { - const data = {...createPageContext(), querystring: 'closeAfterLogin'}; + const ctx = {...createPageContext(), querystring: 'closeAfterLogin'}; const closeStub = sinon.stub(window, 'close'); - const result = router.handleRootRoute(data); + const result = router.handleRootRoute(ctx); assert.isNotOk(result); assert.isTrue(closeStub.called); assert.isFalse(redirectStub.called); }); test('redirects to dashboard if logged in', () => { - const data = {...createPageContext(), canonicalPath: '/', path: '/'}; - const result = router.handleRootRoute(data); + const ctx = {...createPageContext(), canonicalPath: '/', path: '/'}; + const result = router.handleRootRoute(ctx); assert.isOk(result); return result!.then(() => { assert.isTrue(redirectStub.calledWithExactly('/dashboard/self')); @@ -482,8 +482,8 @@ test('redirects to open changes if not logged in', () => { stubRestApi('getLoggedIn').returns(Promise.resolve(false)); - const data = {...createPageContext(), canonicalPath: '/', path: '/'}; - const result = router.handleRootRoute(data); + const ctx = {...createPageContext(), canonicalPath: '/', path: '/'}; + const result = router.handleRootRoute(ctx); assert.isOk(result); return result!.then(() => { assert.isTrue( @@ -494,73 +494,73 @@ suite('GWT hash-path URLs', () => { test('redirects hash-path URLs', () => { - const data = { + const ctx = { ...createPageContext(), canonicalPath: '/#/foo/bar/baz', hash: '/foo/bar/baz', }; - const result = router.handleRootRoute(data); + const result = router.handleRootRoute(ctx); assert.isNotOk(result); assert.isTrue(redirectStub.called); assert.isTrue(redirectStub.calledWithExactly('/foo/bar/baz')); }); test('redirects hash-path URLs w/o leading slash', () => { - const data = { + const ctx = { ...createPageContext(), canonicalPath: '/#foo/bar/baz', hash: 'foo/bar/baz', }; - const result = router.handleRootRoute(data); + const result = router.handleRootRoute(ctx); assert.isNotOk(result); assert.isTrue(redirectStub.called); assert.isTrue(redirectStub.calledWithExactly('/foo/bar/baz')); }); test('normalizes "/ /" in hash to "/+/"', () => { - const data = { + const ctx = { ...createPageContext(), canonicalPath: '/#/foo/bar/+/123/4', hash: '/foo/bar/ /123/4', }; - const result = router.handleRootRoute(data); + const result = router.handleRootRoute(ctx); assert.isNotOk(result); assert.isTrue(redirectStub.called); assert.isTrue(redirectStub.calledWithExactly('/foo/bar/+/123/4')); }); test('prepends baseurl to hash-path', () => { - const data = { + const ctx = { ...createPageContext(), canonicalPath: '/#/foo/bar', hash: '/foo/bar', }; stubBaseUrl('/baz'); - const result = router.handleRootRoute(data); + const result = router.handleRootRoute(ctx); assert.isNotOk(result); assert.isTrue(redirectStub.called); assert.isTrue(redirectStub.calledWithExactly('/baz/foo/bar')); }); test('normalizes /VE/ settings hash-paths', () => { - const data = { + const ctx = { ...createPageContext(), canonicalPath: '/#/VE/foo/bar', hash: '/VE/foo/bar', }; - const result = router.handleRootRoute(data); + const result = router.handleRootRoute(ctx); assert.isNotOk(result); assert.isTrue(redirectStub.called); assert.isTrue(redirectStub.calledWithExactly('/settings/VE/foo/bar')); }); test('does not drop "inner hashes"', () => { - const data = { + const ctx = { ...createPageContext(), canonicalPath: '/#/foo/bar#baz', hash: '/foo/bar', }; - const result = router.handleRootRoute(data); + const result = router.handleRootRoute(ctx); assert.isNotOk(result); assert.isTrue(redirectStub.called); assert.isTrue(redirectStub.calledWithExactly('/foo/bar#baz')); @@ -577,12 +577,12 @@ test('own dashboard but signed out redirects to login', () => { stubRestApi('getLoggedIn').returns(Promise.resolve(false)); - const data = { + const ctx = { ...createPageContext(), canonicalPath: '/dashboard/', params: {0: 'seLF'}, }; - return router.handleDashboardRoute(data).then(() => { + return router.handleDashboardRoute(ctx).then(() => { assert.isTrue(redirectToLoginStub.calledOnce); assert.isFalse(redirectStub.called); assert.isFalse(setStateStub.called); @@ -591,12 +591,12 @@ test('non-self dashboard but signed out does not redirect', () => { stubRestApi('getLoggedIn').returns(Promise.resolve(false)); - const data = { + const ctx = { ...createPageContext(), canonicalPath: '/dashboard/', params: {0: 'foo'}, }; - return router.handleDashboardRoute(data).then(() => { + return router.handleDashboardRoute(ctx).then(() => { assert.isFalse(redirectToLoginStub.called); assert.isFalse(setStateStub.called); assert.isTrue(redirectStub.calledOnce); @@ -605,12 +605,12 @@ }); test('dashboard while signed in sets params', () => { - const data = { + const ctx = { ...createPageContext(), canonicalPath: '/dashboard/', params: {0: 'foo'}, }; - return router.handleDashboardRoute(data).then(() => { + return router.handleDashboardRoute(ctx).then(() => { assert.isFalse(redirectToLoginStub.called); assert.isFalse(redirectStub.called); assert.isTrue(setStateStub.calledOnce); @@ -630,13 +630,13 @@ }); test('no user specified', () => { - const data: PageContext = { + const ctx: PageContext = { ...createPageContext(), canonicalPath: '/dashboard/', params: {0: ''}, querystring: '', }; - return router.handleCustomDashboardRoute(data).then(() => { + return router.handleCustomDashboardRoute(ctx).then(() => { assert.isFalse(setStateStub.called); assert.isTrue(redirectStub.called); assert.equal(redirectStub.lastCall.args[0], '/dashboard/self'); @@ -644,13 +644,13 @@ }); test('custom dashboard without title', () => { - const data: PageContext = { + const ctx: PageContext = { ...createPageContext(), canonicalPath: '/dashboard/', params: {0: ''}, querystring: '?a=b&c&d=e', }; - return router.handleCustomDashboardRoute(data).then(() => { + return router.handleCustomDashboardRoute(ctx).then(() => { assert.isFalse(redirectStub.called); assert.isTrue(setStateStub.calledOnce); assert.deepEqual(setStateStub.lastCall.args[0], { @@ -666,13 +666,13 @@ }); test('custom dashboard with title', () => { - const data: PageContext = { + const ctx: PageContext = { ...createPageContext(), canonicalPath: '/dashboard/', params: {0: ''}, querystring: '?a=b&c&d=&=e&title=t', }; - return router.handleCustomDashboardRoute(data).then(() => { + return router.handleCustomDashboardRoute(ctx).then(() => { assert.isFalse(redirectToLoginStub.called); assert.isFalse(redirectStub.called); assert.isTrue(setStateStub.calledOnce); @@ -686,13 +686,13 @@ }); test('custom dashboard with foreach', () => { - const data: PageContext = { + const ctx: PageContext = { ...createPageContext(), canonicalPath: '/dashboard/', params: {0: ''}, querystring: '?a=b&c&d=&=e&foreach=is:open', }; - return router.handleCustomDashboardRoute(data).then(() => { + return router.handleCustomDashboardRoute(ctx).then(() => { assert.isFalse(redirectToLoginStub.called); assert.isFalse(redirectStub.called); assert.isTrue(setStateStub.calledOnce); @@ -708,15 +708,15 @@ suite('group routes', () => { test('handleGroupInfoRoute', () => { - const data = {...createPageContext(), params: {0: '1234'}}; - router.handleGroupInfoRoute(data); + const ctx = {...createPageContext(), params: {0: '1234'}}; + router.handleGroupInfoRoute(ctx); assert.isTrue(redirectStub.calledOnce); assert.equal(redirectStub.lastCall.args[0], '/admin/groups/1234'); }); test('handleGroupAuditLogRoute', () => { - const data = {...createPageContext(), params: {0: '1234'}}; - assertDataToParams(data, 'handleGroupAuditLogRoute', { + const ctx = {...createPageContext(), params: {0: '1234'}}; + assertctxToParams(ctx, 'handleGroupAuditLogRoute', { view: GerritView.GROUP, detail: GroupDetailView.LOG, groupId: '1234' as GroupId, @@ -724,8 +724,8 @@ }); test('handleGroupMembersRoute', () => { - const data = {...createPageContext(), params: {0: '1234'}}; - assertDataToParams(data, 'handleGroupMembersRoute', { + const ctx = {...createPageContext(), params: {0: '1234'}}; + assertctxToParams(ctx, 'handleGroupMembersRoute', { view: GerritView.GROUP, detail: GroupDetailView.MEMBERS, groupId: '1234' as GroupId, @@ -733,8 +733,8 @@ }); test('handleGroupListOffsetRoute', () => { - const data = createPageContext(); - assertDataToParams(data, 'handleGroupListOffsetRoute', { + const ctx = createPageContext(); + assertctxToParams(ctx, 'handleGroupListOffsetRoute', { view: GerritView.ADMIN, adminView: AdminChildView.GROUPS, offset: 0, @@ -742,8 +742,8 @@ openCreateModal: false, }); - data.params[1] = '42'; - assertDataToParams(data, 'handleGroupListOffsetRoute', { + ctx.params[1] = '42'; + assertctxToParams(ctx, 'handleGroupListOffsetRoute', { view: GerritView.ADMIN, adminView: AdminChildView.GROUPS, offset: '42', @@ -751,8 +751,8 @@ openCreateModal: false, }); - data.hash = 'create'; - assertDataToParams(data, 'handleGroupListOffsetRoute', { + ctx.hash = 'create'; + assertctxToParams(ctx, 'handleGroupListOffsetRoute', { view: GerritView.ADMIN, adminView: AdminChildView.GROUPS, offset: '42', @@ -762,11 +762,11 @@ }); test('handleGroupListFilterOffsetRoute', () => { - const data = { + const ctx = { ...createPageContext(), params: {filter: 'foo', offset: '42'}, }; - assertDataToParams(data, 'handleGroupListFilterOffsetRoute', { + assertctxToParams(ctx, 'handleGroupListFilterOffsetRoute', { view: GerritView.ADMIN, adminView: AdminChildView.GROUPS, offset: '42', @@ -775,8 +775,8 @@ }); test('handleGroupListFilterRoute', () => { - const data = {...createPageContext(), params: {filter: 'foo'}}; - assertDataToParams(data, 'handleGroupListFilterRoute', { + const ctx = {...createPageContext(), params: {filter: 'foo'}}; + assertctxToParams(ctx, 'handleGroupListFilterRoute', { view: GerritView.ADMIN, adminView: AdminChildView.GROUPS, filter: 'foo', @@ -784,8 +784,8 @@ }); test('handleGroupRoute', () => { - const data = {...createPageContext(), params: {0: '4321'}}; - assertDataToParams(data, 'handleGroupRoute', { + const ctx = {...createPageContext(), params: {0: '4321'}}; + assertctxToParams(ctx, 'handleGroupRoute', { view: GerritView.GROUP, groupId: '4321' as GroupId, }); @@ -794,22 +794,22 @@ suite('repo routes', () => { test('handleProjectsOldRoute', () => { - const data = {...createPageContext(), params: {}}; - router.handleProjectsOldRoute(data); + const ctx = {...createPageContext(), params: {}}; + router.handleProjectsOldRoute(ctx); assert.isTrue(redirectStub.calledOnce); assert.equal(redirectStub.lastCall.args[0], '/admin/repos/'); }); test('handleProjectsOldRoute test', () => { - const data = {...createPageContext(), params: {1: 'test'}}; - router.handleProjectsOldRoute(data); + const ctx = {...createPageContext(), params: {1: 'test'}}; + router.handleProjectsOldRoute(ctx); assert.isTrue(redirectStub.calledOnce); assert.equal(redirectStub.lastCall.args[0], '/admin/repos/test'); }); test('handleProjectsOldRoute test,branches', () => { - const data = {...createPageContext(), params: {1: 'test,branches'}}; - router.handleProjectsOldRoute(data); + const ctx = {...createPageContext(), params: {1: 'test,branches'}}; + router.handleProjectsOldRoute(ctx); assert.isTrue(redirectStub.calledOnce); assert.equal( redirectStub.lastCall.args[0], @@ -818,8 +818,8 @@ }); test('handleRepoRoute', () => { - const data = {...createPageContext(), path: '/admin/repos/test'}; - router.handleRepoRoute(data); + const ctx = {...createPageContext(), path: '/admin/repos/test'}; + router.handleRepoRoute(ctx); assert.isTrue(redirectStub.calledOnce); assert.equal( redirectStub.lastCall.args[0], @@ -828,8 +828,8 @@ }); test('handleRepoGeneralRoute', () => { - const data = {...createPageContext(), params: {0: '4321'}}; - assertDataToParams(data, 'handleRepoGeneralRoute', { + const ctx = {...createPageContext(), params: {0: '4321'}}; + assertctxToParams(ctx, 'handleRepoGeneralRoute', { view: GerritView.REPO, detail: RepoDetailView.GENERAL, repo: '4321' as RepoName, @@ -837,8 +837,8 @@ }); test('handleRepoCommandsRoute', () => { - const data = {...createPageContext(), params: {0: '4321'}}; - assertDataToParams(data, 'handleRepoCommandsRoute', { + const ctx = {...createPageContext(), params: {0: '4321'}}; + assertctxToParams(ctx, 'handleRepoCommandsRoute', { view: GerritView.REPO, detail: RepoDetailView.COMMANDS, repo: '4321' as RepoName, @@ -846,8 +846,8 @@ }); test('handleRepoAccessRoute', () => { - const data = {...createPageContext(), params: {0: '4321'}}; - assertDataToParams(data, 'handleRepoAccessRoute', { + const ctx = {...createPageContext(), params: {0: '4321'}}; + assertctxToParams(ctx, 'handleRepoAccessRoute', { view: GerritView.REPO, detail: RepoDetailView.ACCESS, repo: '4321' as RepoName, @@ -856,11 +856,11 @@ suite('branch list routes', () => { test('handleBranchListOffsetRoute', () => { - const data: PageContext = { + const ctx: PageContext = { ...createPageContext(), params: {0: '4321'}, }; - assertDataToParams(data, 'handleBranchListOffsetRoute', { + assertctxToParams(ctx, 'handleBranchListOffsetRoute', { view: GerritView.REPO, detail: RepoDetailView.BRANCHES, repo: '4321' as RepoName, @@ -868,8 +868,8 @@ filter: null, }); - data.params[2] = '42'; - assertDataToParams(data, 'handleBranchListOffsetRoute', { + ctx.params[2] = '42'; + assertctxToParams(ctx, 'handleBranchListOffsetRoute', { view: GerritView.REPO, detail: RepoDetailView.BRANCHES, repo: '4321' as RepoName, @@ -879,11 +879,11 @@ }); test('handleBranchListFilterOffsetRoute', () => { - const data = { + const ctx = { ...createPageContext(), params: {repo: '4321', filter: 'foo', offset: '42'}, }; - assertDataToParams(data, 'handleBranchListFilterOffsetRoute', { + assertctxToParams(ctx, 'handleBranchListFilterOffsetRoute', { view: GerritView.REPO, detail: RepoDetailView.BRANCHES, repo: '4321' as RepoName, @@ -893,11 +893,11 @@ }); test('handleBranchListFilterRoute', () => { - const data = { + const ctx = { ...createPageContext(), params: {repo: '4321', filter: 'foo'}, }; - assertDataToParams(data, 'handleBranchListFilterRoute', { + assertctxToParams(ctx, 'handleBranchListFilterRoute', { view: GerritView.REPO, detail: RepoDetailView.BRANCHES, repo: '4321' as RepoName, @@ -908,8 +908,8 @@ suite('tag list routes', () => { test('handleTagListOffsetRoute', () => { - const data = {...createPageContext(), params: {0: '4321'}}; - assertDataToParams(data, 'handleTagListOffsetRoute', { + const ctx = {...createPageContext(), params: {0: '4321'}}; + assertctxToParams(ctx, 'handleTagListOffsetRoute', { view: GerritView.REPO, detail: RepoDetailView.TAGS, repo: '4321' as RepoName, @@ -919,11 +919,11 @@ }); test('handleTagListFilterOffsetRoute', () => { - const data = { + const ctx = { ...createPageContext(), params: {repo: '4321', filter: 'foo', offset: '42'}, }; - assertDataToParams(data, 'handleTagListFilterOffsetRoute', { + assertctxToParams(ctx, 'handleTagListFilterOffsetRoute', { view: GerritView.REPO, detail: RepoDetailView.TAGS, repo: '4321' as RepoName, @@ -933,19 +933,19 @@ }); test('handleTagListFilterRoute', () => { - const data: PageContext = { + const ctx: PageContext = { ...createPageContext(), params: {repo: '4321'}, }; - assertDataToParams(data, 'handleTagListFilterRoute', { + assertctxToParams(ctx, 'handleTagListFilterRoute', { view: GerritView.REPO, detail: RepoDetailView.TAGS, repo: '4321' as RepoName, filter: null, }); - data.params.filter = 'foo'; - assertDataToParams(data, 'handleTagListFilterRoute', { + ctx.params.filter = 'foo'; + assertctxToParams(ctx, 'handleTagListFilterRoute', { view: GerritView.REPO, detail: RepoDetailView.TAGS, repo: '4321' as RepoName, @@ -956,8 +956,8 @@ suite('repo list routes', () => { test('handleRepoListOffsetRoute', () => { - const data = createPageContext(); - assertDataToParams(data, 'handleRepoListOffsetRoute', { + const ctx = createPageContext(); + assertctxToParams(ctx, 'handleRepoListOffsetRoute', { view: GerritView.ADMIN, adminView: AdminChildView.REPOS, offset: 0, @@ -965,8 +965,8 @@ openCreateModal: false, }); - data.params[1] = '42'; - assertDataToParams(data, 'handleRepoListOffsetRoute', { + ctx.params[1] = '42'; + assertctxToParams(ctx, 'handleRepoListOffsetRoute', { view: GerritView.ADMIN, adminView: AdminChildView.REPOS, offset: '42', @@ -974,8 +974,8 @@ openCreateModal: false, }); - data.hash = 'create'; - assertDataToParams(data, 'handleRepoListOffsetRoute', { + ctx.hash = 'create'; + assertctxToParams(ctx, 'handleRepoListOffsetRoute', { view: GerritView.ADMIN, adminView: AdminChildView.REPOS, offset: '42', @@ -985,11 +985,11 @@ }); test('handleRepoListFilterOffsetRoute', () => { - const data = { + const ctx = { ...createPageContext(), params: {filter: 'foo', offset: '42'}, }; - assertDataToParams(data, 'handleRepoListFilterOffsetRoute', { + assertctxToParams(ctx, 'handleRepoListFilterOffsetRoute', { view: GerritView.ADMIN, adminView: AdminChildView.REPOS, offset: '42', @@ -998,15 +998,15 @@ }); test('handleRepoListFilterRoute', () => { - const data = createPageContext(); - assertDataToParams(data, 'handleRepoListFilterRoute', { + const ctx = createPageContext(); + assertctxToParams(ctx, 'handleRepoListFilterRoute', { view: GerritView.ADMIN, adminView: AdminChildView.REPOS, filter: null, }); - data.params.filter = 'foo'; - assertDataToParams(data, 'handleRepoListFilterRoute', { + ctx.params.filter = 'foo'; + assertctxToParams(ctx, 'handleRepoListFilterRoute', { view: GerritView.ADMIN, adminView: AdminChildView.REPOS, filter: 'foo', @@ -1017,16 +1017,16 @@ suite('plugin routes', () => { test('handlePluginListOffsetRoute', () => { - const data = createPageContext(); - assertDataToParams(data, 'handlePluginListOffsetRoute', { + const ctx = createPageContext(); + assertctxToParams(ctx, 'handlePluginListOffsetRoute', { view: GerritView.ADMIN, adminView: AdminChildView.PLUGINS, offset: 0, filter: null, }); - data.params[1] = '42'; - assertDataToParams(data, 'handlePluginListOffsetRoute', { + ctx.params[1] = '42'; + assertctxToParams(ctx, 'handlePluginListOffsetRoute', { view: GerritView.ADMIN, adminView: AdminChildView.PLUGINS, offset: '42', @@ -1035,11 +1035,11 @@ }); test('handlePluginListFilterOffsetRoute', () => { - const data = { + const ctx = { ...createPageContext(), params: {filter: 'foo', offset: '42'}, }; - assertDataToParams(data, 'handlePluginListFilterOffsetRoute', { + assertctxToParams(ctx, 'handlePluginListFilterOffsetRoute', { view: GerritView.ADMIN, adminView: AdminChildView.PLUGINS, offset: '42', @@ -1048,15 +1048,15 @@ }); test('handlePluginListFilterRoute', () => { - const data = createPageContext(); - assertDataToParams(data, 'handlePluginListFilterRoute', { + const ctx = createPageContext(); + assertctxToParams(ctx, 'handlePluginListFilterRoute', { view: GerritView.ADMIN, adminView: AdminChildView.PLUGINS, filter: null, }); - data.params.filter = 'foo'; - assertDataToParams(data, 'handlePluginListFilterRoute', { + ctx.params.filter = 'foo'; + assertctxToParams(ctx, 'handlePluginListFilterRoute', { view: GerritView.ADMIN, adminView: AdminChildView.PLUGINS, filter: 'foo', @@ -1064,8 +1064,8 @@ }); test('handlePluginListRoute', () => { - const data = createPageContext(); - assertDataToParams(data, 'handlePluginListRoute', { + const ctx = createPageContext(); + assertctxToParams(ctx, 'handlePluginListRoute', { view: GerritView.ADMIN, adminView: AdminChildView.PLUGINS, }); @@ -1074,8 +1074,8 @@ suite('change/diff routes', () => { test('handleChangeNumberLegacyRoute', () => { - const data = {...createPageContext(), params: {0: '12345'}}; - router.handleChangeNumberLegacyRoute(data); + const ctx = {...createPageContext(), params: {0: '12345'}}; + router.handleChangeNumberLegacyRoute(ctx); assert.isTrue(redirectStub.calledOnce); assert.isTrue(redirectStub.calledWithExactly('/c/12345')); }); @@ -1135,7 +1135,7 @@ test('change view', () => { const ctx = makeParams('', ''); - assertDataToParams(ctx, 'handleChangeRoute', { + assertctxToParams(ctx, 'handleChangeRoute', { view: GerritView.CHANGE, project: 'foo/bar' as RepoName, changeNum: 1234 as NumericChangeId, @@ -1153,7 +1153,7 @@ queryMap.set('select', 'sss'); queryMap.set('attempt', '1'); ctx.querystring = queryMap.toString(); - assertDataToParams(ctx, 'handleChangeRoute', { + assertctxToParams(ctx, 'handleChangeRoute', { view: GerritView.CHANGE, project: 'foo/bar' as RepoName, changeNum: 1234 as NumericChangeId, @@ -1191,7 +1191,7 @@ test('diff view', () => { const ctx = makeParams('foo/bar/baz', 'b44'); - assertDataToParams(ctx, 'handleDiffRoute', { + assertctxToParams(ctx, 'handleDiffRoute', { view: GerritView.DIFF, project: 'foo/bar' as RepoName, changeNum: 1234 as NumericChangeId, @@ -1212,7 +1212,7 @@ '264833', // changeNum '00049681_f34fd6a9', // commentId ]); - assertDataToParams( + assertctxToParams( {params: groups!.slice(1)} as any, 'handleCommentRoute', { @@ -1233,7 +1233,7 @@ '264833', // changeNum '00049681_f34fd6a9', // commentId ]); - assertDataToParams( + assertctxToParams( {params: groups!.slice(1)} as any, 'handleCommentsRoute', { @@ -1326,7 +1326,7 @@ test('handlePluginScreen', () => { const ctx = {...createPageContext(), params: {0: 'foo', 1: 'bar'}}; - assertDataToParams(ctx, 'handlePluginScreen', { + assertctxToParams(ctx, 'handlePluginScreen', { view: GerritView.PLUGIN_SCREEN, plugin: 'foo', screen: 'bar',