Skip to content

Commit

Permalink
rebased
Browse files Browse the repository at this point in the history
  • Loading branch information
Tcharl committed Nov 7, 2024
1 parent 7ffcb51 commit 68358ab
Show file tree
Hide file tree
Showing 8 changed files with 5 additions and 61 deletions.
3 changes: 2 additions & 1 deletion generators/angular/generator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ import {
addItemToAdminMenu,
addRoute,
addToEntitiesMenu,
buildAngularFormPath as angularFormPath,
isTranslatedAngularFile,
translateAngularFilesTransform,
} from './support/index.js';
Expand Down Expand Up @@ -195,7 +196,7 @@ export default class AngularGenerator extends BaseApplicationGenerator<
return angularFormPath(reference, prefix);
};

entity.generateTestEntityId = (primaryKey, index = 0, wrapped = true) => {
entity.generateTestEntityId = (primaryKey, index: 0 | 1 | 'random' = 0, wrapped = true) => {
return getTestEntityId(primaryKey, index, wrapped);
};
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -136,11 +136,7 @@ describe('<%= entityAngularName %> Management Component', () => {

describe('track<%= primaryKey.nameCapitalized %>', () => {
it('Should forward to <%= entityInstance %>Service', () => {
<<<<<<< HEAD
const entity = <%- tsPrimaryKeySamples[0] %>;
=======
const entity = <%- generateTestEntityPrimaryKey(primaryKey, 0) %>;
>>>>>>> 6a2ff33b25 (generator-specific entity)
jest.spyOn(service, 'get<%= entityAngularName %>Identifier');
const <%= primaryKey.name %> = comp.track<%= primaryKey.nameCapitalized %>(entity);
expect(service.get<%= entityAngularName %>Identifier).toHaveBeenCalledWith(entity);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -219,11 +219,7 @@ describe('<%= entityAngularName %> Service', () => {
});

it('Should return false if one entity is null', () => {
<<<<<<< HEAD
const entity1 = <%- tsPrimaryKeySamples[0] %>;
=======
const entity1 = <%- generateTestEntityPrimaryKey(primaryKey, 0) %>;
>>>>>>> 6a2ff33b25 (generator-specific entity)
const entity2 = null;

const compareResult1 = service.compare<%= entityAngularName %>(entity1, entity2);
Expand All @@ -234,13 +230,8 @@ describe('<%= entityAngularName %> Service', () => {
});

it('Should return false if primaryKey differs', () => {
<<<<<<< HEAD
const entity1 = <%- tsPrimaryKeySamples[0] %>;
const entity2 = <%- tsPrimaryKeySamples[1] %>;
=======
const entity1 = <%- generateTestEntityPrimaryKey(primaryKey, 0) %>;
const entity2 = <%- generateTestEntityPrimaryKey(primaryKey, 1) %>;
>>>>>>> 6a2ff33b25 (generator-specific entity)

const compareResult1 = service.compare<%= entityAngularName %>(entity1, entity2);
const compareResult2 = service.compare<%= entityAngularName %>(entity2, entity1);
Expand All @@ -250,13 +241,8 @@ describe('<%= entityAngularName %> Service', () => {
});

it('Should return false if primaryKey matches', () => {
<<<<<<< HEAD
const entity1 = <%- tsPrimaryKeySamples[0] %>;
const entity2 = <%- tsPrimaryKeySamples[0] %>;
=======
const entity1 = <%- generateTestEntityPrimaryKey(primaryKey, 0) %>;
const entity2 = <%- generateTestEntityPrimaryKey(primaryKey, 0) %>;
>>>>>>> 6a2ff33b25 (generator-specific entity)

const compareResult1 = service.compare<%= entityAngularName %>(entity1, entity2);
const compareResult2 = service.compare<%= entityAngularName %>(entity2, entity1);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -175,11 +175,7 @@ _%>
<option [ngValue]="null" selected></option>
}
<%_ } else { _%>
<<<<<<< HEAD
@if (editForm.get(['<%- relationship.propertyName %>'])!.value == null) {
=======
@if (editForm.get([<%- buildAngularFormPath(relationship.reference) %>])!.value == null) {
>>>>>>> 6a2ff33b25 (generator-specific entity)
<option [ngValue]="null" selected></option>
}
<%_ } _%>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,22 +17,13 @@
limitations under the License.
-%>
<%_
<<<<<<< HEAD
const tsKeyId = primaryKey.tsSampleValues[0];
=======
const tsKeyId = generateTestEntityId(primaryKey.type);
>>>>>>> 6a2ff33b25 (generator-specific entity)
const allRelationshipsByEntityNeedingOptions = Object
.values(relationshipsByOtherEntity)
.map(relationships => relationships.filter(rel => rel.persistableRelationship && !rel.otherEntity.embedded))
.filter(relationships => relationships.length > 0);
<<<<<<< HEAD
const testEntityPrimaryKey0 = tsPrimaryKeySamples[0];
const testEntityPrimaryKey1 = tsPrimaryKeySamples[1];
=======
const testEntityPrimaryKey0 = generateTestEntityPrimaryKey(primaryKey, 0);
const testEntityPrimaryKey1 = generateTestEntityPrimaryKey(primaryKey, 1);
>>>>>>> 6a2ff33b25 (generator-specific entity)
_%>
import { ComponentFixture, TestBed } from '@angular/core/testing';
import { provideHttpClient, HttpResponse } from '@angular/common/http';
Expand Down Expand Up @@ -104,24 +95,14 @@ describe('<%= entityAngularName %> Management Update Component', () => {
<%_ for (const relationship of relationshipsWithCustomSharedOptions) { _%>
<%_ const reference = relationship.reference _%>
<%_ if (relationship.collection) { _%>
<<<<<<< HEAD
const <%= reference.name %> : I<%= otherEntity.entityAngularName %>[] = [<%- otherEntity.tsPrimaryKeySamples[0] %>];
<%_ } else { _%>
const <%= reference.name %> : I<%= otherEntity.entityAngularName %> = <%- otherEntity.tsPrimaryKeySamples[0] %>;
=======
const <%= reference.name %> : I<%= otherEntity.entityAngularName %>[] = [<%- generateTestEntityPrimaryKey(otherEntity.primaryKey) %>];
<%_ } else { _%>
const <%= reference.name %> : I<%= otherEntity.entityAngularName %> = <%- generateTestEntityPrimaryKey(otherEntity.primaryKey) %>;
>>>>>>> 6a2ff33b25 (generator-specific entity)
<%_ } _%>
<%= entityInstance %>.<%= reference.name %> = <%= reference.name %>;
<%_ } _%>

<<<<<<< HEAD
const <%= otherEntity.entityInstance %>Collection: I<%= otherEntity.entityAngularName %>[] = [<%- otherEntity.tsPrimaryKeySamples[0] %>];
=======
const <%= otherEntity.entityInstance %>Collection: I<%= otherEntity.entityAngularName %>[] = [<%- generateTestEntityPrimaryKey(otherEntity.primaryKey) %>];
>>>>>>> 6a2ff33b25 (generator-specific entity)
jest.spyOn(<%= otherEntity.entityInstance %>Service, 'query').mockReturnValue(of(new HttpResponse({ body: <%= otherEntity.entityInstance %>Collection })));
const additional<%= otherEntity.entityAngularNamePlural %> = [
<%_ for (const relationship of relationshipsWithCustomSharedOptions) { _%>
Expand Down Expand Up @@ -149,17 +130,10 @@ describe('<%= entityAngularName %> Management Update Component', () => {
<%_ const reference = relationship.reference _%>
it('Should call <%= reference.name %> query and add missing value', () => {
const <%= entityInstance %> : I<%= entityAngularName %> = <%- testEntityPrimaryKey1 %>;
<<<<<<< HEAD
const <%= reference.name %> : I<%= otherEntity.entityAngularName %> = <%- otherEntity.tsPrimaryKeySamples[0] %>;
<%= entityInstance %>.<%= reference.name %> = <%= reference.name %>;

const <%= reference.name %>Collection: I<%= otherEntity.entityAngularName %>[] = [<%- otherEntity.tsPrimaryKeySamples[0] %>];
=======
const <%= reference.name %> : I<%= otherEntity.entityAngularName %> = <%- generateTestEntityPrimaryKey(otherEntity.primaryKey) %>;
<%= entityInstance %>.<%= reference.name %> = <%= reference.name %>;

const <%= reference.name %>Collection: I<%= otherEntity.entityAngularName %>[] = [<%- generateTestEntityPrimaryKey(otherEntity.primaryKey) %>];
>>>>>>> 6a2ff33b25 (generator-specific entity)
jest.spyOn(<%= otherEntity.entityInstance %>Service, 'query').mockReturnValue(of(new HttpResponse({ body: <%= reference.name %>Collection })));
const expectedCollection: I<%= otherEntity.entityAngularName %>[] = [<%= reference.name %>, ...<%= reference.name %>Collection];
jest.spyOn(<%= otherEntity.entityInstance %>Service, 'add<%= otherEntity.entityAngularName %>ToCollectionIfMissing').mockReturnValue(expectedCollection);
Expand All @@ -179,11 +153,7 @@ describe('<%= entityAngularName %> Management Update Component', () => {
<%_ for (const relationshipsByEntityNeedingOptions of allRelationshipsByEntityNeedingOptions) { _%>
<%_ for (const relationship of relationshipsByEntityNeedingOptions) { _%>
<%_ const otherEntity = relationship.otherEntity _%>
<<<<<<< HEAD
const <%= relationship.relationshipName %>: I<%= otherEntity.entityAngularName %> = <%- otherEntity.tsPrimaryKeySamples[0] %>;
=======
const <%= relationship.relationshipName %>: I<%= otherEntity.entityAngularName %> = <%- generateTestEntityPrimaryKey(otherEntity.primaryKey) %>;
>>>>>>> 6a2ff33b25 (generator-specific entity)
<%= entityInstance %>.<%= relationship.reference.name %> = <%= relationship.collection ? `[${relationship.relationshipName}]` : relationship.relationshipName %>;
<%_ } _%>
<%_ } _%>
Expand Down Expand Up @@ -284,13 +254,8 @@ _%>
_%>
describe('compare<%= otherEntity.entityAngularName %>', () => {
it('Should forward to <%= otherEntity.entityInstance %>Service', () => {
<<<<<<< HEAD
const entity = <%- otherEntity.tsPrimaryKeySamples[0] %>;
const entity2 = <%- otherEntity.tsPrimaryKeySamples[1] %>;
=======
const entity = <%- generateTestEntityPrimaryKey(otherEntity.primaryKey, 0) %>;
const entity2 = <%- generateTestEntityPrimaryKey(otherEntity.primaryKey, 1) %>;
>>>>>>> 6a2ff33b25 (generator-specific entity)
jest.spyOn(<%= otherEntity.entityInstance %>Service, 'compare<%= otherEntity.entityAngularName %>');
comp.compare<%= otherEntity.entityAngularName %>(entity, entity2);
expect(<%= otherEntity.entityInstance %>Service.compare<%= otherEntity.entityAngularName %>).toHaveBeenCalledWith(entity, entity2);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
* limitations under the License.
*/
/**
* Will be deprecated and merged into AngularApplication
* @deprecated Will be deprecated and merged into types.d/AngularApplication
*/
export type PartialAngularApplication = {
angularLocaleId: string;
Expand Down
2 changes: 1 addition & 1 deletion generators/angular/types.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ export interface AngularEntity extends Entity {
* @param wrapped if the value should be within quotes
* @returns {string|number|string}
*/
generateTestEntityId: (primaryKey: any, index?: number, wrapped?: boolean) => any;
generateTestEntityId: (primaryKey: any, index?: 0 | 1 | 'random', wrapped?: boolean) => any;
/**
* @private
* Create a angular form path getter method of reference.
Expand Down
2 changes: 1 addition & 1 deletion generators/client/types.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import type { ExportApplicationPropertiesFromCommand } from '../../lib/command/i
import type { CypressApplication } from '../cypress/types.js';
import type { JavaScriptApplication, JavaScriptSourceType } from '../javascript/types.js';
import type { PostWritingEntitiesTaskParam } from '../../lib/types/application/tasks.js';
import type { PartialAngularApplication } from '../angular/types-deprecated.js';
import type { PartialAngularApplication } from '../angular/types-partial.js';
import type Command from './command.ts';

type ApplicationClientProperties = ExportApplicationPropertiesFromCommand<typeof Command>;
Expand Down

0 comments on commit 68358ab

Please sign in to comment.