Skip to content
This repository has been archived by the owner on Oct 15, 2023. It is now read-only.

Commit

Permalink
Merge pull request #2 from yoriiis/update-ignored-hash
Browse files Browse the repository at this point in the history
Add the ignoredHash parameter
  • Loading branch information
yoriiis authored Oct 31, 2020
2 parents a8a3349 + d38d6f2 commit 2f7a1ac
Show file tree
Hide file tree
Showing 13 changed files with 223 additions and 83 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# CHANGELOG

## 1.2.1

### New features

* Add the `ignoredHash` on the manager to ignored hashs

## 1.2.0

### New features
Expand Down
15 changes: 14 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# StepManager

![StepManager](https://img.shields.io/badge/step--manager-v1.2.0-ff004b.svg?style=for-the-badge) ![GitHub Workflow Status (branch)](https://img.shields.io/github/workflow/status/yoriiis/step-manager/Build/master?style=for-the-badge) [![Coverage Status](https://img.shields.io/coveralls/github/yoriiis/step-manager?style=for-the-badge)](https://coveralls.io/github/yoriiis/step-manager?branch=master) ![Node.js](https://img.shields.io/node/v/step-manager?style=for-the-badge)
![StepManager](https://img.shields.io/badge/step--manager-v1.2.1-ff004b.svg?style=for-the-badge) ![GitHub Workflow Status (branch)](https://img.shields.io/github/workflow/status/yoriiis/step-manager/Build/master?style=for-the-badge) [![Coverage Status](https://img.shields.io/coveralls/github/yoriiis/step-manager?style=for-the-badge)](https://coveralls.io/github/yoriiis/step-manager?branch=master) ![Node.js](https://img.shields.io/node/v/step-manager?style=for-the-badge)

`StepManager` is a library to create **flexible** and **robust** multiple **steps** navigation with hash, **validations**, browser **storage** and **hook** functions.

Expand Down Expand Up @@ -187,6 +187,7 @@ const manager = new Manager({
element: document.querySelector("#steps"),
datas: {},
steps: [StepPeople, StepPlanet],
ignoredHash: [],
onComplete: datas => {},
onChange: action => {}
});
Expand Down Expand Up @@ -218,6 +219,18 @@ See the SWAPI example in the `./example/` directory for the full implementation.

The array of steps.

#### `ignoredHash`

`Array`

The array of ignored hash.

Use this array to list the ignored hashs and prevent the manager from listening for specific hashs which can cause conflicts with steps navigation. For example the following use case will work:

* With an ignored hash triggered, nothing will be added to the current steps.
* When the user returns to the same hash, nothing will is added because the step already exists.
* When the user triggers step navigation when an ignored hash is set, the navigation will run normally and destroy/create steps.

#### `cacheMethod`

`String`
Expand Down
6 changes: 3 additions & 3 deletions dist/step-manager.js

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions example/dist/demo.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "step-manager",
"version": "1.2.0",
"version": "1.2.1",
"description": "StepManager is a library to create flexible and robust multiple steps navigation with hash, validations, browser storage and hook functions.",
"keywords": [
"manager",
Expand All @@ -24,6 +24,7 @@
"scripts": {
"build": "rm -rf ./dist/ && webpack --mode=production",
"build:example": "rm -rf ./example/dist/ && webpack --config=./example/webpack.config.js --mode=production",
"build:all": "npm run build && npm run build:example",
"coverage": "npm run test:coverage && cat ./coverage/lcov.info | coveralls",
"create:gh-pages": "rm -rf ./gh-pages && mkdir ./gh-pages && cp -r ./example/dist/. ./gh-pages/dist/ && cp ./example/index.html ./gh-pages/index.html",
"start": "rm -rf ./dist/ && webpack --mode=development",
Expand Down
8 changes: 3 additions & 5 deletions src/__mocks__/mocks.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,7 @@
* @param {Object} result Object with steps instance, steps order and default route
*/
export function mockAnalyzeSteps(manager, result) {
manager.analyzeSteps = jest.fn().mockImplementation(() => {
return result;
});
manager.analyzeSteps = jest.fn().mockReturnValue(result);
}

/**
Expand All @@ -20,7 +18,7 @@ export function mockRouter(manager, { triggerNext = true, routeId = '' } = {}) {
manager.Router = {
init: jest.fn(),
currentRoute: 'people',
triggerNext: jest.fn().mockImplementation(() => triggerNext),
triggerNext: jest.fn().mockReturnValue(triggerNext),
triggerPrevious: jest.fn(),
destroy: jest.fn(),
setRoute: jest.fn(),
Expand All @@ -37,7 +35,7 @@ export function mockRouter(manager, { triggerNext = true, routeId = '' } = {}) {
*/
export function mockCacheManager(manager, { getDatasFromCache } = {}) {
manager.CacheManager = {
getDatasFromCache: jest.fn().mockImplementation(() => getDatasFromCache),
getDatasFromCache: jest.fn().mockReturnValue(getDatasFromCache),
removeDatasFromCache: jest.fn(),
setDatasToCache: jest.fn()
};
Expand Down
6 changes: 3 additions & 3 deletions src/__tests__/cache-manager.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ describe('CacheManager getDatasFromCache', () => {

// Render the first item corresponding to filters array
// to not rewrite the function filterDatas inside the test
cacheManager.filterDatas = jest.fn().mockImplementation(() => datas[filters[0]]);
cacheManager.filterDatas = jest.fn().mockReturnValue(datas[filters[0]]);

const result = cacheManager.getDatasFromCache(filters);

Expand Down Expand Up @@ -119,7 +119,7 @@ describe('CacheManager setDatasToCache', () => {
});

it('Should call the setDatasToCache function with already datas in cache', () => {
const route = 'planet';
const route = 'id-planet';
const firstDatas = {
'id-people': {
datas: datas['id-people']
Expand All @@ -131,7 +131,7 @@ describe('CacheManager setDatasToCache', () => {
};
window[cacheMethod].setItem(keyBrowserStorage, JSON.stringify(firstDatas));

cacheManager.getDatasFromCache = jest.fn().mockImplementation(() => firstDatas);
cacheManager.getDatasFromCache = jest.fn().mockReturnValue(firstDatas);
jest.spyOn(window[cacheMethod], 'setItem');

cacheManager.setDatasToCache({ route, datas: datas[route] });
Expand Down
16 changes: 9 additions & 7 deletions src/__tests__/manager.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ const getOptions = () => {
element: document.querySelector('#steps'),
datas: datas,
steps: [StepPeople, StepPlanet],
ignoredHash: ['menu'],
onComplete: (datas) => {
console.log('onComplete');
},
Expand Down Expand Up @@ -108,10 +109,11 @@ describe('Manager constructor', () => {
steps: [StepPeople, StepPlanet],
cacheMethod: 'sessionStorage',
keyBrowserStorage: 'stepManager',
ignoredHash: ['menu'],
onComplete: expect.any(Function),
onChange: expect.any(Function)
});
expect(manager.isCompleted).toBeFalsy();
expect(manager.isCompleted).toBe(false);
expect(manager.triggerPreviousStep).toBe(manager.triggerPreviousStep);
expect(manager.triggerNextStep).toBe(manager.triggerNextStep);
});
Expand All @@ -125,10 +127,11 @@ describe('Manager constructor', () => {
steps: [],
cacheMethod: 'sessionStorage',
keyBrowserStorage: 'stepManager',
ignoredHash: [],
onComplete: expect.any(Function),
onChange: expect.any(Function)
});
expect(manager.isCompleted).toBeFalsy();
expect(manager.isCompleted).toBe(false);
});
});

Expand All @@ -151,6 +154,7 @@ describe('Manager init', () => {
defaultRoute: resultAnalyzeSteps.defaultRoute,
stepsOrder: resultAnalyzeSteps.stepsOrder,
steps: resultAnalyzeSteps.steps,
ignoredHash: manager.options.ignoredHash,
onChange: manager.options.onChange,
getDatasFromCache: expect.any(Function)
});
Expand Down Expand Up @@ -212,9 +216,7 @@ describe('Manager triggerNextStep', () => {

manager.steps = {
'id-people': {
getDatasFromStep: jest.fn().mockImplementation(() => {
return {};
})
getDatasFromStep: jest.fn().mockReturnValue({})
}
};

Expand Down Expand Up @@ -294,8 +296,8 @@ describe('Manager allStepsComplete', () => {

manager.allStepsComplete();

expect(manager.isCompleted).toBeTruthy();
expect(manager.options.element.classList.contains('loading')).toBeTruthy();
expect(manager.isCompleted).toBe(true);
expect(manager.options.element.classList.contains('loading')).toBe(true);
expect(manager.options.onComplete).toHaveBeenCalledWith({});
expect(manager.CacheManager.removeDatasFromCache).toHaveBeenCalled();
});
Expand Down
Loading

0 comments on commit 2f7a1ac

Please sign in to comment.