Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SF-3084 Fix checking overview page not showing questions correctly #2959

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,16 @@ describe('CheckingOverviewComponent', () => {
expect(env.noQuestionsLabel).not.toBeNull();
}));

it('should not display loading if user is offline', fakeAsync(() => {
const env = new TestEnvironment();
env.testOnlineStatusService.setIsOnline(false);
tick();
env.fixture.detectChanges();
expect(env.loadingQuestionsLabel).toBeNull();
expect(env.noQuestionsLabel).not.toBeNull();
env.waitForQuestions();
}));

it('should not display "Add question" button for community checker', fakeAsync(() => {
const env = new TestEnvironment();
env.setCurrentUser(env.checkerUser);
Expand Down Expand Up @@ -420,6 +430,25 @@ describe('CheckingOverviewComponent', () => {
discardPeriodicTasks();
}));

it('should not display loading if user is offline', fakeAsync(async () => {
const env = new TestEnvironment();
const questionDoc: QuestionDoc = env.realtimeService.get(
QuestionDoc.COLLECTION,
getQuestionDocId('project01', 'q7Id')
);
await questionDoc.submitJson0Op(op => {
op.set(d => d.isArchived, false);
});
env.testOnlineStatusService.setIsOnline(false);
env.fixture.detectChanges();
tick();
env.fixture.detectChanges();
expect(env.loadingArchivedQuestionsLabel).toBeNull();
expect(env.noArchivedQuestionsLabel).not.toBeNull();

env.waitForQuestions();
}));

it('archives and republishes a question', fakeAsync(() => {
const env = new TestEnvironment();
env.waitForQuestions();
Expand Down Expand Up @@ -1067,6 +1096,7 @@ class TestEnvironment {
}
);
this.setCurrentUser(this.adminUser);
this.testOnlineStatusService.setIsOnline(true);

this.fixture = TestBed.createComponent(CheckingOverviewComponent);
this.component = this.fixture.componentInstance;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,24 +75,20 @@ export class CheckingOverviewComponent extends DataLoadingComponent implements O
}

get showQuestionsLoadingMessage(): boolean {
return this.questionsQuery?.ready !== true && this.allQuestionsCount === 0;
return !this.questionsLoaded && this.allQuestionsCount === 0;
}

get showArchivedQuestionsLoadingMessage(): boolean {
return (
this.questionsQuery?.ready !== true &&
(this.questionsQuery?.docs || []).filter(qd => qd.data?.isArchived).length === 0
);
return !this.questionsLoaded && (this.questionsQuery?.docs ?? []).filter(qd => qd.data?.isArchived).length === 0;
}

get showNoQuestionsMessage(): boolean {
return this.questionsQuery?.ready === true && this.allQuestionsCount === 0;
return this.questionsLoaded && this.allQuestionsCount === 0;
}

get showNoArchivedQuestionsMessage(): boolean {
return (
this.questionsQuery?.ready === true &&
this.questionsQuery?.docs.filter(qd => qd.data != null && qd.data.isArchived).length === 0
this.questionsLoaded && this.questionsQuery?.docs.filter(qd => qd.data != null && qd.data.isArchived).length === 0
);
}

Expand Down Expand Up @@ -194,6 +190,11 @@ export class CheckingOverviewComponent extends DataLoadingComponent implements O
return this.questionsQuery.docs.filter(qd => qd.data != null && !qd.data.isArchived);
}

private get questionsLoaded(): boolean {
// if the user is offline, 'ready' will never be true, but the query will still return the offline docs
return !this.onlineStatusService.isOnline || this.questionsQuery?.ready === true;
}

ngOnInit(): void {
let projectDocPromise: Promise<SFProjectProfileDoc>;
const projectId$ = this.activatedRoute.params.pipe(
Expand Down
Loading