|
import { WikiDocument } from '@/classes/Document.js' |
|
import { encodeUnicode } from '@/services/helpers/dataFormatter' |
|
|
|
const FIRST_DOCUMENT = { |
|
document: { |
|
approval_state: false, |
|
data: 'This is the first document.', |
|
id: 'as9hd98ktp7g3', |
|
namespace: ':FirstNamespace', |
|
rid: 'as98dfgy', |
|
timestamp: '1606080364139', |
|
title: 'The first document' |
|
} |
|
} |
|
const SECOND_DOCUMENT = new WikiDocument({ |
|
document: { |
|
approval_state: false, |
|
data: 'This is the second document in a different namespace.', |
|
id: 'ashgd98o0p7g3', |
|
namespace: ':SecondNamespace', |
|
rid: 'as98dfgy', |
|
timestamp: '1606080364139', |
|
title: 'document title' |
|
} |
|
}) |
|
var TEST_OBJECT = new WikiDocument(FIRST_DOCUMENT) |
|
|
|
beforeEach(() => { |
|
TEST_OBJECT = new WikiDocument(FIRST_DOCUMENT) |
|
}) |
|
describe('Document Class', () => { |
|
it('should return a class', () => { |
|
expect(TEST_OBJECT).toBeInstanceOf(WikiDocument) |
|
}) |
|
it('should set the document', () => { |
|
expect(TEST_OBJECT.setData(SECOND_DOCUMENT)).not.toEqual(new WikiDocument(FIRST_DOCUMENT)) |
|
expect(TEST_OBJECT.setData(FIRST_DOCUMENT)).not.toEqual(new WikiDocument(SECOND_DOCUMENT)) |
|
}) |
|
it('should reset the document', () => { |
|
const TEST_OBJECT_2 = new WikiDocument(FIRST_DOCUMENT) |
|
TEST_OBJECT_2.setData(SECOND_DOCUMENT) |
|
TEST_OBJECT_2.resetData() |
|
expect(TEST_OBJECT_2).toEqual(new WikiDocument()) |
|
}) |
|
it('should approve the document', () => { |
|
expect(TEST_OBJECT.approved()).toStrictEqual(false) |
|
TEST_OBJECT.sign() |
|
expect(TEST_OBJECT.approved()).toStrictEqual(true) |
|
}) |
|
it('should return the formatted document', () => { |
|
expect(TEST_OBJECT.format()).toEqual({ |
|
data: encodeUnicode('This is the first document.'), |
|
id: 'as9hd98ktp7g3', |
|
namespace: ':FirstNamespace', |
|
title: 'The first document' |
|
}) |
|
}) |
|
it('should be signable', () => { |
|
expect(TEST_OBJECT.signable()).toEqual(true) |
|
}) |
|
}) |