Skip to content

Commit

Permalink
Do not track saves when fixtures are stored
Browse files Browse the repository at this point in the history
  • Loading branch information
igorski committed Apr 4, 2024
1 parent 2ff7dae commit 272ffca
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 3 deletions.
3 changes: 2 additions & 1 deletion src/model/types/song.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,8 @@ export type EffluxSong = {
order: EffluxPatternOrder;
samples: Sample[];
origin?: EffluxSongOrigin;
type: EffluxSongType
type: EffluxSongType;
fixture?: boolean; // whether Song was part of factory fixtures
};

export type StoredEffluxSongDescriptor = {
Expand Down
8 changes: 6 additions & 2 deletions src/store/modules/song-module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,9 @@ const SongModule: Module<SongState, any> = {
if ( Array.isArray( songs )) {
commit( "setShowSaveMessage", false );
for ( let i = 0; i < songs.length; ++i ) {
await dispatch( "saveSongInLS", await SongAssemblyService.assemble( songs[ i ]));
const song = await SongAssemblyService.assemble( songs[ i ]);
song.fixture = true; // do not track saves for these
await dispatch( "saveSongInLS", song );
}
commit( "setShowSaveMessage", true );
}
Expand Down Expand Up @@ -289,7 +291,9 @@ const SongModule: Module<SongState, any> = {
return reject();
}
commit( "setStatesOnSave", getters.totalSaved );
commit( "publishMessage", PubSubMessages.SONG_SAVED );
if ( !song.fixture ) {
commit( "publishMessage", PubSubMessages.SONG_SAVED );
}
if ( state.showSaveMessage ) {
commit( "showNotification", { message: getters.t( "messages.songSaved", { name: song.meta.title }) });
}
Expand Down
29 changes: 29 additions & 0 deletions tests/unit/store/modules/song-module.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import songModule, { createSongState } from "@/store/modules/song-module";
import type { SongState } from "@/store/modules/song-module";
import PatternFactory from "@/model/factories/pattern-factory";
import SongFactory, { FACTORY_VERSION } from "@/model/factories/song-factory";
import PubSubMessages from "@/services/pubsub/messages";
import { type EffluxSong, type EffluxSongMeta, EffluxSongType } from "@/model/types/song";
import SongValidator from "@/model/validators/song-validator";
import { createSample } from "../../mocks";
Expand Down Expand Up @@ -287,6 +288,34 @@ describe( "Vuex song module", () => {
}, 1 );
});
});

it( "should broadcast the save event", async () => {
commit = vi.fn();

// @ts-expect-error Type 'ActionObject<SongState, any>' has no call signatures.
const song = await actions.createSong();
const state = createSongState({ songs: [], showSaveMessage: false });

// @ts-expect-error Type 'ActionObject<SongState, any>' has no call signatures.
await actions.saveSongInLS({ state, getters: mockedGetters, commit, dispatch }, song);

expect( commit ).toHaveBeenCalledWith( "publishMessage", PubSubMessages.SONG_SAVED );
});

it( "should not broadcast the save event when saving factory fixtures", async () => {
commit = vi.fn();

// @ts-expect-error Type 'ActionObject<SongState, any>' has no call signatures.
const song = await actions.createSong();
song.fixture = true;

const state = createSongState({ songs: [], showSaveMessage: false });

// @ts-expect-error Type 'ActionObject<SongState, any>' has no call signatures.
await actions.saveSongInLS({ state, getters: mockedGetters, commit, dispatch }, song);

expect( commit ).not.toHaveBeenCalledWith( "publishMessage", PubSubMessages.SONG_SAVED );
});
});

it( "should be able to delete songs from local storage", async () => {
Expand Down

0 comments on commit 272ffca

Please sign in to comment.