Files
scratch-gui/test/unit/util/tutorial-from-url.test.js
T
Ray Schamp 3b90ac207b Return early if no query param
This prevents a tutorial with no urlId being returned in the case of no tutorial query param

Nice catch @kchadha!
2018-10-25 19:22:16 +01:00

48 lines
1.2 KiB
JavaScript

jest.mock('../../../src/lib/analytics.js', () => ({
event: () => {}
}));
jest.mock('../../../src/lib/libraries/decks/index.jsx', () => ({
noUrlId: {},
foo: {urlId: 'one'},
noUrlIdSandwich: {}
}));
import {detectTutorialId} from '../../../src/lib/tutorial-from-url.js';
Object.defineProperty(
window.location,
'search',
{value: '', writable: true}
);
test('returns the tutorial ID if the urlId matches', () => {
window.location.search = '?tutorial=one';
expect(detectTutorialId()).toBe('foo');
});
test('returns null if no matching urlId', () => {
window.location.search = '?tutorial=10';
expect(detectTutorialId()).toBe(null);
});
test('returns null if empty template', () => {
window.location.search = '?tutorial=';
expect(detectTutorialId()).toBe(null);
});
test('returns null if no query param', () => {
window.location.search = '';
expect(detectTutorialId()).toBe(null);
});
test('returns null if non-numeric template', () => {
window.location.search = '?tutorial=asdf';
expect(detectTutorialId()).toBe(null);
});
test('takes the first of multiple', () => {
window.location.search = '?tutorial=one&tutorial=two';
expect(detectTutorialId()).toBe('foo');
});