Skip to content

Commit 27ab3e2

Browse files
authored
Merge pull request #883 from alexpelan/alexpelan/experimental
Set experimental property in ui if url parameter passed
2 parents 2728dcf + 3ce426e commit 27ab3e2

7 files changed

Lines changed: 39 additions & 13 deletions

File tree

.eslintrc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@
5050
],
5151
"complexity": [
5252
2,
53-
{"max": 27}
53+
{"max": 30}
5454
],
5555
"computed-property-spacing": [
5656
2,

src/actions/applicationLoaded.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,4 @@ import {createAction} from 'redux-actions';
22

33
export default createAction(
44
'APPLICATION_LOADED',
5-
(gistId = null) => ({gistId}),
65
);

src/components/Workspace.jsx

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -116,13 +116,17 @@ class Workspace extends React.Component {
116116
}
117117

118118
componentWillMount() {
119-
let gistId;
119+
let gistId = null;
120+
let isExperimental = false;
120121
if (location.search) {
121122
const query = qs.parse(location.search.slice(1));
122-
gistId = query.gist;
123+
if (query.gist) {
124+
gistId = query.gist;
125+
}
126+
isExperimental = Object.keys(query).includes('experimental');
123127
}
124128
history.replaceState({}, '', location.pathname);
125-
this.props.dispatch(applicationLoaded(gistId));
129+
this.props.dispatch(applicationLoaded({gistId, isExperimental}));
126130
this._listenForAuthChange();
127131
startSessionHeartbeat();
128132
}

src/reducers/ui.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,12 @@ export default function ui(stateIn, action) {
165165
case 'REFRESH_PREVIEW':
166166
return state.set('lastRefreshTimestamp', action.payload.timestamp);
167167

168+
case 'APPLICATION_LOADED':
169+
if (action.payload.isExperimental) {
170+
return state.set('experimental', true);
171+
}
172+
return state.set('experimental', false);
173+
168174
default:
169175
return state;
170176
}

test/unit/reducers/ui.js

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ import {
2525
} from '../../../src/actions/clients';
2626
import {EmptyGistError} from '../../../src/clients/gists';
2727
import {userLoggedOut} from '../../../src/actions/user';
28+
import {applicationLoaded} from '../../../src/actions/';
2829

2930
const initialState = Immutable.fromJS({
3031
editors: {
@@ -246,3 +247,19 @@ test('refreshPreview', reducerTest(
246247
partial(refreshPreview, 1),
247248
initialState.set('lastRefreshTimestamp', 1),
248249
));
250+
251+
test('applicationLoaded', (t) => {
252+
t.test('isExperimental = true', reducerTest(
253+
reducer,
254+
initialState,
255+
partial(applicationLoaded, {gistId: null, isExperimental: true}),
256+
initialState.set('experimental', true),
257+
));
258+
259+
t.test('isExperimental = false', reducerTest(
260+
reducer,
261+
initialState,
262+
partial(applicationLoaded, {gistId: null, isExperimental: false}),
263+
initialState.set('experimental', false),
264+
));
265+
});

test/unit/sagas/projects.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ test('changeCurrentProject()', (assert) => {
7272

7373
test('applicationLoaded()', (t) => {
7474
t.test('with no gist ID', (assert) => {
75-
testSaga(applicationLoadedSaga, applicationLoaded(null)).
75+
testSaga(applicationLoadedSaga, applicationLoaded({gistId: null})).
7676
next().call(createProjectSaga).
7777
next().isDone();
7878

@@ -81,8 +81,8 @@ test('applicationLoaded()', (t) => {
8181

8282
t.test('with gist ID', (assert) => {
8383
const gistId = '123abc';
84-
testSaga(applicationLoadedSaga, applicationLoaded(gistId)).
85-
next().call(importGistSaga, applicationLoaded(gistId)).
84+
testSaga(applicationLoadedSaga, applicationLoaded({gistId})).
85+
next().call(importGistSaga, applicationLoaded({gistId})).
8686
next().isDone();
8787

8888
assert.end();
@@ -93,7 +93,7 @@ test('importGist()', (t) => {
9393
const gistId = 'abc123';
9494

9595
t.test('with successful import', (assert) => {
96-
const saga = testSaga(importGistSaga, applicationLoaded(gistId));
96+
const saga = testSaga(importGistSaga, applicationLoaded({gistId}));
9797

9898
saga.next().call(loadFromId, gistId, {authenticated: false});
9999

@@ -122,7 +122,7 @@ test('importGist()', (t) => {
122122
});
123123

124124
t.test('with not found error', (assert) => {
125-
testSaga(importGistSaga, applicationLoaded(gistId)).
125+
testSaga(importGistSaga, applicationLoaded({gistId})).
126126
next().call(loadFromId, gistId, {authenticated: false}).
127127
throw(
128128
Object.create(new Error(), {response: {value: {status: 404}}}),
@@ -132,7 +132,7 @@ test('importGist()', (t) => {
132132
});
133133

134134
t.test('with other error', (assert) => {
135-
testSaga(importGistSaga, applicationLoaded(gistId)).
135+
testSaga(importGistSaga, applicationLoaded({gistId})).
136136
next().call(loadFromId, gistId, {authenticated: false}).
137137
throw(new Error()).put(gistImportError()).
138138
next().isDone();

test/unit/sagas/user.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import {getInitialUserState} from '../../../src/clients/firebaseAuth';
99

1010
test('applicationLoaded', (t) => {
1111
t.test('with no logged in user', (assert) => {
12-
testSaga(applicationLoadedSaga, applicationLoaded()).
12+
testSaga(applicationLoadedSaga, applicationLoaded({})).
1313
next().call(getInitialUserState).
1414
next(null).isDone();
1515

@@ -21,7 +21,7 @@ test('applicationLoaded', (t) => {
2121
user: {uid: 'student1'},
2222
credential: {provider: 'github.com'},
2323
};
24-
testSaga(applicationLoadedSaga, applicationLoaded()).
24+
testSaga(applicationLoadedSaga, applicationLoaded({})).
2525
next().call(getInitialUserState).
2626
next(userCredential).put(userAuthenticated(userCredential)).
2727
next().isDone();

0 commit comments

Comments
 (0)