Skip to content

Commit

Permalink
Merge GT-1968-update-publishing-status into staging
Browse files Browse the repository at this point in the history
  • Loading branch information
stage-branch-merger[bot] authored Jan 10, 2024
2 parents b552f96 + e2aa35f commit 90c4df9
Show file tree
Hide file tree
Showing 2 changed files with 113 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ import { By } from '@angular/platform-browser';
import { NgbButtonLabel } from '@ng-bootstrap/ng-bootstrap';
import { Language } from '../../models/language';
import { DebugElement } from '@angular/core';
import { TranslationVersionBadgeComponent } from '../translation/translation-version-badge/translation-version-badge.component';
import { MessageType } from '../../models/message';

describe('MultipleDraftGeneratorComponent', () => {
let comp: MultipleDraftGeneratorComponent;
Expand All @@ -38,7 +40,10 @@ describe('MultipleDraftGeneratorComponent', () => {

beforeEach(() => {
TestBed.configureTestingModule({
declarations: [MultipleDraftGeneratorComponent],
declarations: [
MultipleDraftGeneratorComponent,
TranslationVersionBadgeComponent,
],
imports: [NgbModule.forRoot(), FormsModule],
providers: [
{ provide: DraftService },
Expand Down Expand Up @@ -66,21 +71,47 @@ describe('MultipleDraftGeneratorComponent', () => {
fixture.detectChanges();
});

it('only shows languages without drafts', () => {
it('shows languages with and without drafts', () => {
expect(
fixture.debugElement.queryAll(By.directive(NgbButtonLabel)).length,
).toBe(3);
).toBe(4);
});

it('confirm message lists all languages', () => {
it('shows confirm message to publish selected languages', () => {
comp.showConfirmAlert();
fixture.detectChanges();

const alert: DebugElement = fixture.debugElement.query(
By.directive(NgbAlert),
);
expect(alert.nativeElement.textContent).toContain(
`Are you sure you want to generate a draft for these languages Chinese, French?`,
`Are you sure you want to publish these languages: Chinese, French?`,
);
});

it('shows confirm message to create a draft for selected languages', () => {
comp.actionType = 'createDrafts';
comp.showConfirmAlert();
fixture.detectChanges();

const alert: DebugElement = fixture.debugElement.query(
By.directive(NgbAlert),
);
expect(alert.nativeElement.textContent).toContain(
`Are you sure you want to generate a draft for these languages: Chinese, French?`,
);
});

describe('Publish languages', () => {
it('shows confirm message to publish selected languages', () => {
comp.showConfirmAlert();
fixture.detectChanges();
spyOn(comp, 'renderMessage');
comp.publishOrCreateDrafts();
expect(comp.renderMessage).toHaveBeenCalledWith(
MessageType.success,
'Publishing translations...',
);
});
});
});
86 changes: 77 additions & 9 deletions src/app/components/translation/translation.component.spec.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,11 @@
import { async, ComponentFixture, TestBed } from '@angular/core/testing';
import {
async,
ComponentFixture,
discardPeriodicTasks,
fakeAsync,
TestBed,
tick,
} from '@angular/core/testing';
import { TranslationComponent } from './translation.component';
import { NgbModal, NgbModule } from '@ng-bootstrap/ng-bootstrap';
import { DraftService } from '../../service/draft.service';
Expand All @@ -12,10 +19,12 @@ import { Page } from '../../models/page';
import { CustomPage } from '../../models/custom-page';
import { ResourceComponent } from '../resource/resource.component';
import anything = jasmine.anything;
import { ResourceService } from '../../service/resource/resource.service';
import { CustomPageService } from '../../service/custom-page.service';
import { CustomManifestService } from '../../service/custom-manifest.service';
import { CustomManifest } from '../../models/custom-manifest';
import { CustomTipService } from '../../service/custom-tip.service';
import { CustomManifest } from '../../models/custom-manifest';
import { MessageType } from '../../models/message';
import { TranslationVersionBadgeComponent } from './translation-version-badge/translation-version-badge.component';

describe('TranslationComponent', () => {
Expand All @@ -26,6 +35,8 @@ describe('TranslationComponent', () => {
let customTipsServiceStub;
let modalServiceStub;
let customManifestServiceStub;
let customDraftServiceStub;
let customResourceServiceStub;

let resourceComponent: ResourceComponent;
let language: Language;
Expand Down Expand Up @@ -73,6 +84,12 @@ describe('TranslationComponent', () => {
modalServiceStub = {
open() {},
};
customDraftServiceStub = {
publishDraft() {},
};
customResourceServiceStub = {
getResource() {},
};
const modalRef = {
componentInstance: {},
result: Promise.resolve(),
Expand All @@ -87,20 +104,33 @@ describe('TranslationComponent', () => {
spyOn(customManifestServiceStub, 'delete').and.returnValue(
Promise.resolve(),
);
spyOn(customDraftServiceStub, 'publishDraft').and.returnValue(
Promise.resolve([
{
'publishing-errors': null,
},
]),
);
spyOn(customResourceServiceStub, 'getResource').and.returnValue(
Promise.resolve(),
);

customPageServiceStub.delete();
modalServiceStub.open();
customManifestServiceStub.delete();
customDraftServiceStub.publishDraft();
customResourceServiceStub.getResource();

TestBed.configureTestingModule({
declarations: [TranslationComponent, TranslationVersionBadgeComponent],
imports: [NgbModule.forRoot()],
providers: [
{ provide: DraftService },
{ provide: DraftService, useValue: customDraftServiceStub },
{ provide: CustomPageService, useValue: customPageServiceStub },
{ provide: CustomTipService, useValue: customTipsServiceStub },
{ provide: CustomManifestService, useValue: customManifestServiceStub },
{ provide: NgbModal, useValue: modalServiceStub },
{ provide: ResourceService, useValue: customResourceServiceStub },
],
}).compileComponents();
}));
Expand All @@ -111,6 +141,9 @@ describe('TranslationComponent', () => {

resourceComponent = new ResourceComponent(null, null);
comp.translationLoaded = resourceComponent.translationLoaded$;
comp.errorMessage = '';
comp.alertMessage = '';
comp.sucessfulMessage = '';

const pageWithCustomPage = buildPage(2);

Expand Down Expand Up @@ -139,11 +172,11 @@ describe('TranslationComponent', () => {
fixture.detectChanges();
});

it(`should show action button with 'New Draft'`, () => {
it(`should show action button with 'Publish'`, () => {
const element: DebugElement = fixture.debugElement
.queryAll(By.css('.btn.btn-secondary'))
.queryAll(By.css('.btn.btn-success'))
.pop();
expect(element.nativeElement.textContent.trim()).toBe('New Draft');
expect(element.nativeElement.textContent.trim()).toBe('Publish');
});

it(`should show status badge with 'None'`, () => {
Expand All @@ -152,6 +185,41 @@ describe('TranslationComponent', () => {
);
expect(element.nativeElement.textContent).toBe('None');
});

describe('publish a new translation (Server creates draft)', () => {
let translation: Translation;

beforeEach(() => {
translation = new Translation();
translation.none = true;
translation.language = language;
translation.resource = comp.resource;

comp.resource['latest-drafts-translations'] = [translation];
comp.reloadTranslation();
fixture.detectChanges();
});

it('should git resource endpoint', fakeAsync(() => {
spyOn(comp, 'renderMessage');
spyOn(comp, 'isPublished');
comp.publish();

expect(comp.renderMessage).toHaveBeenCalledWith(MessageType.error, '');
expect(comp.renderMessage).toHaveBeenCalledWith(
MessageType.success,
'Publishing...',
);

tick(5500);
fixture.detectChanges();

discardPeriodicTasks();
fixture.whenStable().then(() => {
expect(comp.isPublished).toHaveBeenCalled();
});
}));
});
});

describe('language has existing translation(s)', () => {
Expand Down Expand Up @@ -286,15 +354,15 @@ describe('TranslationComponent', () => {
});

describe('action button', () => {
it(`should say 'New Draft' for published translations`, () => {
it(`should say 'Publish' for published translations`, () => {
translation.is_published = true;

fixture.detectChanges();

const element: DebugElement = fixture.debugElement
.queryAll(By.css('.btn.btn-secondary'))
.queryAll(By.css('.btn.btn-success'))
.pop();
expect(element.nativeElement.textContent.trim()).toBe('New Draft');
expect(element.nativeElement.textContent.trim()).toBe('Publish');
});

it(`should say 'Publish' for drafts`, () => {
Expand Down

0 comments on commit 90c4df9

Please sign in to comment.