Commit eeec468d authored by Nicolò Maria Mezzopera's avatar Nicolò Maria Mezzopera

Merge branch 'xanf/fix-async-props' into 'master'

Properly await setProps to update component

See merge request gitlab-org/gitlab!50099
parents d033d6c7 22fb2974
...@@ -27,7 +27,7 @@ describe('FrequentItemsListComponent', () => { ...@@ -27,7 +27,7 @@ describe('FrequentItemsListComponent', () => {
describe('computed', () => { describe('computed', () => {
describe('isListEmpty', () => { describe('isListEmpty', () => {
it('should return `true` or `false` representing whether if `items` is empty or not with projects', () => { it('should return `true` or `false` representing whether if `items` is empty or not with projects', async () => {
createComponent({ createComponent({
items: [], items: [],
}); });
...@@ -37,13 +37,14 @@ describe('FrequentItemsListComponent', () => { ...@@ -37,13 +37,14 @@ describe('FrequentItemsListComponent', () => {
wrapper.setProps({ wrapper.setProps({
items: mockFrequentProjects, items: mockFrequentProjects,
}); });
await wrapper.vm.$nextTick();
expect(wrapper.vm.isListEmpty).toBe(false); expect(wrapper.vm.isListEmpty).toBe(false);
}); });
}); });
describe('fetched item messages', () => { describe('fetched item messages', () => {
it('should return appropriate empty list message based on value of `localStorageFailed` prop with projects', () => { it('should return appropriate empty list message based on value of `localStorageFailed` prop with projects', async () => {
createComponent({ createComponent({
isFetchFailed: true, isFetchFailed: true,
}); });
...@@ -55,13 +56,14 @@ describe('FrequentItemsListComponent', () => { ...@@ -55,13 +56,14 @@ describe('FrequentItemsListComponent', () => {
wrapper.setProps({ wrapper.setProps({
isFetchFailed: false, isFetchFailed: false,
}); });
await wrapper.vm.$nextTick();
expect(wrapper.vm.listEmptyMessage).toBe('Projects you visit often will appear here'); expect(wrapper.vm.listEmptyMessage).toBe('Projects you visit often will appear here');
}); });
}); });
describe('searched item messages', () => { describe('searched item messages', () => {
it('should return appropriate empty list message based on value of `searchFailed` prop with projects', () => { it('should return appropriate empty list message based on value of `searchFailed` prop with projects', async () => {
createComponent({ createComponent({
hasSearchQuery: true, hasSearchQuery: true,
isFetchFailed: true, isFetchFailed: true,
...@@ -72,6 +74,7 @@ describe('FrequentItemsListComponent', () => { ...@@ -72,6 +74,7 @@ describe('FrequentItemsListComponent', () => {
wrapper.setProps({ wrapper.setProps({
isFetchFailed: false, isFetchFailed: false,
}); });
await wrapper.vm.$nextTick();
expect(wrapper.vm.listEmptyMessage).toBe('Sorry, no projects matched your search'); expect(wrapper.vm.listEmptyMessage).toBe('Sorry, no projects matched your search');
}); });
......
...@@ -128,14 +128,17 @@ describe('Ref selector component', () => { ...@@ -128,14 +128,17 @@ describe('Ref selector component', () => {
const selectFirstBranch = () => { const selectFirstBranch = () => {
findFirstBranchDropdownItem().vm.$emit('click'); findFirstBranchDropdownItem().vm.$emit('click');
return wrapper.vm.$nextTick();
}; };
const selectFirstTag = () => { const selectFirstTag = () => {
findFirstTagDropdownItem().vm.$emit('click'); findFirstTagDropdownItem().vm.$emit('click');
return wrapper.vm.$nextTick();
}; };
const selectFirstCommit = () => { const selectFirstCommit = () => {
findFirstCommitDropdownItem().vm.$emit('click'); findFirstCommitDropdownItem().vm.$emit('click');
return wrapper.vm.$nextTick();
}; };
const waitForRequests = ({ andClearMocks } = { andClearMocks: false }) => const waitForRequests = ({ andClearMocks } = { andClearMocks: false }) =>
...@@ -522,75 +525,73 @@ describe('Ref selector component', () => { ...@@ -522,75 +525,73 @@ describe('Ref selector component', () => {
return waitForRequests(); return waitForRequests();
}); });
it('renders a checkmark by the selected item', () => { it('renders a checkmark by the selected item', async () => {
expect(findFirstBranchDropdownItem().find(GlIcon).element).toHaveClass( expect(findFirstBranchDropdownItem().find(GlIcon).element).toHaveClass(
'gl-visibility-hidden', 'gl-visibility-hidden',
); );
selectFirstBranch(); await selectFirstBranch();
return localVue.nextTick().then(() => { expect(findFirstBranchDropdownItem().find(GlIcon).element).not.toHaveClass(
expect(findFirstBranchDropdownItem().find(GlIcon).element).not.toHaveClass( 'gl-visibility-hidden',
'gl-visibility-hidden', );
);
});
}); });
describe('when a branch is seleceted', () => { describe('when a branch is seleceted', () => {
it("displays the branch name in the dropdown's button", () => { it("displays the branch name in the dropdown's button", async () => {
expect(findButtonContent().text()).toBe(DEFAULT_I18N.noRefSelected); expect(findButtonContent().text()).toBe(DEFAULT_I18N.noRefSelected);
selectFirstBranch(); await selectFirstBranch();
return localVue.nextTick().then(() => { return localVue.nextTick().then(() => {
expect(findButtonContent().text()).toBe(fixtures.branches[0].name); expect(findButtonContent().text()).toBe(fixtures.branches[0].name);
}); });
}); });
it("updates the v-model binding with the branch's name", () => { it("updates the v-model binding with the branch's name", async () => {
expect(wrapper.vm.value).toEqual(''); expect(wrapper.vm.value).toEqual('');
selectFirstBranch(); await selectFirstBranch();
expect(wrapper.vm.value).toEqual(fixtures.branches[0].name); expect(wrapper.vm.value).toEqual(fixtures.branches[0].name);
}); });
}); });
describe('when a tag is seleceted', () => { describe('when a tag is seleceted', () => {
it("displays the tag name in the dropdown's button", () => { it("displays the tag name in the dropdown's button", async () => {
expect(findButtonContent().text()).toBe(DEFAULT_I18N.noRefSelected); expect(findButtonContent().text()).toBe(DEFAULT_I18N.noRefSelected);
selectFirstTag(); await selectFirstTag();
return localVue.nextTick().then(() => { return localVue.nextTick().then(() => {
expect(findButtonContent().text()).toBe(fixtures.tags[0].name); expect(findButtonContent().text()).toBe(fixtures.tags[0].name);
}); });
}); });
it("updates the v-model binding with the tag's name", () => { it("updates the v-model binding with the tag's name", async () => {
expect(wrapper.vm.value).toEqual(''); expect(wrapper.vm.value).toEqual('');
selectFirstTag(); await selectFirstTag();
expect(wrapper.vm.value).toEqual(fixtures.tags[0].name); expect(wrapper.vm.value).toEqual(fixtures.tags[0].name);
}); });
}); });
describe('when a commit is selected', () => { describe('when a commit is selected', () => {
it("displays the full SHA in the dropdown's button", () => { it("displays the full SHA in the dropdown's button", async () => {
expect(findButtonContent().text()).toBe(DEFAULT_I18N.noRefSelected); expect(findButtonContent().text()).toBe(DEFAULT_I18N.noRefSelected);
selectFirstCommit(); await selectFirstCommit();
return localVue.nextTick().then(() => { return localVue.nextTick().then(() => {
expect(findButtonContent().text()).toBe(fixtures.commit.id); expect(findButtonContent().text()).toBe(fixtures.commit.id);
}); });
}); });
it("updates the v-model binding with the commit's full SHA", () => { it("updates the v-model binding with the commit's full SHA", async () => {
expect(wrapper.vm.value).toEqual(''); expect(wrapper.vm.value).toEqual('');
selectFirstCommit(); await selectFirstCommit();
expect(wrapper.vm.value).toEqual(fixtures.commit.id); expect(wrapper.vm.value).toEqual(fixtures.commit.id);
}); });
......
...@@ -33,28 +33,31 @@ describe('IssueMilestoneComponent', () => { ...@@ -33,28 +33,31 @@ describe('IssueMilestoneComponent', () => {
describe('computed', () => { describe('computed', () => {
describe('isMilestoneStarted', () => { describe('isMilestoneStarted', () => {
it('should return `false` when milestoneStart prop is not defined', () => { it('should return `false` when milestoneStart prop is not defined', async () => {
wrapper.setProps({ wrapper.setProps({
milestone: { ...mockMilestone, start_date: '' }, milestone: { ...mockMilestone, start_date: '' },
}); });
await wrapper.vm.$nextTick();
expect(wrapper.vm.isMilestoneStarted).toBe(false); expect(wrapper.vm.isMilestoneStarted).toBe(false);
}); });
it('should return `true` when milestone start date is past current date', () => { it('should return `true` when milestone start date is past current date', async () => {
wrapper.setProps({ await wrapper.setProps({
milestone: { ...mockMilestone, start_date: '1990-07-22' }, milestone: { ...mockMilestone, start_date: '1990-07-22' },
}); });
await wrapper.vm.$nextTick();
expect(wrapper.vm.isMilestoneStarted).toBe(true); expect(wrapper.vm.isMilestoneStarted).toBe(true);
}); });
}); });
describe('isMilestonePastDue', () => { describe('isMilestonePastDue', () => {
it('should return `false` when milestoneDue prop is not defined', () => { it('should return `false` when milestoneDue prop is not defined', async () => {
wrapper.setProps({ wrapper.setProps({
milestone: { ...mockMilestone, due_date: '' }, milestone: { ...mockMilestone, due_date: '' },
}); });
await wrapper.vm.$nextTick();
expect(wrapper.vm.isMilestonePastDue).toBe(false); expect(wrapper.vm.isMilestonePastDue).toBe(false);
}); });
...@@ -73,41 +76,45 @@ describe('IssueMilestoneComponent', () => { ...@@ -73,41 +76,45 @@ describe('IssueMilestoneComponent', () => {
expect(vm.milestoneDatesAbsolute).toBe('(December 31, 2019)'); expect(vm.milestoneDatesAbsolute).toBe('(December 31, 2019)');
}); });
it('returns string containing absolute milestone start date when due date is not present', () => { it('returns string containing absolute milestone start date when due date is not present', async () => {
wrapper.setProps({ wrapper.setProps({
milestone: { ...mockMilestone, due_date: '' }, milestone: { ...mockMilestone, due_date: '' },
}); });
await wrapper.vm.$nextTick();
expect(wrapper.vm.milestoneDatesAbsolute).toBe('(January 1, 2018)'); expect(wrapper.vm.milestoneDatesAbsolute).toBe('(January 1, 2018)');
}); });
it('returns empty string when both milestone start and due dates are not present', () => { it('returns empty string when both milestone start and due dates are not present', async () => {
wrapper.setProps({ wrapper.setProps({
milestone: { ...mockMilestone, start_date: '', due_date: '' }, milestone: { ...mockMilestone, start_date: '', due_date: '' },
}); });
await wrapper.vm.$nextTick();
expect(wrapper.vm.milestoneDatesAbsolute).toBe(''); expect(wrapper.vm.milestoneDatesAbsolute).toBe('');
}); });
}); });
describe('milestoneDatesHuman', () => { describe('milestoneDatesHuman', () => {
it('returns string containing milestone due date when date is yet to be due', () => { it('returns string containing milestone due date when date is yet to be due', async () => {
wrapper.setProps({ wrapper.setProps({
milestone: { ...mockMilestone, due_date: `${new Date().getFullYear() + 10}-01-01` }, milestone: { ...mockMilestone, due_date: `${new Date().getFullYear() + 10}-01-01` },
}); });
await wrapper.vm.$nextTick();
expect(wrapper.vm.milestoneDatesHuman).toContain('years remaining'); expect(wrapper.vm.milestoneDatesHuman).toContain('years remaining');
}); });
it('returns string containing milestone start date when date has already started and due date is not present', () => { it('returns string containing milestone start date when date has already started and due date is not present', async () => {
wrapper.setProps({ wrapper.setProps({
milestone: { ...mockMilestone, start_date: '1990-07-22', due_date: '' }, milestone: { ...mockMilestone, start_date: '1990-07-22', due_date: '' },
}); });
await wrapper.vm.$nextTick();
expect(wrapper.vm.milestoneDatesHuman).toContain('Started'); expect(wrapper.vm.milestoneDatesHuman).toContain('Started');
}); });
it('returns string containing milestone start date when date is yet to start and due date is not present', () => { it('returns string containing milestone start date when date is yet to start and due date is not present', async () => {
wrapper.setProps({ wrapper.setProps({
milestone: { milestone: {
...mockMilestone, ...mockMilestone,
...@@ -115,14 +122,16 @@ describe('IssueMilestoneComponent', () => { ...@@ -115,14 +122,16 @@ describe('IssueMilestoneComponent', () => {
due_date: '', due_date: '',
}, },
}); });
await wrapper.vm.$nextTick();
expect(wrapper.vm.milestoneDatesHuman).toContain('Starts'); expect(wrapper.vm.milestoneDatesHuman).toContain('Starts');
}); });
it('returns empty string when milestone start and due dates are not present', () => { it('returns empty string when milestone start and due dates are not present', async () => {
wrapper.setProps({ wrapper.setProps({
milestone: { ...mockMilestone, start_date: '', due_date: '' }, milestone: { ...mockMilestone, start_date: '', due_date: '' },
}); });
await wrapper.vm.$nextTick();
expect(wrapper.vm.milestoneDatesHuman).toBe(''); expect(wrapper.vm.milestoneDatesHuman).toBe('');
}); });
......
...@@ -33,8 +33,8 @@ describe('BaseComponent', () => { ...@@ -33,8 +33,8 @@ describe('BaseComponent', () => {
expect(vm.hiddenInputName).toBe('issue[label_names][]'); expect(vm.hiddenInputName).toBe('issue[label_names][]');
}); });
it('returns correct string when showCreate prop is `false`', () => { it('returns correct string when showCreate prop is `false`', async () => {
wrapper.setProps({ showCreate: false }); await wrapper.setProps({ showCreate: false });
expect(vm.hiddenInputName).toBe('label_id[]'); expect(vm.hiddenInputName).toBe('label_id[]');
}); });
...@@ -45,8 +45,8 @@ describe('BaseComponent', () => { ...@@ -45,8 +45,8 @@ describe('BaseComponent', () => {
expect(vm.createLabelTitle).toBe('Create project label'); expect(vm.createLabelTitle).toBe('Create project label');
}); });
it('return `Create group label` when `isProject` prop is false', () => { it('return `Create group label` when `isProject` prop is false', async () => {
wrapper.setProps({ isProject: false }); await wrapper.setProps({ isProject: false });
expect(vm.createLabelTitle).toBe('Create group label'); expect(vm.createLabelTitle).toBe('Create group label');
}); });
...@@ -57,8 +57,8 @@ describe('BaseComponent', () => { ...@@ -57,8 +57,8 @@ describe('BaseComponent', () => {
expect(vm.manageLabelsTitle).toBe('Manage project labels'); expect(vm.manageLabelsTitle).toBe('Manage project labels');
}); });
it('return `Manage group labels` when `isProject` prop is false', () => { it('return `Manage group labels` when `isProject` prop is false', async () => {
wrapper.setProps({ isProject: false }); await wrapper.setProps({ isProject: false });
expect(vm.manageLabelsTitle).toBe('Manage group labels'); expect(vm.manageLabelsTitle).toBe('Manage group labels');
}); });
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment