File size: 2,302 Bytes
1e92f2d
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
import data from '../../shared/testing/data';
const user = data.users[0];

const toastMessage = 'This is a long toast message';

describe('Toasts and url query paramaters', () => {
  beforeEach(() => {
    cy.auth(user.id);
  });

  it('should show toast', () => {
    const url = new URL('http://localhost:3000/me/settings');
    url.searchParams.append('toastType', 'success');
    url.searchParams.append('toastMessage', toastMessage);
    cy.visit(url.toString());
    cy.get('[data-cy="toast-success"]').contains(toastMessage);
    cy.url().should('eq', 'http://localhost:3000/users/mxstbr/settings');
  });

  it('should not show toast if no toastType', () => {
    const url = new URL('http://localhost:3000/me/settings');
    url.searchParams.append('toastMessage', toastMessage);
    cy.visit(url.toString());
    cy.get('[data-cy="toast-success"]').should('have.length', 0);
    cy.url().should('eq', 'http://localhost:3000/users/mxstbr/settings');
  });

  it('should not show toast if no toastMessage', () => {
    const url = new URL('http://localhost:3000/me/settings');
    url.searchParams.append('toastType', 'success');
    cy.visit(url.toString());
    cy.get('[data-cy="toast-success"]', { timeout: 1 }).should(
      'have.length',
      0
    );
    cy.url().should('eq', 'http://localhost:3000/users/mxstbr/settings');
  });

  it('should not show toast if invalid toastType', () => {
    const url = new URL('http://localhost:3000/me/settings');
    url.searchParams.append('toastType', 'foo');
    cy.visit(url.toString());
    cy.get('[data-cy="toast-success"]', { timeout: 1 }).should(
      'have.length',
      0
    );
    cy.url().should('eq', 'http://localhost:3000/users/mxstbr/settings');
  });

  it('should preserve existing query parameters', () => {
    const url = new URL(
      'http://localhost:3000/spectrum/general/another-thread~thread-2?m=MTQ4MzIyNTIwMDAwMg=='
    );
    url.searchParams.append('toastType', 'success');
    url.searchParams.append('toastMessage', toastMessage);
    cy.visit(url.toString());
    cy.get('[data-cy="toast-success"]', { timeout: 100 }).should(
      'have.length',
      1
    );
    cy.url().should(
      'eq',
      'http://localhost:3000/spectrum/general/another-thread~thread-2?m=MTQ4MzIyNTIwMDAwMg=='
    );
  });
});