Skip to content
Open
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 @@ -15,6 +15,7 @@ import type {
CollectionObjectAttribute,
CollectionObjectType,
Determination,
Accession,
} from '../types';

requireContext();
Expand Down Expand Up @@ -469,6 +470,51 @@ test('save', async () => {
expect(newDetermination.get('number1')).toBe(2);
});

describe('independent resource change propagation', () => {
overrideAjax(
'/api/specify/collectionobject/?domainfilter=false&accession=11&offset=0',
emptyCollection
);
overrideAjax(accessionUrl, accessionResponse, { method: 'PUT' });

test('needsSaved propagates from independent collection to parent', async () => {
const parentResource = new tables.Accession.Resource({ id: accessionId });
expect(parentResource.needsSaved).toBe(false);

const collectionObjectRel =
tables.CollectionObject.strictGetRelationship('accession')!;

const independentCollection =
new tables.CollectionObject.IndependentCollection({
related: parentResource,
field: collectionObjectRel,
}) as Collection<CollectionObject>;

await independentCollection.fetch();

// Connect the collection to the parent's event system, as rgetCollection would do internally.
// storeIndependent is not in the public TS types so cast to any.
(parentResource as any).storeIndependent(
collectionObjectRel.getReverse(),
independentCollection
);

const newCollectionObject = new tables.CollectionObject.Resource({
id: 998,
});
independentCollection.add(newCollectionObject);

// Adding an existing resource to an independent collection does not mark the resource itself needsSaved;
// only the parent is notified via saverequired
expect(newCollectionObject.needsSaved).toBe(false);
expect(parentResource.needsSaved).toBe(true);

await parentResource.save();

expect(parentResource.needsSaved).toBe(false);
});
});

describe('resource initialization', () => {
test('Initialization with dependent resources does not trigger saveRequired', () => {
const resource = new tables.CollectionObject.Resource({
Expand Down
Loading