2021-03-01 18:11:21 +00:00
|
|
|
import { GlTable } from '@gitlab/ui';
|
2020-05-04 18:10:20 +00:00
|
|
|
import { mount } from '@vue/test-utils';
|
2021-03-01 18:11:21 +00:00
|
|
|
import { extendedWrapper } from 'helpers/vue_test_utils_helper';
|
2020-06-24 00:08:43 +00:00
|
|
|
import PipelinesTable from '~/pipelines/components/pipelines_list/pipelines_table.vue';
|
2020-05-04 18:10:20 +00:00
|
|
|
|
|
|
|
describe('Pipelines Table', () => {
|
|
|
|
let pipeline;
|
|
|
|
let wrapper;
|
|
|
|
|
|
|
|
const jsonFixtureName = 'pipelines/pipelines.json';
|
|
|
|
|
|
|
|
const defaultProps = {
|
|
|
|
pipelines: [],
|
|
|
|
viewType: 'root',
|
|
|
|
};
|
|
|
|
|
2021-03-01 18:11:21 +00:00
|
|
|
const createComponent = (props = defaultProps, flagState = false) => {
|
|
|
|
wrapper = extendedWrapper(
|
|
|
|
mount(PipelinesTable, {
|
|
|
|
propsData: props,
|
|
|
|
provide: {
|
|
|
|
glFeatures: {
|
|
|
|
newPipelinesTable: flagState,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}),
|
|
|
|
);
|
2020-05-04 18:10:20 +00:00
|
|
|
};
|
2021-03-01 18:11:21 +00:00
|
|
|
|
2020-05-04 18:10:20 +00:00
|
|
|
const findRows = () => wrapper.findAll('.commit.gl-responsive-table-row');
|
2021-03-01 18:11:21 +00:00
|
|
|
const findGlTable = () => wrapper.findComponent(GlTable);
|
|
|
|
const findLegacyTable = () => wrapper.findByTestId('ci-table');
|
2020-05-04 18:10:20 +00:00
|
|
|
|
|
|
|
preloadFixtures(jsonFixtureName);
|
|
|
|
|
|
|
|
beforeEach(() => {
|
|
|
|
const { pipelines } = getJSONFixture(jsonFixtureName);
|
2020-12-24 00:10:25 +00:00
|
|
|
pipeline = pipelines.find((p) => p.user !== null && p.commit !== null);
|
2020-05-04 18:10:20 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
afterEach(() => {
|
|
|
|
wrapper.destroy();
|
|
|
|
wrapper = null;
|
|
|
|
});
|
|
|
|
|
2021-03-01 18:11:21 +00:00
|
|
|
describe('table with feature flag off', () => {
|
|
|
|
describe('renders the table correctly', () => {
|
|
|
|
beforeEach(() => {
|
|
|
|
createComponent();
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should render a table', () => {
|
|
|
|
expect(wrapper.classes()).toContain('ci-table');
|
|
|
|
});
|
2020-05-04 18:10:20 +00:00
|
|
|
|
2021-03-01 18:11:21 +00:00
|
|
|
it('should render table head with correct columns', () => {
|
|
|
|
expect(wrapper.find('.table-section.js-pipeline-status').text()).toEqual('Status');
|
2020-05-04 18:10:20 +00:00
|
|
|
|
2021-03-01 18:11:21 +00:00
|
|
|
expect(wrapper.find('.table-section.js-pipeline-info').text()).toEqual('Pipeline');
|
2020-05-04 18:10:20 +00:00
|
|
|
|
2021-03-01 18:11:21 +00:00
|
|
|
expect(wrapper.find('.table-section.js-pipeline-commit').text()).toEqual('Commit');
|
2020-05-04 18:10:20 +00:00
|
|
|
|
2021-03-01 18:11:21 +00:00
|
|
|
expect(wrapper.find('.table-section.js-pipeline-stages').text()).toEqual('Stages');
|
|
|
|
});
|
2020-05-04 18:10:20 +00:00
|
|
|
});
|
|
|
|
|
2021-03-01 18:11:21 +00:00
|
|
|
describe('without data', () => {
|
|
|
|
it('should render an empty table', () => {
|
|
|
|
createComponent();
|
|
|
|
|
|
|
|
expect(findRows()).toHaveLength(0);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('with data', () => {
|
|
|
|
it('should render rows', () => {
|
|
|
|
createComponent({ pipelines: [pipeline], viewType: 'root' });
|
|
|
|
|
|
|
|
expect(findRows()).toHaveLength(1);
|
|
|
|
});
|
2020-05-04 18:10:20 +00:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2021-03-01 18:11:21 +00:00
|
|
|
describe('table with feature flag on', () => {
|
|
|
|
it('displays new table', () => {
|
|
|
|
createComponent(defaultProps, true);
|
2020-05-04 18:10:20 +00:00
|
|
|
|
2021-03-01 18:11:21 +00:00
|
|
|
expect(findGlTable().exists()).toBe(true);
|
|
|
|
expect(findLegacyTable().exists()).toBe(false);
|
2020-05-04 18:10:20 +00:00
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|