Initial commit of 001code-html Scratch frontend project.
Includes scratch-gui, scratch-vm, scratch-blocks, scratch-render, scratch-l10n, and deployment config. Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
47
scratch-gui/test/unit/util/tutorial-from-url.test.js
Normal file
47
scratch-gui/test/unit/util/tutorial-from-url.test.js
Normal file
@@ -0,0 +1,47 @@
|
||||
jest.mock('../../../src/lib/analytics.js', () => ({
|
||||
event: () => {}
|
||||
}));
|
||||
|
||||
jest.mock('../../../src/lib/libraries/decks/index.jsx', () => ({
|
||||
noUrlId: {},
|
||||
foo: {urlId: 'one'},
|
||||
noUrlIdSandwich: {}
|
||||
}));
|
||||
|
||||
import queryString from 'query-string';
|
||||
import {detectTutorialId} from '../../../src/lib/tutorial-from-url.js';
|
||||
|
||||
test('returns the tutorial ID if the urlId matches', () => {
|
||||
const queryParams = queryString.parse('?tutorial=one');
|
||||
expect(detectTutorialId(queryParams)).toBe('foo');
|
||||
});
|
||||
|
||||
test('returns null if no matching urlId', () => {
|
||||
const queryParams = queryString.parse('?tutorial=10');
|
||||
expect(detectTutorialId(queryParams)).toBe(null);
|
||||
});
|
||||
|
||||
test('returns null if empty template', () => {
|
||||
const queryParams = queryString.parse('?tutorial=');
|
||||
expect(detectTutorialId(queryParams)).toBe(null);
|
||||
});
|
||||
|
||||
test('returns null if no query param', () => {
|
||||
const queryParams = queryString.parse('');
|
||||
expect(detectTutorialId(queryParams)).toBe(null);
|
||||
});
|
||||
|
||||
test('returns null if unrecognized template', () => {
|
||||
const queryParams = queryString.parse('?tutorial=asdf');
|
||||
expect(detectTutorialId(queryParams)).toBe(null);
|
||||
});
|
||||
|
||||
test('takes the first of multiple', () => {
|
||||
const queryParams = queryString.parse('?tutorial=one&tutorial=two');
|
||||
expect(detectTutorialId(queryParams)).toBe('foo');
|
||||
});
|
||||
|
||||
test('returns all for the tutorial library shortcut', () => {
|
||||
const queryParams = queryString.parse('?tutorial=all');
|
||||
expect(detectTutorialId(queryParams)).toBe('all');
|
||||
});
|
||||
Reference in New Issue
Block a user