UNPKG

3.36 kBJSXView Raw
1const React = require('react');
2const { expect } = require('chai');
3const { shallow } = require('enzyme');
4const { Binary } = require('bson');
5const { BinaryValue } = require('../');
6
7const TESTING_BASE64 = Buffer.from('testing').toString('base64');
8
9describe('<BinaryValue />', () => {
10 context('when the type is an old uuid', () => {
11 const binary = new Binary('testing', 3);
12 const component = shallow(<BinaryValue type="Binary" value={binary} />);
13
14 it('sets the base class', () => {
15 expect(component.hasClass('element-value')).to.equal(true);
16 });
17
18 it('sets the type class', () => {
19 expect(component.hasClass('element-value-is-binary')).to.equal(true);
20 });
21
22 it('sets the title', () => {
23 expect(component.props().title).to.equal(`Binary('${TESTING_BASE64}')`);
24 });
25
26 it('sets the value', () => {
27 expect(component.text()).to.equal(`Binary('${TESTING_BASE64}')`);
28 });
29 });
30
31 context('when the type is a new uuid', () => {
32 const binary = new Binary('testing', 4);
33 const component = shallow(<BinaryValue type="Binary" value={binary} />);
34
35 it('sets the base class', () => {
36 expect(component.hasClass('element-value')).to.equal(true);
37 });
38
39 it('sets the type class', () => {
40 expect(component.hasClass('element-value-is-binary')).to.equal(true);
41 });
42
43 it('sets the title', () => {
44 expect(component.props().title).to.equal(`Binary('${TESTING_BASE64}')`);
45 });
46
47 it('sets the value', () => {
48 expect(component.text()).to.equal(`Binary('${TESTING_BASE64}')`);
49 });
50 });
51
52 context('when the type is a GUID', () => {
53 const buffer = Buffer.from('WBAc3FDBDU+Zh/cBQFPc3Q==', 'base64');
54 const binary = new Binary(buffer, 4);
55 const component = shallow(<BinaryValue type="Binary" value={binary} />);
56
57 it('title is base64 encoded', () => {
58 expect(component.props().title).to.equal('Binary(\'WBAc3FDBDU+Zh/cBQFPc3Q==\')');
59 });
60
61 it('value is base64 encoded', () => {
62 expect(component.text()).to.equal('Binary(\'WBAc3FDBDU+Zh/cBQFPc3Q==\')');
63 });
64 });
65
66 context('when the type is not a uuid', () => {
67 const binary = new Binary('testing', 2);
68 const component = shallow(<BinaryValue type="Binary" value={binary} />);
69
70 it('sets the base class', () => {
71 expect(component.hasClass('element-value')).to.equal(true);
72 });
73
74 it('sets the type class', () => {
75 expect(component.hasClass('element-value-is-binary')).to.equal(true);
76 });
77
78 it('sets the title', () => {
79 expect(component.props().title).to.equal('Binary(\'dGVzdGluZw==\')');
80 });
81
82 it('sets the value', () => {
83 expect(component.text()).to.equal('Binary(\'dGVzdGluZw==\')');
84 });
85 });
86
87 context('when the type is FLE', () => {
88 const binary = new Binary('testing', 6);
89 const component = shallow(<BinaryValue type="Binary" value={binary} />);
90
91 it('sets the base class', () => {
92 expect(component.hasClass('element-value')).to.equal(true);
93 });
94
95 it('sets the type class', () => {
96 expect(component.hasClass('element-value-is-binary')).to.equal(true);
97 });
98
99 it('sets the title', () => {
100 expect(component.props().title).to.equal('This field is encrypted');
101 });
102
103 it('sets the value', () => {
104 expect(component.text()).to.equal('*********');
105 });
106 });
107});