123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256 |
- describe('MessageService', function() {
- let messageService;
- // Ignoring page reload request
- beforeAll(() => window.onbeforeunload = () => null);
- beforeEach(function() {
- // Load threema services
- module('3ema.services');
- // Inject the MessageService
- inject(function(MessageService) {
- messageService = MessageService;
- });
- });
- describe ('getAccess', () => {
- let test = (m, r) => {
- return expect(messageService.getAccess(m, r));
- };
- it('invalid arguments', () => {
- test().toEqual(jasmine.objectContaining({
- quote: false,
- copy: false,
- ack: false,
- dec: false,
- delete: false,
- download: false,
- }));
- })
- const testCases = [['contact', {id: 'ECHOECHO', type: 'contact'}, true],
- ['gateway contact', {id: '*THREEMA', type: 'contact'}, true],
- ['group', {id: 1, type: 'group'}, false],
- ['distributionList', {id: 1, type: 'distributionList'}, false]]
- testCases.forEach((testData) => {
- let type = testData[0];
- let receiver = testData[1];
- let canAckDec = testData[2];
- describe(type, () => {
- it('text messages ', () => {
- test({isOutbox: false, type: 'text'}, receiver)
- .toEqual(jasmine.objectContaining({
- quote: true,
- copy: true,
- ack: true && canAckDec,
- dec: true && canAckDec,
- delete: true,
- download: false,
- }));
- test({isOutbox: true, type: 'text'}, receiver)
- .toEqual(jasmine.objectContaining({
- quote: true,
- copy: true,
- ack: false,
- dec: false,
- delete: true,
- download: false,
- }));
- test({isOutbox: false, type: 'text', state: 'user-ack'}, receiver)
- .toEqual(jasmine.objectContaining({
- quote: true,
- copy: true,
- ack: false,
- dec: true && canAckDec,
- delete: true,
- download: false,
- }));
- test({isOutbox: false, type: 'text', state: 'user-dec'}, receiver)
- .toEqual(jasmine.objectContaining({
- quote: true,
- copy: true,
- ack: true && canAckDec,
- dec: false,
- delete: true,
- download: false,
- }));
- });
- it('location messages ', () => {
- test({isOutbox: false, type: 'text'}, receiver)
- .toEqual(jasmine.objectContaining({
- quote: true,
- copy: true,
- ack: true && canAckDec,
- dec: true && canAckDec,
- delete: true,
- download: false,
- }));
- test({isOutbox: true, type: 'text'}, receiver)
- .toEqual(jasmine.objectContaining({
- quote: true,
- copy: true,
- ack: false,
- dec: false,
- delete: true,
- download: false,
- }));
- test({isOutbox: false, type: 'text', state: 'user-ack'}, receiver)
- .toEqual(jasmine.objectContaining({
- quote: true,
- copy: true,
- ack: false,
- dec: true && canAckDec,
- delete: true,
- download: false,
- }));
- test({isOutbox: false, type: 'text', state: 'user-dec'}, receiver)
- .toEqual(jasmine.objectContaining({
- quote: true,
- copy: true,
- ack: true && canAckDec,
- dec: false,
- delete: true,
- download: false,
- }));
- });
- ['image', 'video', 'audio', 'file'].forEach((type) => {
- it('inbox ' + type, () => {
- test({isOutbox: false, type: type}, receiver)
- .toEqual(jasmine.objectContaining({
- quote: false,
- copy: false,
- ack: true && canAckDec,
- dec: true && canAckDec,
- delete: true,
- download: true,
- }));
- });
- it('inbox (caption) ' + type, () => {
- test({isOutbox: false, type: type, caption: 'test'}, receiver)
- .toEqual(jasmine.objectContaining({
- quote: true,
- copy: true,
- ack: true && canAckDec,
- dec: true && canAckDec,
- delete: true,
- download: true,
- }));
- });
- it('outbox ' + type, () => {
- test({isOutbox: false, type: type}, receiver)
- .toEqual(jasmine.objectContaining({
- quote: false,
- copy: false,
- ack: true && canAckDec,
- dec: true && canAckDec,
- delete: true,
- download: true,
- }));
- });
- it('outbox (caption) ' + type, () => {
- test({isOutbox: false, type: type, caption: 'test'}, receiver)
- .toEqual(jasmine.objectContaining({
- quote: true,
- copy: true,
- ack: true && canAckDec,
- dec: true && canAckDec,
- delete: true,
- download: true,
- }));
- });
- });
- });
- });
- });
- describe ('showStatusIcon', () => {
- let test = (m, r) => {
- return expect(messageService.showStatusIcon(m, r));
- };
- it ('invalid arguments', () => {
- test(null, null).toEqual(false);
- test({}, null).toEqual(false);
- test(null, {}).toEqual(false);
- test({}, {}).toEqual(false);
- });
- let testAll = (receiver, outboxTrue, outboxFalse, inboxTrue, inboxFalse) => {
- let testDirection = (outbox, t, f) => {
- let testDirections = (states, toBe) => {
- states.forEach((state) => {
- it(state, () => {
- test({isOutbox: outbox, state: state}, receiver).toBe(toBe);
- });
- });
- };
- testDirections(t, true);
- testDirections(f, false);
- };
- describe ('outbox', () => {
- testDirection(true, outboxTrue, outboxFalse);
- });
- describe ('inbox', () => {
- testDirection(false, inboxTrue, inboxFalse);
- });
- };
- describe ('normal contact', () => {
- testAll({id: 'ECHOECHO', type: 'contact'},
- ['delivered', 'read', 'send-failed', 'sent', 'pending', 'sending', 'user-ack', 'user-dec'],
- [],
- ['user-ack', 'user-dec'],
- ['delivered', 'read', 'send-failed', 'sent', 'pending', 'sending']
- );
- });
- describe ('gateway contact', () => {
- testAll({id: '*THREEMA', type: 'contact'},
- ['send-failed', 'pending', 'sending'],
- ['delivered', 'read', 'sent', 'user-ack', 'user-dec'],
- ['user-ack', 'user-dec'],
- ['delivered', 'read', 'send-failed', 'sent', 'pending', 'sending']
- );
- });
- describe ('Group', () => {
- testAll({id: 1, type: 'group'},
- ['send-failed', 'pending', 'sending'],
- ['delivered', 'read', 'sent', 'user-ack', 'user-dec'],
- [],
- ['delivered', 'read', 'send-failed', 'sent', 'pending', 'sending', 'user-ack', 'user-dec']
- );
- });
- describe ('Distribution List', () => {
- testAll({id: 1, type: 'distributionList'},
- [],
- ['send-failed', 'pending', 'sending', 'delivered', 'read', 'sent', 'user-ack', 'user-dec'],
- [],
- ['delivered', 'read', 'send-failed', 'sent', 'pending', 'sending', 'user-ack', 'user-dec']
- );
- });
- });
- });
|