Skip to content

Commit

Permalink
Fix failing test on search specs (mattermost#3022)
Browse files Browse the repository at this point in the history
  • Loading branch information
saturninoabril committed Jul 2, 2019
1 parent d0055a1 commit de35928
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 14 deletions.
29 changes: 16 additions & 13 deletions cypress/integration/search/date_filter_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,11 @@ function searchAndValidate(query, expectedResults = []) {
// # Enter in search query, and hit enter
cy.get('#searchBox').clear().type(query).type('{enter}');

if (expectedResults.length > 0) {
// * Verify that there's search item before querying by test ID
cy.get('.search-item__container').should('be.visible');
}

// * Verify the amount of results matches the amount of our expected results
cy.queryAllByTestId('search-item-container').should('have.length', expectedResults.length).then((results) => {
if (expectedResults.length > 0) {
Expand Down Expand Up @@ -73,6 +78,7 @@ describe('SF15699 Search Date Filter', () => {
const secondDateLater = getMsAndQueryForDate(Date.UTC(2018, 9, 15, 13, 25)); // October 15th, 2018 @ 1:25pm

const baseUrl = Cypress.config('baseUrl');
let newAdmin;

before(() => {
// # Login as the sysadmin.
Expand Down Expand Up @@ -100,6 +106,7 @@ describe('SF15699 Search Date Filter', () => {

// # Set user to be a sysadmin, so it can access the system console
cy.get('@newAdmin').then((user) => {
newAdmin = user;
cy.task('externalRequest', {user: users.sysadmin, method: 'put', baseUrl, path: `users/${user.id}/roles`, data: {roles: 'system_user system_admin'}}).
its('status').
should('be.equal', 200);
Expand Down Expand Up @@ -191,10 +198,6 @@ describe('SF15699 Search Date Filter', () => {
});

describe('works without leading 0 in', () => {
before(() => {
cy.reload();
});

// These must match the date of the firstMessage, only altering leading zeroes
const tests = [
{name: 'day', date: '2018-06-5'},
Expand Down Expand Up @@ -234,8 +237,8 @@ describe('SF15699 Search Date Filter', () => {
searchAndValidate(`before:${secondDateEarly.query} in:town-square ${timestamp}`, [firstMessage]);
});

it('can be used in conjunction with "from:"', function() {
searchAndValidate(`before:${secondDateEarly.query} from:${this.newAdmin.username} ${timestamp}`, [firstMessage]);
it('can be used in conjunction with "from:"', () => {
searchAndValidate(`before:${secondDateEarly.query} from:${newAdmin.username} ${timestamp}`, [firstMessage]);
});

it('using a date from the future shows results', () => {
Expand All @@ -252,8 +255,8 @@ describe('SF15699 Search Date Filter', () => {
searchAndValidate(`after:${firstDateEarly.query} in:town-square ${timestamp}`, [todayMessage, secondMessage]);
});

it('can be used in conjunction with "from:"', function() {
searchAndValidate(`after:${firstDateEarly.query} from:${this.newAdmin.username} ${timestamp}`, [secondOffTopicMessage]);
it('can be used in conjunction with "from:"', () => {
searchAndValidate(`after:${firstDateEarly.query} from:${newAdmin.username} ${timestamp}`, [secondOffTopicMessage]);
});

it('using a date from the future shows no results', () => {
Expand All @@ -278,8 +281,8 @@ describe('SF15699 Search Date Filter', () => {
searchAndValidate(`on:${secondDateEarly.query} in:town-square ${timestamp}`, [secondMessage]);
});

it('can be used in conjunction with "from:"', function() {
searchAndValidate(`on:${secondDateEarly.query} from:${this.newAdmin.username} ${timestamp}`, [secondOffTopicMessage]);
it('can be used in conjunction with "from:"', () => {
searchAndValidate(`on:${secondDateEarly.query} from:${newAdmin.username} ${timestamp}`, [secondOffTopicMessage]);
});

it('works from 12:00am to 11:59pm', () => {
Expand Down Expand Up @@ -334,8 +337,8 @@ describe('SF15699 Search Date Filter', () => {
searchAndValidate(`before:${Cypress.moment().format('YYYY-MM-DD')} after:${firstDateEarly.query} ${timestamp}`, [secondOffTopicMessage, secondMessage]);
});

it('"before:", "after:", "from:", and "in:" can be used in one search', function() {
searchAndValidate(`before:${Cypress.moment().format('YYYY-MM-DD')} after:${firstDateEarly.query} from:${this.newAdmin.username} in:off-topic ${timestamp}`, [secondOffTopicMessage]);
it('"before:", "after:", "from:", and "in:" can be used in one search', () => {
searchAndValidate(`before:${Cypress.moment().format('YYYY-MM-DD')} after:${firstDateEarly.query} from:${newAdmin.username} in:off-topic ${timestamp}`, [secondOffTopicMessage]);
});
});

Expand Down Expand Up @@ -410,7 +413,7 @@ describe('SF15699 Search Date Filter', () => {

// # Post message with unique text
cy.getCurrentChannelId().then((channelId) => {
cy.postMessageAs(users.sysadmin, targetMessage, channelId, target.ms);
cy.task('postMessageAs', {sender: users.sysadmin, message: targetMessage, channelId, createAt: target.ms, baseUrl});
});

// * Verify result appears in current timezone
Expand Down
2 changes: 1 addition & 1 deletion cypress/integration/search/results_post_comment_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ describe('Search', () => {
cy.apiLogin('user-1');
cy.visit('/');

const message = `asparagus-${Date.now()}`;
const message = `asparagus${Date.now()}`;
const comment = 'Replying to asparagus';

// # Post a new message
Expand Down

0 comments on commit de35928

Please sign in to comment.