Skip to content

Commit

Permalink
imp(core): ✅ add history tests for store method
Browse files Browse the repository at this point in the history
  • Loading branch information
xavierfoucrier committed Apr 5, 2023
1 parent 920880a commit 178e7c3
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 0 deletions.
1 change: 1 addition & 0 deletions packages/core/__tests__/core/core.init.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ it('init history', () => {
y: 0,
},
url: 'http://localhost/',
data: {}
});
});

Expand Down
50 changes: 50 additions & 0 deletions packages/core/__tests__/utils/history.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ const first = {
y: 0,
},
url: 'url1',
data: {},
};
const second = {
ns: 'ns2',
Expand All @@ -15,6 +16,7 @@ const second = {
y: 0,
},
url: 'url2',
data: {},
};
const tmp = {
...second,
Expand Down Expand Up @@ -153,3 +155,51 @@ it('manage history with data-barba-history="replace"', async () => {
expect(h.ps).toHaveBeenCalledTimes(0);
expect(h.rs).toHaveBeenCalledTimes(1);
});

it('store custom user data', async () => {
const custom = {
custom: 'data',
};

history.init(first.url, first.ns);
history.store(custom);

expect(history.current.data).toEqual(custom);
});

it('store custom user data per state', async () => {
const state1 = {
state: 1,
};

const state2 = {
state: 2,
};

history.init(first.url, first.ns);
history.store(state1);
history.change(second.url, 'barba');
history.store(state2);

expect(history.previous.data).toEqual(state1);
expect(history.current.data).toEqual(state2);
});

it('merge custom user data with existing one', async () => {
const custom = {
custom: 'data',
};

const update = {
additional: 'data',
};

history.init(first.url, first.ns);
history.store(custom);
history.store(update);

expect(history.current.data).toEqual({
...custom,
...update,
});
});

0 comments on commit 178e7c3

Please sign in to comment.