-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Update EntitySchemaSnak to handle ID prefix and add tests for Commons…
…MediaSnak and EntitySchemaSnak
- Loading branch information
Showing
7 changed files
with
135 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
{ | ||
"ignore": { | ||
"@typescript-eslint/eslint-plugin": { | ||
"versions": "8.18.1", | ||
"reason": "airbnb-eslint" | ||
}, | ||
"@typescript-eslint/parser": { | ||
"versions": "8.18.1", | ||
"reason": "airbnb-eslint" | ||
}, | ||
"eslint": { | ||
"versions": "9.17.0", | ||
"reason": "airbnb-eslint" | ||
}, | ||
"eslint-import-resolver-typescript": { | ||
"versions": "3.7.0", | ||
"reason": "airbnb-eslint" | ||
}, | ||
"eslint-plugin-compat": { | ||
"versions": "6.0.2", | ||
"reason": "airbnb-eslint" | ||
}, | ||
"eslint-plugin-cypress": { | ||
"versions": "4.1.0", | ||
"reason": "airbnb-eslint" | ||
}, | ||
"eslint-plugin-import": { | ||
"versions": "2.31.0", | ||
"reason": "airbnb-eslint" | ||
}, | ||
"eslint-plugin-jest": { | ||
"versions": "28.10.0", | ||
"reason": "airbnb-eslint" | ||
}, | ||
"eslint-plugin-jsdoc": { | ||
"versions": "", | ||
"reason": "airbnb-eslint" | ||
}, | ||
"eslint-plugin-jsonc": { | ||
"versions": "2.18.2", | ||
"reason": "airbnb-eslint" | ||
}, | ||
"eslint-plugin-no-secrets": { | ||
"versions": "2.1.1", | ||
"reason": "airbnb-eslint" | ||
}, | ||
"eslint-plugin-sonarjs": { | ||
"versions": "3.0.1", | ||
"reason": "airbnb-eslint" | ||
}, | ||
"eslint-plugin-unicorn": { | ||
"versions": "56.0.1", | ||
"reason": "airbnb-eslint" | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -54,5 +54,6 @@ | |
"wikipedia", | ||
"wmde", | ||
"wvdp" | ||
] | ||
], | ||
"editor.formatOnSave": true | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
import EntitySchemaSnak from '../../../src/snaks/EntitySchemaSnak'; | ||
|
||
const EntitySnak = { | ||
snaktype: 'value' as const, | ||
property: 'P123', | ||
datavalue: { | ||
value: { | ||
id: 'E123456', | ||
'entity-type': 'entity-schema' as const | ||
}, | ||
type: 'wikibase-entityid' as const | ||
}, | ||
datatype: 'entity-schema' as const | ||
}; | ||
|
||
describe('EntitySchemaSnak', () => { | ||
describe('toJSON', () => { | ||
it('should have the right JSON stringification', () => { | ||
const snak = new EntitySchemaSnak(EntitySnak); | ||
|
||
expect(snak.toJSON()).toStrictEqual(EntitySnak); | ||
}); | ||
}); | ||
|
||
describe('equals', () => { | ||
it('should be true if the items are equal', () => { | ||
const a = new EntitySchemaSnak(EntitySnak); | ||
const b = new EntitySchemaSnak(EntitySnak); | ||
|
||
expect(a.equals(b)).toBe(true); | ||
}); | ||
|
||
it('should be false if the property changes', () => { | ||
const a = new EntitySchemaSnak(EntitySnak); | ||
const b = new EntitySchemaSnak(EntitySnak); | ||
|
||
b.property = 'P42'; | ||
|
||
expect(a.equals(b)).toBe(false); | ||
}); | ||
|
||
it('should be false if the items are NOT equal', () => { | ||
const snak = new EntitySchemaSnak(EntitySnak); | ||
const snak2 = new EntitySchemaSnak(EntitySnak); | ||
snak2.id = 'E654321'; | ||
|
||
expect(snak.equals(snak2)).toBe(false); | ||
}); | ||
}); | ||
|
||
describe('fromID', () => { | ||
it('should create a snak from an ID', () => { | ||
const snak = EntitySchemaSnak.fromID('P2013', 'E987654'); | ||
|
||
expect(snak.id).toEqual('E987654'); | ||
expect(snak.property).toEqual('P2013'); | ||
}); | ||
}); | ||
}); |