Skip to content

Commit

Permalink
Merge pull request #1 from antvis/master
Browse files Browse the repository at this point in the history
update from origin
  • Loading branch information
LHC8888 authored Oct 18, 2022
2 parents 1b1e80f + 1ede665 commit 408b79f
Show file tree
Hide file tree
Showing 29 changed files with 540 additions and 253 deletions.
14 changes: 13 additions & 1 deletion .releaserc.base.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,19 @@ module.exports = {
],
extends: 'semantic-release-monorepo',
plugins: [
'@semantic-release/commit-analyzer',
[
'@semantic-release/commit-analyzer',
{
preset: 'angular',
releaseRules: [
{ type: 'feat', release: 'minor' },
{ type: 'fix', release: 'patch' },
{ type: 'perf', release: 'patch' },
{ type: 'refactor', release: 'patch' },
{ type: 'style', release: 'patch' },
],
},
],
'@semantic-release/release-notes-generator',
'@semantic-release/changelog',
'@semantic-release/npm',
Expand Down
2 changes: 1 addition & 1 deletion packages/s2-core/__tests__/bugs/issue-1624-spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ describe('Data Cell Border Tests', () => {

// @ts-ignore
const meta = dataCell.getCellArea();
const borderBbox = dataCell.getChildByIndex(3).getBBox();
const borderBbox = dataCell.getChildByIndex(2).getBBox();

expect(meta.x).toEqual(borderBbox.x - borderWidth / 2);
expect(meta.y).toEqual(borderBbox.y - borderWidth / 2);
Expand Down
3 changes: 1 addition & 2 deletions packages/s2-core/__tests__/spreadsheet/theme-spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -448,8 +448,7 @@ describe('SpreadSheet Theme Tests', () => {

const seriesCell = s2.facet.rowIndexHeader.getChildByIndex(3) as IGroup; // 序号1
const textOfSeriesCell = getTextShape(seriesCell);

expect(textOfRowCell.attr('textBaseline')).toEqual('top');
expect(textOfRowCell.attr('textBaseline')).toEqual(textBaseline);
expect(textOfSeriesCell.attr('textBaseline')).toEqual('top');
expect(textOfRowCell.attr('y')).toEqual(textOfSeriesCell.attr('y'));
},
Expand Down
91 changes: 85 additions & 6 deletions packages/s2-core/__tests__/unit/cell/col-cell-spec.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
import _ from 'lodash';
/* eslint-disable @typescript-eslint/ban-ts-comment */
import { get, set } from 'lodash';
import { createPivotSheet } from 'tests/util/helpers';
import type { Node } from '@/facet/layout/node';
import { PivotDataSet } from '@/data-set';
import { SpreadSheet, PivotSheet } from '@/sheet-type';
import type { Formatter, TextAlign } from '@/common';
import { EXTRA_FIELD, type Formatter, type TextAlign } from '@/common';
import { ColCell } from '@/cell';

const MockPivotSheet = PivotSheet as unknown as jest.Mock<PivotSheet>;
Expand Down Expand Up @@ -55,9 +57,9 @@ describe('Col Cell Tests', () => {
});

const colCell = new ColCell(node, s2, { ...headerConfig });
_.set(colCell, 'actualTextWidth', actualTextWidth); // 文字总长度
set(colCell, 'actualTextWidth', actualTextWidth); // 文字总长度

const getTextPosition = _.get(colCell, 'getTextPosition').bind(colCell);
const getTextPosition = get(colCell, 'getTextPosition').bind(colCell);
expect(getTextPosition()).toEqual({
x: textX,
y: 15,
Expand Down Expand Up @@ -95,9 +97,9 @@ describe('Col Cell Tests', () => {
});

const colCell = new ColCell(node, s2, { ...headerConfig });
_.set(colCell, 'actualTextWidth', actualTextWidth); // 文字总长度
set(colCell, 'actualTextWidth', actualTextWidth); // 文字总长度

const getIconPosition = _.get(colCell, 'getIconPosition').bind(colCell);
const getIconPosition = get(colCell, 'getIconPosition').bind(colCell);
expect(getIconPosition()).toEqual({
x: iconX,
y: 10,
Expand Down Expand Up @@ -136,4 +138,81 @@ describe('Col Cell Tests', () => {
expect(colCell.textShape.attr('text')).toEqual('test');
});
});

describe('Condition Tests', () => {
const s2 = createPivotSheet({
conditions: {
text: [
{
field: EXTRA_FIELD,
mapping() {
return {
fill: '#5083F5',
};
},
},
],
},
});
test('should draw right condition text shape', () => {
s2.render();
const colCell = s2.facet.columnHeader
.getChildByIndex(0)
// @ts-ignore
.getChildByIndex(1);

expect(get(colCell, 'textShape.attrs.fill')).toEqual('#5083F5');
});

test('should draw right condition icon shape', () => {
s2.setOptions({
conditions: {
icon: [
{
field: 'type',
mapping(field) {
if (field === '笔') {
return {
icon: 'CellUp',
fill: 'red',
};
}
},
},
],
},
});
s2.render();

const colCell = s2.facet.columnHeader
.getChildByIndex(0)
// @ts-ignore
.getChildByIndex(0);
expect(get(colCell, 'conditionIconShape.cfg.name')).toEqual('CellUp');
expect(get(colCell, 'conditionIconShape.cfg.fill')).toEqual('red');
});

test('should draw right condition background shape', () => {
s2.setOptions({
conditions: {
background: [
{
field: EXTRA_FIELD,
mapping() {
return {
fill: '#F7B46F',
};
},
},
],
},
});
s2.render();
const colCell = s2.facet.columnHeader
.getChildByIndex(0)
// @ts-ignore
.getChildByIndex(1);
expect(get(colCell, 'backgroundShape.attrs.fill')).toEqual('#F7B46F');
});
});
});
210 changes: 142 additions & 68 deletions packages/s2-core/__tests__/unit/cell/data-cell-spec.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
/* eslint-disable @typescript-eslint/ban-ts-comment */
import { get } from 'lodash';
import { createPivotSheet } from 'tests/util/helpers';
import { EXTRA_FIELD, VALUE_FIELD } from '@/common/constant/basic';
import type { Formatter, ViewMeta } from '@/common';
import { PivotDataSet } from '@/data-set';
Expand All @@ -9,91 +11,163 @@ import type { PivotFacet } from '@/facet';
const MockPivotSheet = PivotSheet as unknown as jest.Mock<PivotSheet>;
const MockPivotDataSet = PivotDataSet as unknown as jest.Mock<PivotDataSet>;

describe('data cell formatter test', () => {
const meta = {
fieldValue: 'fieldValue',
label: 'label',
value: 'value',
data: {
city: 'chengdu',
value: 12,
[VALUE_FIELD]: 'value',
[EXTRA_FIELD]: 12,
},
} as unknown as ViewMeta;

let s2: SpreadSheet;

beforeEach(() => {
const container = document.createElement('div');
describe('Data Cell Tests', () => {
describe('data cell formatter test', () => {
const meta = {
fieldValue: 'fieldValue',
label: 'label',
value: 'value',
data: {
city: 'chengdu',
value: 12,
[VALUE_FIELD]: 'value',
[EXTRA_FIELD]: 12,
},
} as unknown as ViewMeta;

s2 = new MockPivotSheet(container);
const dataSet: PivotDataSet = new MockPivotDataSet(s2);
let s2: SpreadSheet;

s2.dataSet = dataSet;
beforeEach(() => {
const container = document.createElement('div');

s2.facet = {
layoutResult: {
rowLeafNodes: [],
},
} as PivotFacet;
});
s2 = new MockPivotSheet(container);
const dataSet: PivotDataSet = new MockPivotDataSet(s2);

test('should pass complete data into formatter', () => {
const formatter = jest.fn();
jest.spyOn(s2.dataSet, 'getFieldFormatter').mockReturnValue(formatter);
s2.dataSet = dataSet;

// eslint-disable-next-line @typescript-eslint/no-unused-vars
const dataCell = new DataCell(meta, s2);
s2.facet = {
layoutResult: {
rowLeafNodes: [],
},
} as PivotFacet;
});

expect(formatter).toHaveBeenCalledWith(meta.fieldValue, meta.data, meta);
});
test('should pass complete data into formatter', () => {
const formatter = jest.fn();
jest.spyOn(s2.dataSet, 'getFieldFormatter').mockReturnValue(formatter);

test('should return correct formatted value', () => {
const formatter: Formatter = (value, data) => `${get(data, 'value') * 10}`;
jest.spyOn(s2.dataSet, 'getFieldFormatter').mockReturnValue(formatter);
// eslint-disable-next-line @typescript-eslint/no-unused-vars
const dataCell = new DataCell(meta, s2);
expect(formatter).toHaveBeenCalledWith(meta.fieldValue, meta.data, meta);
});

const dataCell = new DataCell(meta, s2);
test('should return correct formatted value', () => {
const formatter: Formatter = (_, data) => `${get(data, 'value') * 10}`;
jest.spyOn(s2.dataSet, 'getFieldFormatter').mockReturnValue(formatter);

// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore
expect(dataCell.textShape.attr('text')).toEqual('120');
});
const dataCell = new DataCell(meta, s2);

test('should draw condition interval shape', () => {
const cellWidth = 120;
const fieldValue = 27.334666666666667;
const anotherMeta = {
width: cellWidth,
valueField: 'value',
fieldValue,
data: {
city: 'chengdu',
value: fieldValue,
[VALUE_FIELD]: 'value',
[EXTRA_FIELD]: fieldValue,
},
} as unknown as ViewMeta;

jest.spyOn(s2.dataSet, 'getValueRangeByField').mockReturnValue({
minValue: 0,
maxValue: fieldValue,
// @ts-ignore
expect(dataCell.textShape.attr('text')).toEqual('120');
});

s2.setOptions({
});
describe('Condition Tests', () => {
const s2 = createPivotSheet({
conditions: {
interval: [
text: [
{
field: 'value',
mapping: () => ({ fill: 'red' }),
field: 'price',
mapping() {
return {
fill: '#5083F5',
};
},
},
],
},
});
test('should draw right condition text shape', () => {
s2.render();
const dataCell = s2.facet.panelGroup
.getChildByIndex(0)
// @ts-ignore
.getChildByIndex(0);
expect(get(dataCell, 'textShape.attrs.fill')).toEqual('#5083F5');
});

test('should draw right condition icon shape', () => {
s2.setOptions({
conditions: {
icon: [
{
field: 'cost',
mapping() {
return {
icon: 'CellUp',
fill: 'red',
};
},
},
],
},
});
s2.render();
const dataCell = s2.facet.panelGroup
.getChildByIndex(0)
// @ts-ignore
.getChildByIndex(2);
expect(get(dataCell, 'conditionIconShape.cfg.name')).toEqual('CellUp');
expect(get(dataCell, 'conditionIconShape.cfg.fill')).toEqual('red');
});

const dataCell = new DataCell(anotherMeta, s2);
expect(get(dataCell, 'conditionIntervalShape.attrs.width')).toEqual(
cellWidth,
);
test('should draw right condition background shape', () => {
s2.setOptions({
conditions: {
background: [
{
field: 'cost',
mapping() {
return {
fill: '#F7B46F',
};
},
},
],
},
});
s2.render();
const dataCell = s2.facet.panelGroup
.getChildByIndex(0)
// @ts-ignore
.getChildByIndex(2);
expect(get(dataCell, 'backgroundShape.attrs.fill')).toEqual('#F7B46F');
});

test('should draw condition interval shape', () => {
const cellWidth = 120;
const fieldValue = 27.334666666666667;
const anotherMeta = {
width: cellWidth,
valueField: 'value',
fieldValue,
data: {
city: 'chengdu',
value: fieldValue,
[VALUE_FIELD]: 'value',
[EXTRA_FIELD]: fieldValue,
},
} as unknown as ViewMeta;

jest.spyOn(s2.dataSet, 'getValueRangeByField').mockReturnValue({
minValue: 0,
maxValue: fieldValue,
});

s2.setOptions({
conditions: {
interval: [
{
field: 'value',
mapping: () => ({ fill: 'red' }),
},
],
},
});

const dataCell = new DataCell(anotherMeta, s2);
expect(get(dataCell, 'conditionIntervalShape.attrs.width')).toEqual(
cellWidth,
);
});
});
});
Loading

0 comments on commit 408b79f

Please sign in to comment.