From 1c0a1b2b4664d59f674571a87f56c062ab55b5e6 Mon Sep 17 00:00:00 2001 From: Vadim Dalecky Date: Tue, 8 Oct 2019 01:32:51 +0200 Subject: [PATCH] =?UTF-8?q?test:=20=F0=9F=92=8D=20convert=20Interpreter=20?= =?UTF-8?q?font=20function=20tests=20to=20Jest=20(#47193)=20(#47207)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../public/functions/__tests__/font.ts | 192 ----------------- .../interpreter/public/functions/font.test.ts | 202 ++++++++++++++++++ 2 files changed, 202 insertions(+), 192 deletions(-) delete mode 100644 src/legacy/core_plugins/interpreter/public/functions/__tests__/font.ts create mode 100644 src/legacy/core_plugins/interpreter/public/functions/font.test.ts diff --git a/src/legacy/core_plugins/interpreter/public/functions/__tests__/font.ts b/src/legacy/core_plugins/interpreter/public/functions/__tests__/font.ts deleted file mode 100644 index 8bf8052fee3b7..0000000000000 --- a/src/legacy/core_plugins/interpreter/public/functions/__tests__/font.ts +++ /dev/null @@ -1,192 +0,0 @@ -/* - * Licensed to Elasticsearch B.V. under one or more contributor - * license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright - * ownership. Elasticsearch B.V. licenses this file to you under - * the Apache License, Version 2.0 (the "License"); you may - * not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -import expect from '@kbn/expect'; -import { openSans } from '../../../common/lib/fonts'; -import { font } from '../font'; -import { functionWrapper } from '../../../test_helpers'; - -describe('font', () => { - const fn: any = functionWrapper(font); - - describe('default output', () => { - const result = fn(null); - - it('returns a style', () => { - (expect as any)(result) - .to.have.property('type', 'style') - .and.to.have.property('spec') - .and.to.have.property('css'); - }); - }); - - describe('args', () => { - describe('size', () => { - it('sets font size', () => { - const result = fn(null, { size: 20 }); - (expect as any)(result.spec).to.have.property('fontSize', '20px'); - (expect as any)(result.css).to.contain('font-size:20px'); - }); - - it('defaults to 14px', () => { - const result = fn(null); - expect(result.spec).to.have.property('fontSize', '14px'); - expect(result.css).to.contain('font-size:14px'); - }); - }); - - describe('lHeight', () => { - it('sets line height', () => { - const result = fn(null, { lHeight: 30 }); - expect(result.spec).to.have.property('lineHeight', '30px'); - expect(result.css).to.contain('line-height:30px'); - }); - - it('defaults to 1', () => { - const result = fn(null); - expect(result.spec).to.have.property('lineHeight', '1'); - expect(result.css).to.contain('line-height:1'); - }); - }); - - describe('family', () => { - it('sets font family', () => { - const result = fn(null, { family: 'Optima, serif' }); - expect(result.spec).to.have.property('fontFamily', 'Optima, serif'); - expect(result.css).to.contain('font-family:Optima, serif'); - }); - - it(`defaults to "${openSans.value}"`, () => { - const result = fn(null); - expect(result.spec).to.have.property('fontFamily', `"${openSans.value}"`); - expect(result.css).to.contain(`font-family:"${openSans.value}"`); - }); - }); - - describe('color', () => { - it('sets font color', () => { - const result = fn(null, { color: 'blue' }); - expect(result.spec).to.have.property('color', 'blue'); - expect(result.css).to.contain('color:blue'); - }); - }); - - describe('weight', () => { - it('sets font weight', () => { - let result = fn(null, { weight: 'normal' }); - expect(result.spec).to.have.property('fontWeight', 'normal'); - expect(result.css).to.contain('font-weight:normal'); - - result = fn(null, { weight: 'bold' }); - expect(result.spec).to.have.property('fontWeight', 'bold'); - expect(result.css).to.contain('font-weight:bold'); - - result = fn(null, { weight: 'bolder' }); - expect(result.spec).to.have.property('fontWeight', 'bolder'); - expect(result.css).to.contain('font-weight:bolder'); - - result = fn(null, { weight: 'lighter' }); - expect(result.spec).to.have.property('fontWeight', 'lighter'); - expect(result.css).to.contain('font-weight:lighter'); - - result = fn(null, { weight: '400' }); - expect(result.spec).to.have.property('fontWeight', '400'); - expect(result.css).to.contain('font-weight:400'); - }); - - it("defaults to 'normal'", () => { - const result = fn(null); - expect(result.spec).to.have.property('fontWeight', 'normal'); - expect(result.css).to.contain('font-weight:normal'); - }); - - it('throws when provided an invalid weight', () => { - expect(() => fn(null, { weight: 'foo' })).to.throwException(); - }); - }); - - describe('underline', () => { - it('sets text underline', () => { - let result = fn(null, { underline: true }); - expect(result.spec).to.have.property('textDecoration', 'underline'); - expect(result.css).to.contain('text-decoration:underline'); - - result = fn(null, { underline: false }); - expect(result.spec).to.have.property('textDecoration', 'none'); - expect(result.css).to.contain('text-decoration:none'); - }); - - it('defaults to false', () => { - const result = fn(null); - expect(result.spec).to.have.property('textDecoration', 'none'); - expect(result.css).to.contain('text-decoration:none'); - }); - }); - - describe('italic', () => { - it('sets italic', () => { - let result = fn(null, { italic: true }); - expect(result.spec).to.have.property('fontStyle', 'italic'); - expect(result.css).to.contain('font-style:italic'); - - result = fn(null, { italic: false }); - expect(result.spec).to.have.property('fontStyle', 'normal'); - expect(result.css).to.contain('font-style:normal'); - }); - - it('defaults to false', () => { - const result = fn(null); - expect(result.spec).to.have.property('fontStyle', 'normal'); - expect(result.css).to.contain('font-style:normal'); - }); - }); - - describe('align', () => { - it('sets text alignment', () => { - let result = fn(null, { align: 'left' }); - expect(result.spec).to.have.property('textAlign', 'left'); - expect(result.css).to.contain('text-align:left'); - - result = fn(null, { align: 'center' }); - expect(result.spec).to.have.property('textAlign', 'center'); - expect(result.css).to.contain('text-align:center'); - - result = fn(null, { align: 'right' }); - expect(result.spec).to.have.property('textAlign', 'right'); - expect(result.css).to.contain('text-align:right'); - - result = fn(null, { align: 'justify' }); - expect(result.spec).to.have.property('textAlign', 'justify'); - expect(result.css).to.contain('text-align:justify'); - }); - - it(`defaults to 'left'`, () => { - const result = fn(null); - expect(result.spec).to.have.property('textAlign', 'left'); - expect(result.css).to.contain('text-align:left'); - }); - - it('throws when provided an invalid alignment', () => { - expect(fn) - .withArgs(null, { align: 'foo' }) - .to.throwException(); - }); - }); - }); -}); diff --git a/src/legacy/core_plugins/interpreter/public/functions/font.test.ts b/src/legacy/core_plugins/interpreter/public/functions/font.test.ts new file mode 100644 index 0000000000000..dba540178777b --- /dev/null +++ b/src/legacy/core_plugins/interpreter/public/functions/font.test.ts @@ -0,0 +1,202 @@ +/* + * Licensed to Elasticsearch B.V. under one or more contributor + * license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright + * ownership. Elasticsearch B.V. licenses this file to you under + * the Apache License, Version 2.0 (the "License"); you may + * not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +import { openSans } from '../../common/lib/fonts'; +import { font } from './font'; +import { functionWrapper } from '../../test_helpers'; + +describe('font', () => { + const fn: any = functionWrapper(font); + + describe('default output', () => { + const result = fn(null); + + it('returns a style', () => { + expect(result).toMatchObject({ + type: 'style', + spec: expect.any(Object), + css: expect.any(String), + }); + }); + }); + + describe('args', () => { + describe('size', () => { + it('sets font size', () => { + const result = fn(null, { size: 20 }); + expect(result).toMatchObject({ + spec: { + fontSize: '20px', + }, + }); + expect(result.css).toContain('font-size:20px'); + }); + + it('defaults to 14px', () => { + const result = fn(null); + expect(result).toMatchObject({ + spec: { + fontSize: '14px', + }, + }); + expect(result.css).toContain('font-size:14px'); + }); + }); + + describe('lHeight', () => { + it('sets line height', () => { + const result = fn(null, { lHeight: 30 }); + expect(result).toMatchObject({ + spec: { + lineHeight: '30px', + }, + }); + expect(result.css).toContain('line-height:30px'); + }); + + it('defaults to 1', () => { + const result = fn(null); + expect(result.spec.lineHeight).toBe('1'); + expect(result.css).toContain('line-height:1'); + }); + }); + + describe('family', () => { + it('sets font family', () => { + const result = fn(null, { family: 'Optima, serif' }); + expect(result.spec.fontFamily).toBe('Optima, serif'); + expect(result.css).toContain('font-family:Optima, serif'); + }); + + it(`defaults to "${openSans.value}"`, () => { + const result = fn(null); + expect(result.spec.fontFamily).toBe(`"${openSans.value}"`); + expect(result.css).toContain(`font-family:"${openSans.value}"`); + }); + }); + + describe('color', () => { + it('sets font color', () => { + const result = fn(null, { color: 'blue' }); + expect(result.spec.color).toBe('blue'); + expect(result.css).toContain('color:blue'); + }); + }); + + describe('weight', () => { + it('sets font weight', () => { + let result = fn(null, { weight: 'normal' }); + expect(result.spec.fontWeight).toBe('normal'); + expect(result.css).toContain('font-weight:normal'); + + result = fn(null, { weight: 'bold' }); + expect(result.spec.fontWeight).toBe('bold'); + expect(result.css).toContain('font-weight:bold'); + + result = fn(null, { weight: 'bolder' }); + expect(result.spec.fontWeight).toBe('bolder'); + expect(result.css).toContain('font-weight:bolder'); + + result = fn(null, { weight: 'lighter' }); + expect(result.spec.fontWeight).toBe('lighter'); + expect(result.css).toContain('font-weight:lighter'); + + result = fn(null, { weight: '400' }); + expect(result.spec.fontWeight).toBe('400'); + expect(result.css).toContain('font-weight:400'); + }); + + it("defaults to 'normal'", () => { + const result = fn(null); + expect(result.spec.fontWeight).toBe('normal'); + expect(result.css).toContain('font-weight:normal'); + }); + + it('throws when provided an invalid weight', () => { + expect(() => fn(null, { weight: 'foo' })).toThrow(); + }); + }); + + describe('underline', () => { + it('sets text underline', () => { + let result = fn(null, { underline: true }); + expect(result.spec.textDecoration).toBe('underline'); + expect(result.css).toContain('text-decoration:underline'); + + result = fn(null, { underline: false }); + expect(result.spec.textDecoration).toBe('none'); + expect(result.css).toContain('text-decoration:none'); + }); + + it('defaults to false', () => { + const result = fn(null); + expect(result.spec.textDecoration).toBe('none'); + expect(result.css).toContain('text-decoration:none'); + }); + }); + + describe('italic', () => { + it('sets italic', () => { + let result = fn(null, { italic: true }); + expect(result.spec.fontStyle).toBe('italic'); + expect(result.css).toContain('font-style:italic'); + + result = fn(null, { italic: false }); + expect(result.spec.fontStyle).toBe('normal'); + expect(result.css).toContain('font-style:normal'); + }); + + it('defaults to false', () => { + const result = fn(null); + expect(result.spec.fontStyle).toBe('normal'); + expect(result.css).toContain('font-style:normal'); + }); + }); + + describe('align', () => { + it('sets text alignment', () => { + let result = fn(null, { align: 'left' }); + expect(result.spec.textAlign).toBe('left'); + expect(result.css).toContain('text-align:left'); + + result = fn(null, { align: 'center' }); + expect(result.spec.textAlign).toBe('center'); + expect(result.css).toContain('text-align:center'); + + result = fn(null, { align: 'right' }); + expect(result.spec.textAlign).toBe('right'); + expect(result.css).toContain('text-align:right'); + + result = fn(null, { align: 'justify' }); + expect(result.spec.textAlign).toBe('justify'); + expect(result.css).toContain('text-align:justify'); + }); + + it(`defaults to 'left'`, () => { + const result = fn(null); + expect(result.spec.textAlign).toBe('left'); + expect(result.css).toContain('text-align:left'); + }); + + it('throws when provided an invalid alignment', () => { + expect(() => fn(null, { align: 'foo' })).toThrow(); + }); + }); + }); +});