Skip to content

Commit

Permalink
Revert "Adding new async publish feature for single and bulk. (#700)"
Browse files Browse the repository at this point in the history
This reverts commit 2a80955.
  • Loading branch information
dr-bizz authored Mar 27, 2024
1 parent 2a80955 commit 6fb0fcb
Show file tree
Hide file tree
Showing 14 changed files with 114 additions and 818 deletions.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,92 +1,35 @@
<div class="modal-body">
<div class="btn-group btn-group-toggle toggle-drafts" data-toggle="buttons">
<label
class="btn btn-success {{
actionType === 'publish' ? 'btn-success' : 'btn-outline-success'
}}"
(click)="switchActionType('publish')"
>
Publish Languages
</label>
<label
class="btn {{
actionType === 'createDrafts'
? 'btn-secondary'
: 'btn-outline-secondary'
}}"
(click)="switchActionType('createDrafts')"
>
Generate Drafts
</label>
</div>

<h5>Languages without a Draft</h5>
<div *ngFor="let translation of resource['latest-drafts-translations']">
<label
class="btn-outline-secondary btn-block translation-btn"
class="btn-secondary btn-block"
ngbButtonLabel
*ngIf="
actionType === 'publish' ||
(actionType === 'createDrafts' && translation['is-published'])
"
*ngIf="translation.is_published"
>
<div class="translation-btn-text">
<input
type="checkbox"
ngbButton
[(ngModel)]="translation.selectedForAction"
/>
{{ translation.language.name }}
</div>
<admin-translation-version-badge [translation]="translation">
</admin-translation-version-badge>
<input
type="checkbox"
ngbButton
[(ngModel)]="translation.generateDraft"
/>
{{ translation.language.name }}
</label>
</div>
<br />

<ngb-alert
type="success"
[dismissible]="true"
*ngFor="let successMessage of sucessfulMessages"
>
{{ successMessage }}
<ngb-alert type="info" [dismissible]="false" *ngIf="saving">
Saving...
</ngb-alert>
<ngb-alert type="info" [dismissible]="false" *ngIf="alertMessage">
{{ alertMessage }}
<ngb-alert type="danger" [dismissible]="false" *ngIf="errorMessage">
{{ errorMessage }}
</ngb-alert>
<ngb-alert
type="danger"
[dismissible]="false"
*ngFor="let error of errorMessage"
>
{{ error }}
</ngb-alert>

<ngb-alert type="info" [dismissible]="false" *ngIf="confirmMessage">
<p>{{ confirmMessage }}</p>
<div class="btn-toolbar justify-content-between">
<button (click)="confirmMessage = null" class="btn btn-danger">
Cancel
</button>
<button (click)="publishOrCreateDrafts()" class="btn btn-success">
Confirm
</button>
</div>
</ngb-alert>

<div class="modal-footer justify-content-between">
<button
class="btn btn-secondary"
(click)="cancel()"
[disabled]="disableButtons"
>
<button class="btn btn-danger" (click)="cancel()">Cancel</button>
<button class="btn btn-success" (click)="showConfirmAlert()">
Generate drafts
</button>
<ngb-alert type="danger" [dismissible]="false" *ngIf="confirmMessage">
{{ confirmMessage }}
<button (click)="generateDrafts()" class="btn btn-dark">Confirm</button>
<button (click)="confirmMessage = null" class="btn btn-secondary">
Cancel
</button>
<button
class="btn btn-success"
(click)="showConfirmAlert()"
[disabled]="disableButtons"
>
{{ actionType === 'publish' ? 'Publish' : 'Generate drafts' }}
</button>
</div>
</ngb-alert>
</div>
Original file line number Diff line number Diff line change
@@ -1,10 +1,4 @@
import {
ComponentFixture,
TestBed,
discardPeriodicTasks,
fakeAsync,
tick,
} from '@angular/core/testing';
import { ComponentFixture, TestBed } from '@angular/core/testing';
import {
NgbActiveModal,
NgbAlert,
Expand All @@ -13,26 +7,20 @@ import {
import { MultipleDraftGeneratorComponent } from './multiple-draft-generator.component';
import { FormsModule } from '@angular/forms';
import { DraftService } from '../../service/draft.service';
import { LanguageService } from '../../service/language.service';
import { ResourceService } from '../../service/resource/resource.service';
import { Resource } from '../../models/resource';
import { Translation } from '../../models/translation';
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;
let fixture: ComponentFixture<MultipleDraftGeneratorComponent>;
let customResourceServiceStub;
let customDraftServiceStub;

const buildTranslation = (
isPublished: boolean,
selectedForAction: boolean,
generateDraft: boolean,
language: string,
) => {
const l = new Language();
Expand All @@ -41,57 +29,15 @@ describe('MultipleDraftGeneratorComponent', () => {
const t = new Translation();
t.language = l;
t.is_published = isPublished;
t['is-published'] = isPublished;
t.selectedForAction = selectedForAction;
t.generateDraft = generateDraft;
return t;
};

beforeEach(() => {
customResourceServiceStub = {
getResource() {},
};
customDraftServiceStub = {
createDraft() {},
publishDraft() {},
};

spyOn(customResourceServiceStub, 'getResource').and.returnValue(
Promise.resolve({
'latest-drafts-translations': [
{
language: { id: 1 },
'publishing-errors': null,
'is-published': false,
},
],
}),
);
spyOn(customDraftServiceStub, 'createDraft').and.returnValue(
Promise.resolve(),
);
spyOn(customDraftServiceStub, 'publishDraft').and.returnValue(
Promise.resolve([
{
'publishing-errors': null,
'is-published': false,
},
]),
);

customResourceServiceStub.getResource();

TestBed.configureTestingModule({
declarations: [
MultipleDraftGeneratorComponent,
TranslationVersionBadgeComponent,
],
declarations: [MultipleDraftGeneratorComponent],
imports: [NgbModule.forRoot(), FormsModule],
providers: [
{ provide: DraftService, useValue: customDraftServiceStub },
{ provide: NgbActiveModal },
{ provide: ResourceService, useValue: customResourceServiceStub },
{ provide: LanguageService },
],
providers: [{ provide: DraftService }, { provide: NgbActiveModal }],
}).compileComponents();

fixture = TestBed.createComponent(MultipleDraftGeneratorComponent);
Expand All @@ -107,97 +53,25 @@ describe('MultipleDraftGeneratorComponent', () => {
const r = new Resource();
r['latest-drafts-translations'] = translations;
comp.resource = r;
comp.actionType = 'publish';

fixture.detectChanges();
});

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

it('shows confirm message to publish selected languages', () => {
it('confirm message lists all 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 publish these languages: Chinese, French?`,
`${comp.baseConfirmMessage} 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('publishOrCreateDrafts() Publish', () => {
it('should send publish 2 languages, and call isPublished() every 5 seconds ', fakeAsync(() => {
comp.showConfirmAlert();
fixture.detectChanges();
spyOn(comp, 'renderMessage');
spyOn(comp, 'isPublished');
comp.publishOrCreateDrafts();
expect(comp.renderMessage).toHaveBeenCalledWith(
MessageType.success,
'Publishing translations...',
);

tick(5500);
fixture.detectChanges();
discardPeriodicTasks();

fixture.whenStable().then(() => {
expect(customDraftServiceStub.publishDraft).toHaveBeenCalledTimes(2);
expect(comp.errorMessage).toEqual([]);
expect(comp.isPublished).toHaveBeenCalledTimes(1);

tick(5500);
fixture.detectChanges();
discardPeriodicTasks();

expect(comp.isPublished).toHaveBeenCalledTimes(2);
});
}));

it('should return publishing errors and warn the user.', fakeAsync(() => {
customDraftServiceStub.publishDraft.and.returnValue(
Promise.resolve([
{
'publishing-errors': 'Error publishing...',
'is-published': false,
},
]),
);
spyOn(comp, 'renderMessage');
spyOn(comp, 'isPublished');

comp.showConfirmAlert();
fixture.detectChanges();
comp.publishOrCreateDrafts();

tick(5500);
fixture.detectChanges();
discardPeriodicTasks();

fixture.whenStable().then(() => {
expect(comp.errorMessage).toEqual([
'Error publishing...',
'Error publishing...',
]);
});
}));
});
});
Loading

0 comments on commit 6fb0fcb

Please sign in to comment.