Skip to content

Commit

Permalink
Failing tests added
Browse files Browse the repository at this point in the history
  • Loading branch information
ATHULKNAIR committed Aug 31, 2021
1 parent b98b829 commit 8f2c6f3
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 9 deletions.
1 change: 1 addition & 0 deletions src/medblocks/form/form.ts
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,7 @@ export default class MedblockForm extends LitElement {

handleChildDisconnect(e: CustomEvent) {
const path = e.detail;
console.log("disconnected this path",path)
// delete this.mbElements[path]
const { [path]: _, ...rest } = this.mbElements;
this.mbElements = rest;
Expand Down
52 changes: 43 additions & 9 deletions test/mb-form.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,21 @@ class BaseEhrElement extends EhrElement {
class TestComponent extends LitElement {
@property({type: Array}) paths: string[]
render(){
return html`<mb-form>
${this.paths.map(path=>html`<base-ehr path=${path}></base-ehr>`)}
return html`<mb-form >
${this.paths.map(path=>html`<base-ehr @mb-disconnect=${(e:CustomEvent)=>console.log(e.detail)} path=${path}></base-ehr>`)}
</mb-form>`
}
}

class RepeateableTest extends LitElement{
@property({type:Number}) i:number=2;
render(){
return html `<mb-form>
${[...Array(this.i)].map((_,i)=>html`
<base-ehr @mb-disconnect=${(e:CustomEvent)=>console.log(e.detail)} path=${`path/${i}`}></base-ehr>`)}
</mb-form>`
}
}
customElements.define('repeat-element',RepeateableTest)
customElements.define('base-ehr', BaseEhrElement)
customElements.define('reactive-path', TestComponent)

Expand All @@ -33,16 +42,41 @@ describe('Form', ()=>{
expect(Object.keys(form.mbElements)).to.eql(["test/path"])
})

it('should react to change in path', async ()=>{
// it('should react to change in path', async ()=>{
// let paths = ['hello/there', 'another/path']
// const component = await fixture<TestComponent>(html`<reactive-path .paths=${paths}></reactive-path>`)
// const form = querySelectorDeep('mb-form') as MbForm
// expect(Object.keys(form.mbElements)).to.eql(["hello/there", "another/path"])
// component.paths = ['test2/another', 'changed/path']
// await elementUpdated(component)
// expect(Object.keys(form.mbElements)).to.eql(['test2/another', 'changed/path'])
// component.paths = ['test2/another', 'changed/path2']
// await elementUpdated(component)
// expect(Object.keys(form.mbElements)).to.eql(['test2/another', 'changed/path2'])
// })
it('should react to deletion in path', async ()=>{
let paths = ['hello/there', 'another/path']
const component = await fixture<TestComponent>(html`<reactive-path .paths=${paths}></reactive-path>`)
const form = querySelectorDeep('mb-form') as MbForm
expect(Object.keys(form.mbElements)).to.eql(["hello/there", "another/path"])
component.paths = ['test2/another', 'changed/path']
console.log('------------------')
component.paths = ['hello/there']
await elementUpdated(component)
expect(Object.keys(form.mbElements)).to.eql(['test2/another', 'changed/path'])
component.paths = ['test2/another', 'changed/path2']
await elementUpdated(component)
expect(Object.keys(form.mbElements)).to.eql(['test2/another', 'changed/path2'])
expect(Object.keys(form.mbElements)).to.eql(['hello/there'])
// component.paths = ['test2/another', 'changed/path2']
// await elementUpdated(component)
// expect(Object.keys(form.mbElements)).to.eql(['test2/another', 'changed/path2'])
})

// it('should remove children elements properly',async()=>{
// const component = await fixture<RepeateableTest>(html`<repeat-element ></repeat-element>`)
// const form = querySelectorDeep('mb-form') as MbForm
// console.log(form.mbElements)
// expect(Object.keys(form.data).length).to.eql(2)
// component.i = 1
// await elementUpdated(component)
// console.log(form.mbElements)
// expect(Object.keys(form.data).length).to.eql(1)
// })

})

0 comments on commit 8f2c6f3

Please sign in to comment.