Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
thalia
ThaliApp
Commits
e82bf08a
Commit
e82bf08a
authored
Oct 17, 2018
by
Gijs Hendriksen
Committed by
Gijs Hendriksen
Oct 24, 2018
Browse files
Added tests for all reducers
parent
2f5f4407
Changes
19
Hide whitespace changes
Inline
Side-by-side
__tests__/reducers/__snapshots__/event.spec.js.snap
0 → 100644
View file @
e82bf08a
// Jest Snapshot v1, https://goo.gl/fbAQLP
exports[`events reducer initially should not be fetched 1`] = `
Object {
"data": Object {
"category": "",
"description": "",
"end": "",
"google_maps_url": "",
"has_fields": false,
"is_pizza_event": false,
"location": "",
"map_location": "",
"organiser": -1,
"pk": -1,
"registration_allowed": false,
"start": "",
"title": "",
},
"loading": false,
"registrations": Array [],
"status": "initial",
}
`;
__tests__/reducers/__snapshots__/members.spec.js.snap
0 → 100644
View file @
e82bf08a
// Jest Snapshot v1, https://goo.gl/fbAQLP
exports[`members reducer initially should return the initial state 1`] = `
Object {
"loading": false,
"memberList": Array [],
"more": null,
"searchKey": "",
"status": "initial",
}
`;
__tests__/reducers/__snapshots__/pizza.spec.js.snap
0 → 100644
View file @
e82bf08a
// Jest Snapshot v1, https://goo.gl/fbAQLP
exports[`pizza reducer initially should return the initial state 1`] = `
Object {
"event": null,
"hasLoaded": false,
"loading": false,
"order": null,
"pizzaList": Array [],
"success": false,
}
`;
__tests__/reducers/__snapshots__/profile.spec.js.snap
0 → 100644
View file @
e82bf08a
// Jest Snapshot v1, https://goo.gl/fbAQLP
exports[`profile reducer initially should return the initial state 1`] = `
Object {
"hasLoaded": false,
"profile": Object {
"achievements": Array [],
"avatar": Object {
"full": "http://localhost:8000/static/members/images/default-avatar.jpg",
"large": "http://localhost:8000/static/members/images/default-avatar.jpg",
"medium": "http://localhost:8000/static/members/images/default-avatar.jpg",
"small": "http://localhost:8000/static/members/images/default-avatar.jpg",
},
"birthday": "",
"display_name": "",
"membership_type": "",
"photo": "http://localhost:8000/static/members/images/default-avatar.jpg",
"pk": -1,
"profile_description": "",
"programme": "",
"starting_year": -1,
"website": "",
},
"success": false,
}
`;
__tests__/reducers/__snapshots__/registration.spec.js.snap
0 → 100644
View file @
e82bf08a
// Jest Snapshot v1, https://goo.gl/fbAQLP
exports[`registration reducer initially should return the initial state 1`] = `
Object {
"fields": Object {},
"registration": 0,
"status": "loading",
}
`;
__tests__/reducers/__snapshots__/session.spec.js.snap
0 → 100644
View file @
e82bf08a
// Jest Snapshot v1, https://goo.gl/fbAQLP
exports[`session reducer initially should return the initial state 1`] = `
Object {
"displayName": "",
"photo": "http://localhost:8000/static/members/images/default-avatar.jpg",
"status": "SIGNED_OUT",
"token": "",
"username": "",
}
`;
__tests__/reducers/__snapshots__/settings.spec.js.snap
0 → 100644
View file @
e82bf08a
// Jest Snapshot v1, https://goo.gl/fbAQLP
exports[`settings reducer initially should return the initial state 1`] = `
Object {
"loading": true,
"pushNotifications": Object {
"categoryList": Array [],
"status": "loading",
},
}
`;
exports[`settings reducer push notifications initially should return the inital state 1`] = `
Object {
"categoryList": Array [],
"status": "loading",
}
`;
__tests__/reducers/__snapshots__/welcome.spec.js.snap
0 → 100644
View file @
e82bf08a
// Jest Snapshot v1, https://goo.gl/fbAQLP
exports[`welcome reducer initially should return the initial state 1`] = `
Object {
"eventList": Array [],
"loading": true,
"status": "initial",
}
`;
__tests__/reducers/calendar.spec.js
View file @
e82bf08a
...
...
@@ -2,17 +2,19 @@ import reducer from '../../app/reducers/calendar';
import
*
as
actions
from
'
../../app/actions/calendar
'
;
describe
(
'
calendar reducer
'
,
()
=>
{
const
initial
=
reducer
()
;
const
emptyState
=
{}
;
describe
(
'
initially
'
,
()
=>
{
const
initialState
=
reducer
();
it
(
'
should not be fetched
'
,
()
=>
{
expect
(
initial
).
toMatchSnapshot
();
expect
(
initial
State
).
toMatchSnapshot
();
});
});
describe
(
'
is refreshing
'
,
()
=>
{
const
state
=
reducer
(
{
loading
:
false
}
,
emptyState
,
actions
.
refresh
(),
);
...
...
@@ -23,7 +25,7 @@ describe('calendar reducer', () => {
describe
(
'
is successful
'
,
()
=>
{
const
state
=
reducer
(
initial
,
emptyState
,
actions
.
success
([{
pk
:
1
}]),
);
...
...
@@ -42,7 +44,7 @@ describe('calendar reducer', () => {
describe
(
'
is failure
'
,
()
=>
{
const
state
=
reducer
(
initial
,
emptyState
,
actions
.
failure
(),
);
...
...
@@ -50,13 +52,8 @@ describe('calendar reducer', () => {
expect
(
state
).
toHaveProperty
(
'
loading
'
,
false
);
});
it
(
'
should not have events
'
,
()
=>
{
expect
(
state
).
toHaveProperty
(
'
eventList
'
,
[]);
});
it
(
'
should have status failure
'
,
()
=>
{
expect
(
state
).
toHaveProperty
(
'
status
'
,
'
failure
'
);
});
});
});
\ No newline at end of file
});
__tests__/reducers/event.spec.js
0 → 100644
View file @
e82bf08a
import
reducer
from
'
../../app/reducers/event
'
;
import
*
as
actions
from
'
../../app/actions/event
'
;
describe
(
'
events reducer
'
,
()
=>
{
const
emptyState
=
{};
describe
(
'
initially
'
,
()
=>
{
const
initialState
=
reducer
();
it
(
'
should not be fetched
'
,
()
=>
{
expect
(
initialState
).
toMatchSnapshot
();
});
});
describe
(
'
is refreshing
'
,
()
=>
{
const
state
=
reducer
(
emptyState
,
actions
.
fetching
(),
);
it
(
'
should be loading
'
,
()
=>
{
expect
(
state
).
toHaveProperty
(
'
loading
'
,
true
);
});
});
describe
(
'
is successful
'
,
()
=>
{
const
state
=
reducer
(
emptyState
,
actions
.
success
({
pk
:
1
},
[{
pk
:
2
}]),
);
it
(
'
should not be loading
'
,
()
=>
{
expect
(
state
).
toHaveProperty
(
'
loading
'
,
false
);
});
it
(
'
should have event info
'
,
()
=>
{
expect
(
state
).
toHaveProperty
(
'
data
'
,
{
pk
:
1
});
});
it
(
'
should have registrations info
'
,
()
=>
{
expect
(
state
).
toHaveProperty
(
'
registrations
'
,
[{
pk
:
2
}]);
});
it
(
'
should have status success
'
,
()
=>
{
expect
(
state
).
toHaveProperty
(
'
status
'
,
'
success
'
);
});
});
describe
(
'
is failure
'
,
()
=>
{
const
state
=
reducer
(
emptyState
,
actions
.
failure
(),
);
it
(
'
should not be loading
'
,
()
=>
{
expect
(
state
).
toHaveProperty
(
'
loading
'
,
false
);
});
it
(
'
should have status failure
'
,
()
=>
{
expect
(
state
).
toHaveProperty
(
'
status
'
,
'
failure
'
);
});
});
describe
(
'
is done
'
,
()
=>
{
const
state
=
reducer
(
emptyState
,
actions
.
done
(),
);
it
(
'
should not be loading
'
,
()
=>
{
expect
(
state
).
toHaveProperty
(
'
loading
'
,
false
);
});
});
});
__tests__/reducers/index.spec.js
0 → 100644
View file @
e82bf08a
import
{
createStore
}
from
'
redux
'
;
import
rootReducer
from
'
../../app/reducers/index
'
;
import
session
from
'
../../app/reducers/session
'
;
import
event
from
'
../../app/reducers/event
'
;
import
calendar
from
'
../../app/reducers/calendar
'
;
import
welcome
from
'
../../app/reducers/welcome
'
;
import
profile
from
'
../../app/reducers/profile
'
;
import
pizza
from
'
../../app/reducers/pizza
'
;
import
registration
from
'
../../app/reducers/registration
'
;
import
members
from
'
../../app/reducers/members
'
;
import
settings
from
'
../../app/reducers/settings
'
;
const
reducers
=
{
session
,
event
,
calendar
,
welcome
,
profile
,
pizza
,
registration
,
members
,
settings
,
};
const
store
=
createStore
(
rootReducer
);
describe
(
'
reducers combiner
'
,
()
=>
{
it
(
'
should combine all reducers in the store
'
,
()
=>
{
expect
.
assertions
(
reducers
.
length
);
Object
.
keys
(
reducers
).
forEach
((
key
)
=>
{
expect
(
store
.
getState
()[
key
]).
toEqual
(
reducers
[
key
]());
});
});
});
__tests__/reducers/members.spec.js
0 → 100644
View file @
e82bf08a
import
reducer
from
'
../../app/reducers/members
'
;
import
*
as
actions
from
'
../../app/actions/members
'
;
describe
(
'
members reducer
'
,
()
=>
{
const
emptyState
=
{};
describe
(
'
initially
'
,
()
=>
{
const
initialState
=
reducer
();
it
(
'
should return the initial state
'
,
()
=>
{
expect
(
initialState
).
toMatchSnapshot
();
});
});
describe
(
'
is fetching
'
,
()
=>
{
const
state
=
reducer
(
{
loading
:
false
},
actions
.
fetching
(),
);
it
(
'
should be loading
'
,
()
=>
{
expect
(
state
).
toHaveProperty
(
'
loading
'
,
true
);
});
});
describe
(
'
is successful
'
,
()
=>
{
const
state
=
reducer
(
emptyState
,
actions
.
success
([{
pk
:
1
}],
'
nextUrl
'
,
'
searchKey
'
),
);
it
(
'
should not be loading
'
,
()
=>
{
expect
(
state
).
toHaveProperty
(
'
loading
'
,
false
);
});
it
(
'
should have status success
'
,
()
=>
{
expect
(
state
).
toHaveProperty
(
'
status
'
,
'
success
'
);
});
it
(
'
should have the member list result
'
,
()
=>
{
expect
(
state
).
toHaveProperty
(
'
memberList
'
,
[{
pk
:
1
}]);
});
it
(
'
should have the url for more results
'
,
()
=>
{
expect
(
state
).
toHaveProperty
(
'
more
'
,
'
nextUrl
'
);
});
it
(
'
should have the original search keys
'
,
()
=>
{
expect
(
state
).
toHaveProperty
(
'
searchKey
'
,
'
searchKey
'
);
});
});
describe
(
'
is failure
'
,
()
=>
{
const
state
=
reducer
(
emptyState
,
actions
.
failure
(),
);
it
(
'
should not be loading
'
,
()
=>
{
expect
(
state
).
toHaveProperty
(
'
loading
'
,
false
);
});
it
(
'
should have status failure
'
,
()
=>
{
expect
(
state
).
toHaveProperty
(
'
status
'
,
'
failure
'
);
});
});
describe
(
'
is successful with additional results
'
,
()
=>
{
let
state
=
reducer
(
emptyState
,
actions
.
success
([{
pk
:
1
}],
'
nextUrl
'
,
'
searchKey
'
),
);
state
=
reducer
(
state
,
actions
.
moreSuccess
([{
pk
:
2
}],
'
nextUrl
'
),
);
it
(
'
should not be loading
'
,
()
=>
{
expect
(
state
).
toHaveProperty
(
'
loading
'
,
false
);
});
it
(
'
should have status success
'
,
()
=>
{
expect
(
state
).
toHaveProperty
(
'
status
'
,
'
success
'
);
});
it
(
'
should have the combined member lists
'
,
()
=>
{
expect
(
state
).
toHaveProperty
(
'
memberList
'
,
[{
pk
:
1
},
{
pk
:
2
}]);
});
it
(
'
should have the url for more results
'
,
()
=>
{
expect
(
state
).
toHaveProperty
(
'
more
'
,
'
nextUrl
'
);
});
});
});
__tests__/reducers/pizza.spec.js
0 → 100644
View file @
e82bf08a
import
reducer
from
'
../../app/reducers/pizza
'
;
import
*
as
actions
from
'
../../app/actions/pizza
'
;
describe
(
'
pizza reducer
'
,
()
=>
{
const
emptyState
=
{};
describe
(
'
initially
'
,
()
=>
{
const
initialState
=
reducer
();
it
(
'
should return the initial state
'
,
()
=>
{
expect
(
initialState
).
toMatchSnapshot
();
});
});
describe
(
'
is fetching
'
,
()
=>
{
const
state
=
reducer
(
emptyState
,
actions
.
fetching
(),
);
it
(
'
should be loading
'
,
()
=>
{
expect
(
state
).
toHaveProperty
(
'
loading
'
,
true
);
});
});
describe
(
'
is successful
'
,
()
=>
{
const
state
=
reducer
(
emptyState
,
actions
.
success
(
{
title
:
'
pizzaEvent
'
},
{
pk
:
1
},
[{
pk
:
2
}],
),
);
it
(
'
should not be loading
'
,
()
=>
{
expect
(
state
).
toHaveProperty
(
'
loading
'
,
false
);
expect
(
state
).
toHaveProperty
(
'
hasLoaded
'
,
true
);
});
it
(
'
should be successful
'
,
()
=>
{
expect
(
state
).
toHaveProperty
(
'
success
'
,
true
);
});
it
(
'
should contain the pizza event info
'
,
()
=>
{
expect
(
state
).
toHaveProperty
(
'
event
'
,
{
title
:
'
pizzaEvent
'
});
});
it
(
'
should contain the user
\'
s current order
'
,
()
=>
{
expect
(
state
).
toHaveProperty
(
'
order
'
,
{
pk
:
1
});
});
it
(
'
should contain the list of pizzas
'
,
()
=>
{
expect
(
state
).
toHaveProperty
(
'
pizzaList
'
,
[{
pk
:
2
}]);
});
});
describe
(
'
is failure
'
,
()
=>
{
const
state
=
reducer
(
emptyState
,
actions
.
failure
(),
);
it
(
'
should not be loading
'
,
()
=>
{
expect
(
state
).
toHaveProperty
(
'
loading
'
,
false
);
expect
(
state
).
toHaveProperty
(
'
hasLoaded
'
,
true
);
});
it
(
'
should not be successful
'
,
()
=>
{
expect
(
state
).
toHaveProperty
(
'
success
'
,
false
);
});
});
describe
(
'
is cancelled successfully
'
,
()
=>
{
const
state
=
reducer
(
emptyState
,
actions
.
cancelSuccess
(),
);
it
(
'
should not contain an order
'
,
()
=>
{
expect
(
state
).
toHaveProperty
(
'
order
'
,
null
);
});
});
describe
(
'
is ordered successfully
'
,
()
=>
{
const
state
=
reducer
(
emptyState
,
actions
.
orderSuccess
({
pk
:
1
}),
);
it
(
'
should contain the user
\'
s current order
'
,
()
=>
{
expect
(
state
).
toHaveProperty
(
'
order
'
,
{
pk
:
1
});
});
});
});
__tests__/reducers/profile.spec.js
0 → 100644
View file @
e82bf08a
import
reducer
from
'
../../app/reducers/profile
'
;
import
*
as
actions
from
'
../../app/actions/profile
'
;
describe
(
'
profile reducer
'
,
()
=>
{
const
emptyState
=
{};
describe
(
'
initially
'
,
()
=>
{
const
initialState
=
reducer
();
it
(
'
should return the initial state
'
,
()
=>
{
expect
(
initialState
).
toMatchSnapshot
();
});
});
describe
(
'
is fetching
'
,
()
=>
{
const
state
=
reducer
(
emptyState
,
actions
.
fetching
(),
);
it
(
'
should be loading
'
,
()
=>
{
expect
(
state
).
toHaveProperty
(
'
hasLoaded
'
,
false
);
});
});
describe
(
'
is successful
'
,
()
=>
{
const
state
=
reducer
(
emptyState
,
actions
.
success
({
pk
:
1
}),
);
it
(
'
should not be loading
'
,
()
=>
{
expect
(
state
).
toHaveProperty
(
'
hasLoaded
'
,
true
);
});
it
(
'
should be successful
'
,
()
=>
{
expect
(
state
).
toHaveProperty
(
'
success
'
,
true
);
});
it
(
'
should contain the profile data
'
,
()
=>
{
expect
(
state
).
toHaveProperty
(
'
profile
'
,
{
pk
:
1
});
});
});
describe
(
'
is failure
'
,
()
=>
{
const
state
=
reducer
(
emptyState
,
actions
.
failure
(),
);
it
(
'
should not be loading
'
,
()
=>
{
expect
(
state
).
toHaveProperty
(
'
hasLoaded
'
,
true
);
});
it
(
'
should not be successful
'
,
()
=>
{
expect
(
state
).
toHaveProperty
(
'
success
'
,
false
);
});
});
});
__tests__/reducers/registration.spec.js
0 → 100644
View file @
e82bf08a
import
reducer
from
'
../../app/reducers/registration
'
;
import
*
as
actions
from
'
../../app/actions/registration
'
;
describe
(
'
registration reducer
'
,
()
=>
{
const
initialState
=
reducer
();
const
emptyState
=
{};
describe
(
'
initially
'
,
()
=>
{
it
(
'
should return the initial state
'
,
()
=>
{
expect
(
initialState
).
toMatchSnapshot
();
});
});
describe
(
'
is loading
'
,
()
=>
{
const
state
=
reducer
(
emptyState
,
actions
.
loading
(),
);
it
(
'
should be loading
'
,
()
=>
{
expect
(
state
).
toHaveProperty
(
'
status
'
,
'
loading
'
);
});
});
describe
(
'
is successful
'
,
()
=>
{
const
state
=
reducer
(
emptyState
,
actions
.
success
(),
);
it
(
'
should be successful
'
,
()
=>
{
expect
(
state
).
toHaveProperty
(
'
status
'
,
'
success
'
);
});
});
describe
(
'
is failure
'
,
()
=>
{
const
state
=
reducer
(
emptyState
,
actions
.
failure
(),
);
it
(
'
should be failure
'
,
()
=>
{
expect
(
state
).
toHaveProperty
(
'
status
'
,
'
failure
'
);
});
});
describe
(
'
is retrieving new fields
'
,
()
=>
{
const
state
=
reducer
(
emptyState
,
actions
.
retrieveFields
(
1
),
);
it
(
'
should reset the state
'
,
()
=>
{
expect
(
state
).
toEqual
(
initialState
);
});
});