Skip to content

Commit

Permalink
Merge pull request #664 from europeana/develop
Browse files Browse the repository at this point in the history
Merge Develop to Master for Sandbox v3
  • Loading branch information
andyjmaclean authored Jul 20, 2022
2 parents ca9c772 + 4b6e260 commit 23ca4f3
Show file tree
Hide file tree
Showing 81 changed files with 2,351 additions and 1,033 deletions.
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@
"build-shared": "ng build shared",
"build": "npm run build-shared && npm run build-metis && npm run build-sandbox",
"clean": "rm -rf ./dist && rm -rf ./projects/**/dist && rm -rf ./projects/**/coverage",
"prettier": "prettier --write '{tools/**/*.{ts,js,json,mjs},projects/**/{src,cypress,test-data}/**/*.{ts,js,json,scss,html}}' '*.{js,json}'",
"prettier:ci": "prettier --list-different '(tools/**/*.{ts,js,json,mjs},projects/**/{src,cypress,test-data}/**/*.{ts,js,json,scss,html}}' '*.{js,json}'",
"prettier": "prettier --write '{tools/**/*.{ts,js,json,mjs},shared-styles/**/*.scss,projects/**/{shared-styles,src,cypress,test-data}/**/*.{ts,js,json,scss,html}}' '*.{scss,js,json}'",
"prettier:ci": "prettier --list-different '(tools/**/*.{ts,js,json,mjs},shared-styles/**/*.scss,projects/**/{src,cypress,test-data}/**/*.{ts,js,json,scss,html}}' '*.{js,json}'",
"lint-any": "eslint --ext .js,.ts projects/${npm_config_project} --fix",
"lint:ci-any": "eslint --ext .ts projects/${npm_config_project}/src/app",
"lint-metis": "npm run lint-any --project=metis",
Expand Down
7 changes: 5 additions & 2 deletions projects/metis/cypress/integration/dataset.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ context('metis-ui', () => {

beforeEach(() => {
setupDatasetPage('edit', 0);
cy.wait(50);
});

const expectedId = '0';
Expand All @@ -39,10 +40,12 @@ context('metis-ui', () => {
cy.get('@dd').contains('865');
cy.get('@dd').contains(lastPublished);

cy.get('.dataset-actionbar .status').as('status');
cy.get('@status').contains('Finished');
cy.get('.dataset-actionbar .status').contains('Finished');
cy.get('.unfit-to-publish').contains('This dataset is not fit for publication');

cy.get('.dataset-actionbar .started-by').as('startedBy');
cy.get('@startedBy').contains('Valentine');

cy.get('.table-grid.last-execution .table-grid-row-start').should('have.length', 11);
getHistoryRow(0).contains('Check Links');
getHistoryRow(1).contains('Depublish');
Expand Down
73 changes: 73 additions & 0 deletions projects/metis/cypress/integration/mapping.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
import { cleanupUser, setupUser } from '../support/helpers';

context('metis-ui', () => {
describe('mapping', () => {
afterEach(() => {
cleanupUser();
});

beforeEach(() => {
cy.server();
setupUser();
cy.visit('/dataset/mapping/0');
});
const force = { force: true };
const selBtnInitDefault = '[data-e2e=xslt-init-default]';
const selBtnTryDefaultXSLT = '[data-e2e=xslt-try-default]';
const selEditors = '.view-sample';
const selStatistics = '.view-statistics';

it('should show the statistics', () => {
cy.get(selStatistics).should('have.length', 1);
cy.get(selEditors).should('have.length', 1);
});

it('should show try out XSLT', () => {
const btnLabel = 'Go back to Mapping';

cy.get('button')
.contains(btnLabel)
.should('not.exist');
cy.url().should('not.contain', '/preview');
cy.url().should('contain', '/mapping');

cy.get(selBtnTryDefaultXSLT)
.first()
.click();

cy.url().should('contain', '/preview');
cy.url().should('not.contain', '/mapping');
cy.get('button')
.contains(btnLabel)
.should('have.length', 1);
cy.get('button')
.contains(btnLabel)
.click(force);
cy.url().should('not.contain', '/preview');
cy.url().should('contain', '/mapping');
});

it('should initialise an editor with the default XSLT', () => {
cy.get(selBtnInitDefault).should('have.length', 0);
cy.visit('/dataset/mapping/1');
cy.get(selBtnInitDefault).should('have.length', 1);

cy.get(selEditors).should('have.length', 1);
cy.get(selBtnInitDefault).click();
cy.get(selEditors).should('have.length', 2);

cy.get('button')
.contains('Cancel')
.should('have.length', 1);
cy.get('button')
.contains('Reset to default XSLT')
.should('have.length', 1);
cy.get('button')
.contains('Save')
.should('have.length', 1);
cy.get('button')
.contains('Save XSLT & Try it out')
.should('have.length', 1);
});
});
});
81 changes: 65 additions & 16 deletions projects/metis/cypress/integration/preview.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -88,35 +88,84 @@ context('metis-ui', () => {
});

it('should show a single menu on initialisation', () => {
cy.get(selMenuDate).should('have.length', 1);
cy.get(selMenuPlugin).should('have.length', 0);
cy.get(selMenuCompare).should('have.length', 0);
cy.get(selMenuDateItems).should('have.length', 0);
cy.get(selMenuPluginItems).should('have.length', 0);
cy.get(selMenuCompareItems).should('have.length', 0);
cy.get(selMenuDate).should('not.exist');
cy.get(selMenuPlugin).should('not.exist');
cy.get(selMenuCompare).should('not.exist');
cy.get(selMenuDateItems).should('not.exist');
cy.get(selMenuPluginItems).should('not.exist');
cy.get(selMenuCompareItems).should('not.exist');
});

it('should open the menus successively', () => {
cy.scrollTo(0, 100000);
cy.get(selMenuDateItems).should('have.length', 0);
cy.get(selMenuPluginItems).should('have.length', 0);
cy.get(selMenuCompareItems).should('have.length', 0);
cy.get(selMenuDateItems).should('not.exist');
cy.get(selMenuPluginItems).should('not.exist');
cy.get(selMenuCompareItems).should('not.exist');
fillMenus(3);
checkMenusVisible();
});

it('should restore the selection when the user leaves then returns', () => {
fillMenus(3);
leaveAndReturn();
cy.get(selEditorDefault).should('have.length', 0);
cy.get(selEditorDefault).should('not.exist');
cy.get(selEditorCompare).should('be.visible');
checkMenusVisible();
});

it('should maintain themed editors', () => {
fillMenus(3);
const selEditorOps = '.theme-ctrl';
const selIndicatorActiveBlack = '.theme-ctrl.black.active';
const selIndicatorActiveWhite = '.theme-ctrl.active:not(.black)';

const selLinkThemeBlack = '[data-e2e=set-theme-white]';
const selLinkThemeWhite = '[data-e2e=set-theme-white]';
console.log(selLinkThemeBlack + selLinkThemeWhite + selIndicatorActiveWhite);

cy.get(selEditorOps).should('have.length', 5);
cy.get(selLinkThemeBlack).should('not.exist', 1);
cy.get(selLinkThemeWhite).should('not.exist', 1);

cy.get(selEditorOps)
.first()
.click(force);

cy.get(selLinkThemeBlack).should('have.length', 1);
cy.get(selLinkThemeWhite).should('have.length', 1);
cy.get(selIndicatorActiveBlack).should('not.exist');
cy.get(selIndicatorActiveWhite).should('have.length', 1);

cy.get(selLinkThemeBlack).click(force);

// re-open the menu, check switched
cy.get(selEditorOps)
.first()
.click(force);

cy.get(selLinkThemeBlack).should('have.length', 1);
cy.get(selLinkThemeWhite).should('have.length', 1);
cy.get(selIndicatorActiveBlack).should('have.length', 1);
cy.get(selIndicatorActiveWhite).should('not.exist');

// check the last item is switched too
cy.get(selEditorOps)
.first()
.click(force);
cy.get(selEditorOps)
.last()
.click(force);

cy.get(selLinkThemeBlack).should('have.length', 1);
cy.get(selLinkThemeWhite).should('have.length', 1);
cy.get(selIndicatorActiveBlack).should('have.length', 1);
cy.get(selIndicatorActiveWhite).should('not.exist');
});

it('should clear the editors when the user changes the date', () => {
const checkEditorsHidden = (): void => {
cy.get(selEditorCompare).should('have.length', 0);
cy.get(selEditorDefault).should('have.length', 0);
cy.get(selEditorCompare).should('not.exist');
cy.get(selEditorDefault).should('not.exist');
};

checkEditorsHidden();
Expand All @@ -134,18 +183,18 @@ context('metis-ui', () => {
cy.get(selEditorCompare).should('be.visible');

fillMenus(1);
cy.get(selEditorCompare).should('have.length', 0);
cy.get(selEditorCompare).should('not.exist');
leaveAndReturn();
cy.get(selEditorCompare).should('have.length', 0);
cy.get(selEditorCompare).should('not.exist');
fillMenus(3);
cy.get(selEditorCompare).should('be.visible');
leaveAndReturn();
cy.get(selEditorCompare).should('be.visible');

fillMenus(2);
cy.get(selEditorCompare).should('have.length', 0);
cy.get(selEditorCompare).should('not.exist');
leaveAndReturn();
cy.get(selEditorCompare).should('have.length', 0);
cy.get(selEditorCompare).should('not.exist');
});
});
});
65 changes: 65 additions & 0 deletions projects/metis/cypress/integration/report.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
import { cleanupUser, setupUser } from '../support/helpers';

context('metis-ui', () => {
describe('report', () => {
const force = { force: true };
const selectorModal = '.modal';
const selectorOpener = '.table-grid [data-e2e=open-report]';
const selectorDownloadLink = `${selectorModal} .btn-download`;
const selectorDownloadError = `${selectorModal} .download-error`;

beforeEach(() => {
cy.server();
setupUser();
cy.visit('/dataset/log/0');
cy.wait(1000);
});

afterEach(() => {
cleanupUser();
});

it('should open the report', () => {
cy.get(selectorModal).should('not.exist');
cy.get(selectorOpener).should('have.length.gt', 1);
cy.get(selectorOpener)
.eq(2)
.click(force);
cy.get(selectorModal).should('have.length', 1);
});

it('should offer downloads for non-harvest topologies', () => {
cy.get(selectorOpener)
.first()
.click(force);
cy.get(selectorDownloadLink).should('have.length', 3);
});

it('should not offer downloads for harvest topologies', () => {
cy.get(selectorOpener)
.last()
.click(force);
cy.get(selectorDownloadLink).should('not.exist');
});

it('should handle downloads', () => {
cy.get(selectorOpener)
.first()
.click(force);
cy.get(selectorDownloadLink)
.last()
.click(force);
cy.get(selectorDownloadError).should('not.exist');
});

it('should handle download fails', () => {
cy.get(selectorOpener)
.first()
.click(force);
cy.get(selectorDownloadLink)
.first()
.click(force);
cy.get(selectorDownloadError).should('have.length', 1);
});
});
});
41 changes: 23 additions & 18 deletions projects/metis/src/app/_helpers/cache.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { ConnectableObservable, Observable, of } from 'rxjs';
import { publishLast, tap } from 'rxjs/operators';
import { AsyncSubject, connectable, Observable, of } from 'rxjs';
import { tap } from 'rxjs/operators';

export class SingleCache<Value> {
private observable?: ConnectableObservable<Value>;
private observable?: Observable<Value>;

constructor(private readonly sourceFn: () => Observable<Value>) {}

Expand All @@ -16,15 +16,17 @@ export class SingleCache<Value> {
}

// Create new observable.
const observable = this.sourceFn().pipe(
tap(
(_) => undefined,
(_) => this.clear(),
() => undefined
const observable = connectable(
this.sourceFn().pipe(
tap({
error: () => this.clear()
})
),
publishLast()
) as ConnectableObservable<Value>;

{
connector: () => new AsyncSubject<Value>(),
resetOnDisconnect: false
}
);
// Return local variable, as this.observable might be cleared by the connect call.
this.observable = observable;
observable.connect();
Expand Down Expand Up @@ -62,14 +64,17 @@ export class KeyedCache<Value> {
}

// Create new observable.
const observable = this.sourceFn(key).pipe(
tap(
(_) => undefined,
(_) => this.clear(key),
() => undefined
const observable = connectable(
this.sourceFn(key).pipe(
tap({
error: (_) => this.clear(key)
})
),
publishLast()
) as ConnectableObservable<Value>;
{
connector: () => new AsyncSubject<Value>(),
resetOnDisconnect: false
}
);

// Return local variable, as this.observableByKey[key] might be cleared by the connect call.
this.observableByKey[key] = observable;
Expand Down
1 change: 1 addition & 0 deletions projects/metis/src/app/_helpers/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ export * from './calcprogress';
export * from './can-cancel-workflow';
export * from './copycontent';
export * from './statusclassfromplugin';
export * from './trigger-download';
export * from './match-password-validator';
export * from './password-strength';
export * from './stringify-http-error';
Expand Down
13 changes: 13 additions & 0 deletions projects/metis/src/app/_helpers/trigger-download.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import { XmlSample } from '../_models';

export function triggerXmlDownload(xml?: XmlSample): void {
if (xml) {
const anchor = document.createElement('a');
anchor.href = `data:text/xml,${encodeURIComponent(xml.xmlRecord)}`;
anchor.target = '_blank';
anchor.download = `record-${xml.ecloudId}.xml`;
document.body.appendChild(anchor);
anchor.click();
document.body.removeChild(anchor);
}
}
4 changes: 2 additions & 2 deletions projects/metis/src/app/_mocked/mockedworkflow.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -693,9 +693,9 @@ export class MockWorkflowService {
return of(mockHistoryVersions).pipe(delay(1));
}

getWorkflowComparisons(): Observable<XmlSample[]> {
getWorkflowRecordsById(): Observable<XmlSample[]> {
if (this.errorMode) {
return throwError(new Error('mock getWorkflowComparisons throws error...'));
return throwError(new Error('mock getWorkflowRecordsById throws error...'));
}
return of(mockXmlSamples);
}
Expand Down
Loading

0 comments on commit 23ca4f3

Please sign in to comment.