EmbeddedFxBackupOptIn.test.jsx (2643B)
1 import React from "react"; 2 import { mount } from "enzyme"; 3 import { EmbeddedFxBackupOptIn } from "content-src/components/EmbeddedFxBackupOptIn.jsx"; 4 5 function getFxBackupComponent(wrapper) { 6 return wrapper.find("turn-on-scheduled-backups").getDOMNode(); 7 } 8 9 describe("EmbeddedFxBackupOptIn", () => { 10 it("does not crash if ref is null", () => { 11 const wrapper = mount(<EmbeddedFxBackupOptIn isEncryptedBackup={false} />); 12 wrapper.unmount(); 13 }); 14 15 it("unencrypted backups always show file chooser screen", () => { 16 const wrapper = mount( 17 <EmbeddedFxBackupOptIn 18 isEncryptedBackup={false} 19 options={{ hide_password_input: false }} 20 /> 21 ); 22 const el = getFxBackupComponent(wrapper); 23 24 assert.strictEqual(el.hasAttribute("hide-password-input"), true); 25 assert.strictEqual(el.hasAttribute("hide-file-path-chooser"), false); 26 27 wrapper.unmount(); 28 }); 29 30 it("encrypted backups show file chooser first if hide_password_input=true", () => { 31 const wrapper = mount( 32 <EmbeddedFxBackupOptIn 33 isEncryptedBackup={true} 34 options={{ hide_password_input: true }} 35 /> 36 ); 37 const el = getFxBackupComponent(wrapper); 38 39 assert.strictEqual(el.hasAttribute("hide-password-input"), true); 40 assert.strictEqual(el.hasAttribute("hide-file-path-chooser"), false); 41 42 wrapper.unmount(); 43 }); 44 45 it("encrypted backups show password input screen if hide_password_input=false", () => { 46 const wrapper = mount( 47 <EmbeddedFxBackupOptIn 48 isEncryptedBackup={true} 49 options={{ hide_password_input: false }} 50 /> 51 ); 52 const el = getFxBackupComponent(wrapper); 53 54 assert.strictEqual(el.hasAttribute("hide-password-input"), false); 55 assert.strictEqual(el.hasAttribute("hide-file-path-chooser"), true); 56 57 wrapper.unmount(); 58 }); 59 60 it("updates screen when hide_password_input changes for encrypted backups", () => { 61 const wrapper = mount( 62 <EmbeddedFxBackupOptIn 63 isEncryptedBackup={true} 64 options={{ hide_password_input: true }} 65 /> 66 ); 67 let el = getFxBackupComponent(wrapper); 68 69 // Show file chooser screen first 70 assert.strictEqual(el.hasAttribute("hide-password-input"), true); 71 assert.strictEqual(el.hasAttribute("hide-file-path-chooser"), false); 72 73 // Switch to password input screen 74 wrapper.setProps({ options: { hide_password_input: false } }); 75 wrapper.update(); 76 el = getFxBackupComponent(wrapper); 77 78 assert.strictEqual(el.hasAttribute("hide-password-input"), false); 79 assert.strictEqual(el.hasAttribute("hide-file-path-chooser"), true); 80 81 wrapper.unmount(); 82 }); 83 });