Skip to content

Commit a3d11ab

Browse files
authored
Replace activeSurveyId$ with URL param from NavigationService (#2389)
1 parent b0b2abd commit a3d11ab

File tree

12 files changed

+57
-35
lines changed

12 files changed

+57
-35
lines changed

lib/src/date-util.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,6 @@ export function timestampToInt(
2525
return (
2626
(Long.isLong(timestamp.seconds)
2727
? timestamp.seconds.toInt()
28-
: timestamp.seconds || 0) * 1000
28+
: (timestamp.seconds as number) || 0) * 1000
2929
);
3030
}

web/src/app/app.spec.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
* limitations under the License.
1515
*/
1616

17+
import { Component, NO_ERRORS_SCHEMA } from '@angular/core';
1718
import { TestBed } from '@angular/core/testing';
1819
import { RouterTestingModule } from '@angular/router/testing';
1920

@@ -22,7 +23,7 @@ import { AppComponent } from 'app/app.component';
2223
describe('AppComponent', () => {
2324
beforeEach(async () => {
2425
await TestBed.configureTestingModule({
25-
imports: [RouterTestingModule],
26+
imports: [RouterTestingModule.withRoutes([])],
2627
declarations: [AppComponent],
2728
}).compileComponents();
2829
});

web/src/app/components/create-survey/create-survey.component.spec.ts

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,6 @@ describe('CreateSurveyComponent', () => {
143143

144144
route = new ActivatedRouteStub();
145145
surveyServiceSpy = jasmine.createSpyObj<SurveyService>('SurveyService', [
146-
'activateSurvey',
147146
'getActiveSurvey$',
148147
'updateTitleAndDescription',
149148
'createSurvey',
@@ -247,10 +246,8 @@ describe('CreateSurveyComponent', () => {
247246
await fixture.whenStable();
248247
});
249248

250-
it('activates survey ID', async () => {
251-
expect(surveyServiceSpy.activateSurvey).toHaveBeenCalledOnceWith(
252-
surveyId
253-
);
249+
it('initializes draft survey', async () => {
250+
expect(draftSurveyServiceSpy.init).toHaveBeenCalledWith(surveyId);
254251
});
255252
});
256253

web/src/app/components/create-survey/create-survey.component.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,6 @@ export class CreateSurveyComponent implements OnInit {
154154
this.subscription.add(
155155
this.navigationService.getSurveyId$().subscribe(async surveyId => {
156156
this.surveyId = surveyId ? surveyId : SURVEY_ID_NEW;
157-
this.surveyService.activateSurvey(this.surveyId);
158157
await this.draftSurveyService.init(this.surveyId);
159158
this.draftSurveyService
160159
.getSurvey$()

web/src/app/components/edit-survey/edit-survey.component.spec.ts

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -99,12 +99,12 @@ describe('EditSurveyComponent', () => {
9999
'getEditSurveyPageSignal',
100100
'navigateToEditJob',
101101
'navigateToEditSurvey',
102+
'selectSurvey',
102103
]
103104
);
104105
navigationServiceSpy.getEditSurveyPageSignal.and.returnValue(signal(''));
105106

106107
surveyServiceSpy = jasmine.createSpyObj<SurveyService>('SurveyService', [
107-
'activateSurvey',
108108
'getActiveSurvey$',
109109
]);
110110
activeSurvey$ = new Subject<Survey>();
@@ -193,10 +193,8 @@ describe('EditSurveyComponent', () => {
193193
fixture.detectChanges(); // Update view (content)
194194
});
195195

196-
it('activates survey ID', () => {
197-
expect(surveyServiceSpy.activateSurvey).toHaveBeenCalledOnceWith(
198-
surveyId
199-
);
196+
it('initializes draft survey', () => {
197+
expect(draftSurveyServiceSpy.init).toHaveBeenCalledWith(surveyId);
200198
});
201199
});
202200

web/src/app/components/edit-survey/edit-survey.component.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,6 @@ export class EditSurveyComponent {
6666
const id = this.surveyId();
6767

6868
if (id) {
69-
this.surveyService.activateSurvey(id);
7069
await this.draftSurveyService.init(id);
7170
this.draftSurveyService.getSurvey$().subscribe(survey => {
7271
this.survey = survey;

web/src/app/components/main-page-container/main-page-container.component.spec.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ const navigationService = {
3434

3535
const surveyService = jasmine.createSpyObj('SurveyService', [
3636
'getActiveSurvey$',
37-
'activateSurvey',
37+
'loadSurvey$',
3838
]);
3939

4040
describe('MainPageContainerComponent', () => {
@@ -54,6 +54,7 @@ describe('MainPageContainerComponent', () => {
5454
schemas: [NO_ERRORS_SCHEMA],
5555
}).compileComponents();
5656

57+
surveyService.loadSurvey$.and.returnValue(NEVER);
5758
fixture = TestBed.createComponent(MainPageContainerComponent);
5859
component = fixture.componentInstance;
5960
fixture.detectChanges();

web/src/app/components/main-page-container/main-page-container.component.ts

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -36,10 +36,5 @@ export class MainPageContainerComponent {
3636
)
3737
);
3838

39-
constructor() {
40-
effect(() => {
41-
const id = this.surveyId();
42-
if (id) this.surveyService.activateSurvey(id);
43-
});
44-
}
39+
constructor() {}
4540
}

web/src/app/components/main-page-container/main-page/survey-header/survey-header.component.spec.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ import { NEVER, of } from 'rxjs';
2525
import { DataSharingType, Survey } from 'app/models/survey.model';
2626
import { GroundIconModule } from 'app/modules/ground-icon.module';
2727
import { DataStoreService } from 'app/services/data-store/data-store.service';
28+
import { NavigationService } from 'app/services/navigation/navigation.service';
2829
import { SurveyService } from 'app/services/survey/survey.service';
2930

3031
import { SurveyHeaderComponent } from './survey-header.component';
@@ -61,6 +62,14 @@ describe('SurveyHeaderComponent', () => {
6162
updateTitle: () => Promise.resolve(),
6263
},
6364
},
65+
{
66+
provide: NavigationService,
67+
useValue: {
68+
navigateToSurveyList: () => {},
69+
isEditSurveyPage: () => false,
70+
onClickSidePanelButton: () => {},
71+
},
72+
},
6473
{
6574
provide: Router,
6675
useValue: {

web/src/app/components/shared/header/header.component.spec.ts

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ import { of } from 'rxjs';
2424
import { AuthService } from 'app/services/auth/auth.service';
2525
import { DataStoreService } from 'app/services/data-store/data-store.service';
2626
import { DraftSurveyService } from 'app/services/draft-survey/draft-survey.service';
27+
import { NavigationService } from 'app/services/navigation/navigation.service';
2728
import { SurveyService } from 'app/services/survey/survey.service';
2829

2930
import { HeaderComponent } from './header.component';
@@ -44,7 +45,19 @@ describe('HeaderComponent', () => {
4445
{ provide: MatDialog, useValue: {} },
4546
{ provide: AuthService, useValue: { getUser$: () => of() } },
4647
{ provide: DraftSurveyService, useValue: {} },
47-
{ provide: Router, useValue: { events: of() } },
48+
{ provide: Router, useValue: { events: of(), url: '' } },
49+
{
50+
provide: NavigationService,
51+
useValue: {
52+
isEditSurveyPage: () => false,
53+
isSurveyPage: () => false,
54+
navigateToSurveyList: () => {},
55+
navigateToEditSurvey: () => {},
56+
navigateToAboutPage: () => {},
57+
navigateToTermsOfService: () => {},
58+
selectSurvey: () => {},
59+
},
60+
},
4861
{
4962
provide: SurveyService,
5063
useValue: {

0 commit comments

Comments
 (0)