-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'pu/cw/jestTests' into 'main'
tests(Tinebase) add jest logic tests See merge request tine20/tine20!6355
- Loading branch information
Showing
33 changed files
with
1,021 additions
and
1,747 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
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,27 @@ | ||
# jest tests | ||
|
||
## run tests | ||
run all tests (using npm command) | ||
|
||
./console src:npm 'test' | ||
|
||
run one test file only | ||
|
||
./console src:npm 'test -- Array.test.js' | ||
|
||
run on test only | ||
|
||
./console src:npm 'test -- Array.test.js --testNamePattern "Array.diff"' | ||
|
||
## debuging tests | ||
run tests in dbg mode | ||
|
||
./console src:npm 'run test-dbg' | ||
|
||
and attach a debugger, use [phpstorm](https://www.jetbrains.com/help/phpstorm/running-and-debugging-node-js.html#ws_node_debug_remote_chrome) or [chrome](chrome://inspect) | ||
|
||
## core concepts | ||
* pure logic tests, no DOM interaction / testing | ||
* no globals pollution (e.g. Tine, Ext, _, ...) | ||
* neither in tests nor in program code to be tested | ||
* you might need to rewrite / split your code so it stick to this rule |
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,22 @@ | ||
import common from "common"; | ||
|
||
|
||
describe('common functions', () => { | ||
describe('html2text', () => { | ||
it('ignores empty divs', () => { | ||
expect(common.html2text( '<blockquote class="felamimail-body-blockquote"><div>Hello,</div><div><br></div><div>...</div></blockquote>')) | ||
.toEqual("\nHello,\n\n...") | ||
}) | ||
|
||
it('copes with styled div tags', () => { | ||
expect(common.html2text( '<font face="arial, tahoma, helvetica, sans-serif" style="font-size: 11px; font-family: arial, tahoma, helvetica, sans-serif;"><span style="font-size: 11px;"><font color="#808080">Dipl.-Phys. Cornelius Weiss</font></span></font><div style="font-size: 11px; font-family: arial, tahoma, helvetica, sans-serif;"><font face="arial, tahoma, helvetica, sans-serif" color="#808080"><span style="font-size: 11px;">Team Leader Software Engineering</span></font></div>')) | ||
.toEqual("Dipl.-Phys. Cornelius Weiss\nTeam Leader Software Engineering") | ||
}) | ||
|
||
it('copes with nested blocks', () => { | ||
expect(common.html2text('<div><div><span><font><br></font></span></div></div>')) | ||
.toEqual("\n") | ||
}) | ||
}) | ||
|
||
}) |
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,72 @@ | ||
import Record from "data/Record"; | ||
|
||
let RecordCls; | ||
|
||
describe('data/Record', () => { | ||
beforeAll(() => { | ||
RecordCls = Record.create([ | ||
{name: 'name'}, | ||
{name: 'date', type: 'date', dateFormat: 'Y-m-d H:i:s'}, | ||
], { | ||
appName: 'Tinebase', | ||
modelName: 'Test', | ||
idProperty: 'id', | ||
titleProperty: 'name', | ||
recordName: 'TestRecord', | ||
recordsName: 'TestRecords' | ||
}); | ||
}) | ||
|
||
it('creates records by constructor', () => { | ||
expect(RecordCls).toBeInstanceOf(Function) | ||
const record = new RecordCls({id: 'test-id'}) | ||
expect(record).toBeInstanceOf(Record) | ||
expect(record.id).toEqual('test-id') | ||
|
||
}) | ||
|
||
it('assigns auto ids', () => { | ||
expect(RecordCls).toBeInstanceOf(Function) | ||
expect(typeof new RecordCls({}).id).toBe('number') | ||
}) | ||
|
||
it('creates records statically by setFromJson', () => { | ||
// @TODO deal with Date prototype overwrites | ||
const testRecord = Record.setFromJson(JSON.stringify({id: 'abc', name: 'testname'/*, date: '2024-12-11 17:50:32'*/}), RecordCls) | ||
expect(testRecord).toBeInstanceOf(Record) | ||
expect(testRecord.id).toEqual('abc') | ||
}) | ||
|
||
it('can track modifications', () => { | ||
const testRecord = Record.setFromJson(JSON.stringify({id: 'abc', name: 'testname'/*, date: '2024-12-11 17:50:32'*/}), RecordCls) | ||
expect(testRecord.dirty).toEqual(false) | ||
expect(testRecord.editing).toEqual(false) | ||
// expect(testRecord.phantom).toEqual(true) | ||
expect(testRecord.isModified('name')).toEqual(false) | ||
|
||
testRecord.set('name', 'update') | ||
expect(testRecord.get('name')).toEqual('update') | ||
expect(testRecord.isModified('name')).toEqual(true) | ||
expect(testRecord.dirty).toEqual(true) | ||
expect(testRecord.getChanges()).toEqual({ name: 'update' }) | ||
expect(testRecord.modified).toEqual({ name: 'testname' }) | ||
|
||
const recordData = testRecord.getData() | ||
expect(recordData.__meta.dirty).toEqual(true) | ||
expect(recordData.__meta.modified.name).toEqual('testname') | ||
expect(recordData.name).toEqual('update') | ||
}) | ||
|
||
it('copes with magic customfield names', () => { | ||
const record = new RecordCls({}) | ||
record.set('#cftest', 'value') | ||
expect(record.get('#cftest')).toEqual('value') | ||
expect(JSON.stringify(record.data.customfields)).toEqual(JSON.stringify({cftest: 'value'})) | ||
}) | ||
|
||
it('generates unique UIDs in different length', () => { | ||
expect(Record.generateUID().length).toBe(40) | ||
expect(Record.generateUID(5).length).toBe(5) | ||
expect(Record.generateUID()).not.toEqual(Record.generateUID()) | ||
}) | ||
}); |
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
Oops, something went wrong.