Skip to content

Commit

Permalink
Using 'Untitled Story' as default story name
Browse files Browse the repository at this point in the history
  • Loading branch information
Dan Cox authored and Dan Cox committed Jan 12, 2024
1 parent 06e7e66 commit fbdbc62
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 6 deletions.
4 changes: 2 additions & 2 deletions src/Story.js
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ class Story {
* Creates a story.
* @param {string} name - Name of the story.
*/
constructor (name = '') {
constructor (name = 'Untitled Story') {
// Every story has a name.
this.name = name;
// Store the creator.
Expand Down Expand Up @@ -297,7 +297,7 @@ class Story {
// If it does, we ignore it and return.
if (this.getPassageByName(p.name) !== null) {
// Warn user
console.warn('Ignored passage with same name as existing one!');
console.warn('Warning: Ignored passage with same name as existing one!');
//
return;
}
Expand Down
4 changes: 2 additions & 2 deletions test/JSON/JSON.Parse.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ describe('JSON', () => {
const s = parseJSON(r.toJSON());

// Check all properties.
expect(s.name).toBe('');
expect(s.name).toBe('Untitled Story');
expect(Object.keys(s.tagColors).length).toBe(0);
expect(s.IFID).toBe('');
expect(s.start).toBe('');
Expand Down Expand Up @@ -52,7 +52,7 @@ describe('JSON', () => {
it('Should parse everything but name', function () {
const s = '{"tagColors":{"r":"red"},"ifid":"dd","start":"Start","formatVersion":"1.0","metadata":{"some":"thing"},"format":"Snowman","creator":"extwee","creatorVersion":"2.2.0","zoom":1,"passages":[{"name":"Start","tags":["tag1"],"metadata":{},"text":"Word"}]}';
const r = parseJSON(s);
expect(r.name).toBe('');
expect(r.name).toBe('Untitled Story');
expect(Object.keys(r.tagColors).length).toBe(1);
expect(r.IFID).toBe('DD');
expect(r.start).toBe('Start');
Expand Down
7 changes: 6 additions & 1 deletion test/Story.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,11 @@ describe('Story', () => {
s = new Story('Test');
expect(s.name).toBe('Test');
});

it('Should have default name', () => {
s = new Story();
expect(s.name).toBe('Untitled Story');
});
});

describe('creator', () => {
Expand Down Expand Up @@ -401,7 +406,7 @@ describe('Story', () => {
const s = new Story();
// Convert to string and then back to object.
const result = JSON.parse(s.toJSON());
expect(result.name).toBe('');
expect(result.name).toBe('Untitled Story');
expect(Object.keys(result.tagColors).length).toBe(0);
expect(result.ifid).toBe('');
expect(result.start).toBe('');
Expand Down
2 changes: 1 addition & 1 deletion test/Twine2HTML/Twine2HTML.Parse.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ describe('Twine2HTMLParser', () => {
it('Should have default name', () => {
const fr = readFileSync('test/Twine2HTML/Twine2HTMLParser/missingName.html', 'utf-8');
const story = parseTwine2HTML(fr);
expect(story.name).toBe('');
expect(story.name).toBe('Untitled Story');
});

it('Should set a missing IFID to an empty string', () => {
Expand Down

0 comments on commit fbdbc62

Please sign in to comment.