Skip to content
This repository has been archived by the owner on Apr 4, 2022. It is now read-only.

Commit

Permalink
Merge branch 'master' into master
Browse files Browse the repository at this point in the history
  • Loading branch information
tboeckmann committed Oct 18, 2020
2 parents 65a8f56 + 9827084 commit 6f082de
Show file tree
Hide file tree
Showing 22 changed files with 725 additions and 234 deletions.
309 changes: 213 additions & 96 deletions package-lock.json

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion package.json
Expand Up @@ -37,7 +37,7 @@
},
"devDependencies": {
"@angular-devkit/build-angular": "^0.803.25",
"@angular/cli": "^8.3.22",
"@angular/cli": "^8.3.29",
"@angular/compiler-cli": "~8.2.14",
"@angular/language-service": "~8.2.14",
"@babel/compat-data": "~7.8.0",
Expand Down
63 changes: 37 additions & 26 deletions src/app/inbox/inbox-message/inbox-message.component.spec.ts
Expand Up @@ -10,13 +10,19 @@ import { of } from 'rxjs';
import { NameserviceService } from 'src/app/services/mailchain/nameservice/nameservice.service';
import { HttpClientModule } from '@angular/common/http';
import { NameserviceServiceStub } from 'src/app/services/mailchain/nameservice/nameservice.service.stub';
import { LocalStorageServerServiceStub } from 'src/app/services/helpers/local-storage-server/local-storage-server.service.stub';
import { LocalStorageServerService } from 'src/app/services/helpers/local-storage-server/local-storage-server.service';
import { ProtocolsService } from 'src/app/services/mailchain/protocols/protocols.service';
import { ProtocolsServiceStub } from 'src/app/services/mailchain/protocols/protocols.service.stub';

describe('InboxMessageComponent', () => {

let component: InboxMessageComponent;
let fixture: ComponentFixture<InboxMessageComponent>;
let mailchainService: MailchainService;
let nameserviceService: NameserviceService;
let localStorageServerService: LocalStorageServerService;
let protocolsService: ProtocolsService;

let mailchainTestService: MailchainTestService

Expand All @@ -33,7 +39,9 @@ describe('InboxMessageComponent', () => {
providers: [
HttpHelpersService,
MailchainService,
{ provide: ProtocolsService, useClass: ProtocolsServiceStub },
{ provide: NameserviceService, useClass: NameserviceServiceStub },
{ provide: LocalStorageServerService, useClass: LocalStorageServerServiceStub },
],
imports: [
ModalModule.forRoot(),
Expand All @@ -44,12 +52,15 @@ describe('InboxMessageComponent', () => {
})
.compileComponents();
mailchainTestService = TestBed.get(MailchainTestService);
protocolsService = TestBed.get(ProtocolsService);
localStorageServerService = TestBed.get(LocalStorageServerService);
nameserviceService = TestBed.get(NameserviceService);
mailchainService = TestBed.get(MailchainService);

}));

beforeEach(() => {

fixture = TestBed.createComponent(InboxMessageComponent);
component = fixture.componentInstance;

Expand Down Expand Up @@ -83,103 +94,103 @@ describe('InboxMessageComponent', () => {

describe('ngOnInit', () => {
describe('resolveNamesFromMessage', () => {
it('should resolve the To field when there is a resolvable name', () => {
it('should resolve the To field when there is a resolvable name', async () => {
component.currentMessage["headers"]["to"] = mcAddress1
component.ngOnInit()
await component.ngOnInit()
expect(component.messageNameRecords[address1]).toEqual('myaddress.eth')
})
it('should NOT resolve the To field when there is NOT a resolvable name', () => {
it('should NOT resolve the To field when there is NOT a resolvable name', async () => {
component.currentMessage["headers"]["to"] = mcAddress2
component.ngOnInit()
await component.ngOnInit()
expect(component.messageNameRecords[address2]).toEqual(undefined)
})
it('should resolve the From field when there is a resolvable name', () => {
it('should resolve the From field when there is a resolvable name', async () => {
component.currentMessage["headers"]["from"] = mcAddress1
component.ngOnInit()
await component.ngOnInit()
expect(component.messageNameRecords[address1]).toEqual('myaddress.eth')
})
it('should NOT resolve the From field when there is NOT a resolvable name', () => {
it('should NOT resolve the From field when there is NOT a resolvable name', async () => {
component.currentMessage["headers"]["from"] = mcAddress2
component.ngOnInit()
await component.ngOnInit()
expect(component.messageNameRecords[address2]).toEqual(undefined)
})
});
});

describe('getViewForContentType', () => {
it('should call getViewForContentType when the content-type is plaintext ', () => {
it('should call getViewForContentType when the content-type is plaintext ', async () => {
spyOn(component, 'getViewForContentType')

component.currentMessage["headers"]["content-type"] = 'text/plain; charset="UTF-8"'
component.ngOnInit()
await component.ngOnInit()
expect(component.getViewForContentType).toHaveBeenCalled()
})

it('should call getViewForContentType when the content-type is text/plain; charset="UTF-8"', () => {
it('should call getViewForContentType when the content-type is text/plain; charset="UTF-8"', async () => {
spyOn(component, 'getViewForContentType')

component.currentMessage["headers"]["content-type"] = 'text/plain; charset="UTF-8"'
component.ngOnInit()
await component.ngOnInit()
expect(component.getViewForContentType).toHaveBeenCalled()
})

it('should call getViewForContentType when the content-type is unknown', () => {
it('should call getViewForContentType when the content-type is unknown', async () => {
spyOn(component, 'getViewForContentType')

component.currentMessage["headers"]["content-type"] = 'unknown'
component.ngOnInit()
await component.ngOnInit()
expect(component.getViewForContentType).toHaveBeenCalled()
})
})

describe('addMessageText', () => {
it('should call addMessageText when the content-type is plaintext ', () => {
it('should call addMessageText when the content-type is plaintext ', async () => {
spyOn(component, 'addMessageText')

component.currentMessage["headers"]["content-type"] = 'text/plain; charset="UTF-8"'
component.ngOnInit()
await component.ngOnInit()
expect(component.addMessageText).toHaveBeenCalled()
})

it('should NOT call addMessageText when the content-type is text/html; charset="UTF-8" ', () => {
it('should NOT call addMessageText when the content-type is text/html; charset="UTF-8" ', async () => {
spyOn(component, 'addMessageText')

component.currentMessage["headers"]["content-type"] = 'text/html; charset="UTF-8"'
component.ngOnInit()
await component.ngOnInit()
expect(component.addMessageText).not.toHaveBeenCalled()
})

it('should call addMessageText when the content-type is unknown ', () => {
it('should call addMessageText when the content-type is unknown ', async () => {
spyOn(component, 'addMessageText')

component.currentMessage["headers"]["content-type"] = 'unknown'
component.ngOnInit()
await component.ngOnInit()
expect(component.addMessageText).toHaveBeenCalled()
})

})
describe('addMessageIframe', () => {
it('should NOT call addMessageIframe when the content-type is plaintext ', () => {
it('should NOT call addMessageIframe when the content-type is plaintext ', async () => {
spyOn(component, 'addMessageIframe')

component.currentMessage["headers"]["content-type"] = 'text/plain; charset="UTF-8"'
component.ngOnInit()
await component.ngOnInit()
expect(component.addMessageIframe).not.toHaveBeenCalled()
})

it('should call addMessageIframe when the content-type is text/html; charset="UTF-8" ', () => {
it('should call addMessageIframe when the content-type is text/html; charset="UTF-8" ', async () => {
spyOn(component, 'addMessageIframe')

component.currentMessage["headers"]["content-type"] = 'text/html; charset="UTF-8"'
component.ngOnInit()
await component.ngOnInit()
expect(component.addMessageIframe).toHaveBeenCalled()
})

it('should NOT call addMessageIframe when the content-type is unknown ', () => {
it('should NOT call addMessageIframe when the content-type is unknown ', async () => {
spyOn(component, 'addMessageIframe')

component.currentMessage["headers"]["content-type"] = 'unknown'
component.ngOnInit()
await component.ngOnInit()
expect(component.addMessageIframe).not.toHaveBeenCalled()
})

Expand Down
33 changes: 19 additions & 14 deletions src/app/inbox/inbox-message/inbox-message.component.ts
Expand Up @@ -2,6 +2,7 @@ import { Component, Input, Output, EventEmitter, OnInit, ViewEncapsulation } fro
import { InboundMail } from 'src/app/models/inbound-mail';
import { NameserviceService } from 'src/app/services/mailchain/nameservice/nameservice.service';
import { MailchainService } from 'src/app/services/mailchain/mailchain.service';
import { LocalStorageNameserviceService } from 'src/app/services/helpers/local-storage-nameservice/local-storage-nameservice.service';

@Component({
selector: '[inbox-message]',
Expand All @@ -22,6 +23,7 @@ export class InboxMessageComponent implements OnInit {
constructor(
private nameserviceService: NameserviceService,
private mailchainService: MailchainService,
private localStorageNameserviceService: LocalStorageNameserviceService,
) { }
/**
* Go back to the inbox-messages view
Expand All @@ -30,8 +32,8 @@ export class InboxMessageComponent implements OnInit {
this.goToInboxMessages.emit('');
}

ngOnInit() {
this.resolveNamesFromMessage()
async ngOnInit() {
await this.resolveNamesFromMessage()
this.getViewForContentType()
}

Expand All @@ -47,12 +49,13 @@ export class InboxMessageComponent implements OnInit {
* Sets the name corresponding to messageNameRecords
* @param addr address in format 0x1234...1234
*/
private resolveMessageNameRecords(addr) {
this.nameserviceService.resolveAddress(
private async resolveMessageNameRecords(addr) {
let obs = await this.nameserviceService.resolveAddress(
this.currentProtocol,
this.currentNetwork,
addr
).subscribe(res => {
)
obs.subscribe(res => {
if (res['ok']) {
this.messageNameRecords[addr] = res['body']['name']
}
Expand All @@ -63,15 +66,17 @@ export class InboxMessageComponent implements OnInit {
* resolveNamesFromMessages looks up the 'to' and 'from' name
* records according to the currentNetwork and currentProtocol
*/
private resolveNamesFromMessage() {
[
this.currentMessage["headers"]["to"],
this.currentMessage["headers"]["from"]
].forEach(element => {
let parsedAddr = this.parseAddressFromMailchain(element)
this.resolveMessageNameRecords(parsedAddr)
});

private async resolveNamesFromMessage() {
if (await this.localStorageNameserviceService.getCurrentNameserviceAddressEnabled() == "true") {

[
this.currentMessage["headers"]["to"],
this.currentMessage["headers"]["from"]
].forEach(async element => {
let parsedAddr = this.parseAddressFromMailchain(element)
await this.resolveMessageNameRecords(parsedAddr)
});
};
}

/**
Expand Down
28 changes: 17 additions & 11 deletions src/app/inbox/inbox-messages/inbox-messages.component.spec.ts
Expand Up @@ -10,13 +10,17 @@ import { of } from 'rxjs';
import { NameserviceService } from 'src/app/services/mailchain/nameservice/nameservice.service';
import { ReadServiceStub } from 'src/app/services/mailchain/messages/read.service.stub';
import { NameserviceServiceStub } from 'src/app/services/mailchain/nameservice/nameservice.service.stub';
import { ProtocolsService } from 'src/app/services/mailchain/protocols/protocols.service';
import { ProtocolsServiceStub } from 'src/app/services/mailchain/protocols/protocols.service.stub';

describe('InboxMessagesComponent', () => {
let component: InboxMessagesComponent;
let fixture: ComponentFixture<InboxMessagesComponent>;
let mailchainService: MailchainService
let readService: ReadService;
let nameserviceService: NameserviceService
let nameserviceService: NameserviceService;
let protocolsService: ProtocolsService;


const address1 = "0x0123456789012345678901234567890123456789"
const address2 = "0x0000000000000000000000000000000000000002"
Expand Down Expand Up @@ -113,6 +117,7 @@ describe('InboxMessagesComponent', () => {
providers: [
HttpHelpersService,
MailchainService,
{ provide: ProtocolsService, useClass: ProtocolsServiceStub },
{ provide: ReadService, useClass: ReadServiceStub },
{ provide: NameserviceService, useClass: NameserviceServiceStub },

Expand All @@ -124,6 +129,7 @@ describe('InboxMessagesComponent', () => {
})
.compileComponents();
mailchainService = TestBed.get(MailchainService);
protocolsService = TestBed.get(ProtocolsService);
readService = TestBed.get(ReadService);
nameserviceService = TestBed.get(NameserviceService);

Expand Down Expand Up @@ -166,12 +172,12 @@ describe('InboxMessagesComponent', () => {
});

describe('resolveSendersFromMessages', () => {
it('should include resolved names in messagesNameRecords', () => {
component.resolveSendersFromMessages(messages)
it('should include resolved names in messagesNameRecords', async () => {
await component.resolveSendersFromMessages(messages)
expect(component.messagesNameRecords[address1]).toEqual("myaddress.eth")
})
it('should not include unresolved names in messagesNameRecords', () => {
component.resolveSendersFromMessages(messages)
it('should not include unresolved names in messagesNameRecords', async () => {
await component.resolveSendersFromMessages(messages)
expect(component.messagesNameRecords[address2]).toEqual(undefined)
})
})
Expand Down Expand Up @@ -546,29 +552,29 @@ describe('InboxMessagesComponent', () => {
component.addMailToInboxMessages(msg)
})
})
it('should set currentAccountInboxMessages to the currently selected account', () => {
it('should set currentAccountInboxMessages to the currently selected account', async () => {
component.currentAccount = address2
component.getCurrentAccountInboxMessages()
await component.getCurrentAccountInboxMessages()

expect(component.currentAccountInboxMessages).toEqual([
component.inboxMessages[3],
component.inboxMessages[4],
component.inboxMessages[5]
])
})
it('should filter currentAccountInboxMessages based on search text', () => {
it('should filter currentAccountInboxMessages based on search text', async () => {
component.currentAccount = address2
component.searchText = "Message 04"
component.getCurrentAccountInboxMessages()
await component.getCurrentAccountInboxMessages()

expect(component.currentAccountInboxMessages).toEqual([
component.inboxMessages[4]
])
})
it('should dedupe currentAccountInboxMessages', () => {
it('should dedupe currentAccountInboxMessages', async () => {
component.currentAccount = address2
component.inboxMessages.push(component.inboxMessages[4])
component.getCurrentAccountInboxMessages()
await component.getCurrentAccountInboxMessages()

expect(component.currentAccountInboxMessages).toEqual([
component.inboxMessages[3],
Expand Down
12 changes: 6 additions & 6 deletions src/app/inbox/inbox-messages/inbox-messages.component.ts
Expand Up @@ -67,8 +67,8 @@ export class InboxMessagesComponent implements OnInit, OnChanges {
* resolveSendersFromMessages of messages by name according to the currentNetwork and currentProtocol
* @param messagesArray the array of messages
*/
resolveSendersFromMessages(messagesArray) {
this.messagesNameRecords = this.mailchainService.resolveSendersFromMessages(
async resolveSendersFromMessages(messagesArray) {
this.messagesNameRecords = await this.mailchainService.resolveSendersFromMessages(
this.currentProtocol,
this.currentNetwork,
messagesArray
Expand Down Expand Up @@ -193,14 +193,14 @@ export class InboxMessagesComponent implements OnInit, OnChanges {


async ngOnInit(): Promise<void> {
this.getCurrentAccountInboxMessages()
await this.getCurrentAccountInboxMessages()
}

/**
* Get the inbox messages, filtered by 'currently selected account' > 'searchtext'.
* Dedupe message array - workaround for dupe messages @TODO: waiting on dupe bugfix in mailchain
*/
getCurrentAccountInboxMessages() {
async getCurrentAccountInboxMessages() {
if (this.currentProtocol && this.currentAccount) {
var inboxMessagesFilteredByAddress = this.addressPipe.transform(
this.inboxMessages, {
Expand All @@ -217,7 +217,7 @@ export class InboxMessagesComponent implements OnInit, OnChanges {
this.currentAccountInboxMessages = this.mailchainService.dedupeMessagesByIds(inboxMessagesFilteredByAddressSearch)

// fetch names for senders
this.resolveSendersFromMessages(this.currentAccountInboxMessages)
await this.resolveSendersFromMessages(this.currentAccountInboxMessages)
}
}

Expand All @@ -226,7 +226,7 @@ export class InboxMessagesComponent implements OnInit, OnChanges {
if ('currentAccount' in event) {
this.selectNone()
}
this.getCurrentAccountInboxMessages()
await this.getCurrentAccountInboxMessages()
}

}

0 comments on commit 6f082de

Please sign in to comment.